From b357a6a6d914e46c2c782f215e9f566f92663850 Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 9 Apr 2021 20:37:24 +0800 Subject: *UI effect --- .../UnityEngine.UI/UI/Core/Graphics/Graphic.cs | 9 ++++++++- .../UI/Core/Graphics/GraphicRegistry.cs | 2 ++ .../UI/Core/SpecializedCollections/IndexedSet.cs | 2 +- .../UnityEngine.UI/UI/Core/Utility/VertexHelper.cs | 19 ++++++++++--------- .../UI/Core/VertexModifiers/IMeshModifier.cs | 13 +++++++------ 5 files changed, 28 insertions(+), 17 deletions(-) (limited to 'Assets/uGUI-2017.1/UnityEngine.UI/UI/Core') diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/Graphic.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/Graphic.cs index 1ded27a..53cc1bd 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/Graphic.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/Graphic.cs @@ -177,9 +177,11 @@ namespace UnityEngine.UI } } + // 找到父节点中最近的canvas private void CacheCanvas() { var list = ListPool.Get(); + // 找到所有父节点中所有canvas,从里到外 gameObject.GetComponentsInParent(false, list); if (list.Count > 0) { @@ -235,10 +237,14 @@ namespace UnityEngine.UI } } + /// + /// 提交到CanvasRenderer用这个,要应用IMaterialModifier的修改结果 + /// public virtual Material materialForRendering { get { + // 在这里调用IMaterialModifier的修改 var components = ListPool.Get(); GetComponents(typeof(IMaterialModifier), components); @@ -380,7 +386,7 @@ namespace UnityEngine.UI private void DoMeshGeneration() { if (rectTransform != null && rectTransform.rect.width >= 0 && rectTransform.rect.height >= 0) - OnPopulateMesh(s_VertexHelper); + OnPopulateMesh(s_VertexHelper); // 填充vertexHelper else s_VertexHelper.Clear(); // clear the vertex helper so invalid graphics dont draw. @@ -394,6 +400,7 @@ namespace UnityEngine.UI ListPool.Release(components); s_VertexHelper.FillMesh(workerMesh); + // 传入canvasRenderer作为mesh canvasRenderer.SetMesh(workerMesh); } diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/GraphicRegistry.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/GraphicRegistry.cs index ca7eddf..0642792 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/GraphicRegistry.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Graphics/GraphicRegistry.cs @@ -3,10 +3,12 @@ using UnityEngine.UI.Collections; namespace UnityEngine.UI { + // 游戏中只有一份单例 public class GraphicRegistry { private static GraphicRegistry s_Instance; + // 按Canvas分类统计Graphic private readonly Dictionary> m_Graphics = new Dictionary>(); protected GraphicRegistry() diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/SpecializedCollections/IndexedSet.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/SpecializedCollections/IndexedSet.cs index a968577..0f37983 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/SpecializedCollections/IndexedSet.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/SpecializedCollections/IndexedSet.cs @@ -115,7 +115,7 @@ namespace UnityEngine.UI.Collections T item = m_List[index]; m_Dictionary.Remove(item); m_List[index] = value; - m_Dictionary.Add(item, index); + m_Dictionary.Add(item, index); // 这里有问题,应该是value } } diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Utility/VertexHelper.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Utility/VertexHelper.cs index f7e35cd..3020d4d 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Utility/VertexHelper.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/Utility/VertexHelper.cs @@ -5,15 +5,16 @@ namespace UnityEngine.UI { public class VertexHelper : IDisposable { - private List m_Positions = ListPool.Get(); - private List m_Colors = ListPool.Get(); - private List m_Uv0S = ListPool.Get(); - private List m_Uv1S = ListPool.Get(); - private List m_Uv2S = ListPool.Get(); - private List m_Uv3S = ListPool.Get(); - private List m_Normals = ListPool.Get(); - private List m_Tangents = ListPool.Get(); - private List m_Indices = ListPool.Get(); + //c 改成public方便看 + /*private*/ public List m_Positions = ListPool.Get(); + /*private*/ public List m_Colors = ListPool.Get(); + /*private*/ public List m_Uv0S = ListPool.Get(); + /*private*/ public List m_Uv1S = ListPool.Get(); + /*private*/ public List m_Uv2S = ListPool.Get(); + /*private*/ public List m_Uv3S = ListPool.Get(); + /*private*/ public List m_Normals = ListPool.Get(); + /*private*/ public List m_Tangents = ListPool.Get(); + /*private*/ public List m_Indices = ListPool.Get(); private static readonly Vector4 s_DefaultTangent = new Vector4(1.0f, 0.0f, 0.0f, -1.0f); private static readonly Vector3 s_DefaultNormal = Vector3.back; diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/IMeshModifier.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/IMeshModifier.cs index a12505c..582a820 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/IMeshModifier.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/IMeshModifier.cs @@ -3,12 +3,13 @@ using System.Collections.Generic; namespace UnityEngine.UI { - [Obsolete("Use IMeshModifier instead", true)] - public interface IVertexModifier - { - [Obsolete("use IMeshModifier.ModifyMesh (VertexHelper verts) instead", true)] - void ModifyVertices(List verts); - } + + //[Obsolete("Use IMeshModifier instead", true)] + //public interface IVertexModifier + //{ + // [Obsolete("use IMeshModifier.ModifyMesh (VertexHelper verts) instead", true)] + // void ModifyVertices(List verts); + //} public interface IMeshModifier { -- cgit v1.1-26-g67d0