summaryrefslogtreecommitdiff
path: root/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-05-08 23:15:13 +0800
committerchai <chaifix@163.com>2021-05-08 23:15:13 +0800
commitd07e14add74e017b52ab2371efeea1aa4ea10ced (patch)
treeefd07869326e4c428f5bfe43fad0c2583d32a401 /Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers
+init
Diffstat (limited to 'Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers')
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/BaseMeshEffect.cs74
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/BaseMeshEffect.cs.meta13
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/IMeshModifier.cs20
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/IMeshModifier.cs.meta13
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Outline.cs44
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Outline.cs.meta13
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/PositionAsUV1.cs22
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/PositionAsUV1.cs.meta13
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Shadow.cs126
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Shadow.cs.meta13
10 files changed, 351 insertions, 0 deletions
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/BaseMeshEffect.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/BaseMeshEffect.cs
new file mode 100644
index 0000000..aac679d
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/BaseMeshEffect.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using UnityEngine.EventSystems;
+
+namespace UnityEngine.UI
+{
+ [Obsolete("Use BaseMeshEffect instead", true)]
+ public abstract class BaseVertexEffect
+ {
+ [Obsolete("Use BaseMeshEffect.ModifyMeshes instead", true)] //We can't upgrade automatically since the signature changed.
+ public abstract void ModifyVertices(List<UIVertex> vertices);
+ }
+
+ // 关键在于实现IMeshModifier接口,自己写效果,不一定要继承这个类
+ [ExecuteInEditMode]
+ public abstract class BaseMeshEffect : UIBehaviour, IMeshModifier
+ {
+ [NonSerialized]
+ private Graphic m_Graphic;
+
+ protected Graphic graphic
+ {
+ get
+ {
+ if (m_Graphic == null)
+ m_Graphic = GetComponent<Graphic>();
+
+ return m_Graphic;
+ }
+ }
+
+ protected override void OnEnable()
+ {
+ base.OnEnable();
+ if (graphic != null)
+ graphic.SetVerticesDirty();
+ }
+
+ protected override void OnDisable()
+ {
+ if (graphic != null)
+ graphic.SetVerticesDirty();
+ base.OnDisable();
+ }
+
+ protected override void OnDidApplyAnimationProperties()
+ {
+ if (graphic != null)
+ graphic.SetVerticesDirty();
+ base.OnDidApplyAnimationProperties();
+ }
+
+#if UNITY_EDITOR
+ protected override void OnValidate()
+ {
+ base.OnValidate();
+ if (graphic != null)
+ graphic.SetVerticesDirty();
+ }
+
+#endif
+
+ public virtual void ModifyMesh(Mesh mesh)
+ {
+ using (var vh = new VertexHelper(mesh))
+ {
+ ModifyMesh(vh);
+ vh.FillMesh(mesh);
+ }
+ }
+
+ public abstract void ModifyMesh(VertexHelper vh);
+ }
+}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/BaseMeshEffect.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/BaseMeshEffect.cs.meta
new file mode 100644
index 0000000..9f4a3df
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/BaseMeshEffect.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 9e33e594b9e3bfb41b97c11432334978
+timeCreated: 1602119379
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
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
new file mode 100644
index 0000000..582a820
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/IMeshModifier.cs
@@ -0,0 +1,20 @@
+using System;
+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<UIVertex> verts);
+ //}
+
+ public interface IMeshModifier
+ {
+ [Obsolete("use IMeshModifier.ModifyMesh (VertexHelper verts) instead", false)]
+ void ModifyMesh(Mesh mesh);
+ void ModifyMesh(VertexHelper verts);
+ }
+}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/IMeshModifier.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/IMeshModifier.cs.meta
new file mode 100644
index 0000000..df53941
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/IMeshModifier.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 6b4c52564d8d47540a091497d8f9dd49
+timeCreated: 1602119378
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Outline.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Outline.cs
new file mode 100644
index 0000000..e14c862
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Outline.cs
@@ -0,0 +1,44 @@
+using System.Collections.Generic;
+
+namespace UnityEngine.UI
+{
+ [AddComponentMenu("UI/Effects/Outline", 15)]
+ public class Outline : Shadow
+ {
+ protected Outline()
+ {}
+
+ public override void ModifyMesh(VertexHelper vh)
+ {
+ if (!IsActive())
+ return;
+
+ var verts = ListPool<UIVertex>.Get();
+ vh.GetUIVertexStream(verts);
+
+ var neededCpacity = verts.Count * 5;
+ if (verts.Capacity < neededCpacity)
+ verts.Capacity = neededCpacity;
+
+ var start = 0;
+ var end = verts.Count;
+ ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, effectDistance.y);
+
+ start = end;
+ end = verts.Count;
+ ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, -effectDistance.y);
+
+ start = end;
+ end = verts.Count;
+ ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, effectDistance.y);
+
+ start = end;
+ end = verts.Count;
+ ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, -effectDistance.y);
+
+ vh.Clear();
+ vh.AddUIVertexTriangleStream(verts);
+ ListPool<UIVertex>.Release(verts);
+ }
+ }
+}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Outline.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Outline.cs.meta
new file mode 100644
index 0000000..a27dd26
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Outline.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 5978620b88847af4a8835c7008c813b8
+timeCreated: 1602119378
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/PositionAsUV1.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/PositionAsUV1.cs
new file mode 100644
index 0000000..d396bfa
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/PositionAsUV1.cs
@@ -0,0 +1,22 @@
+using System.Linq;
+
+namespace UnityEngine.UI
+{
+ [AddComponentMenu("UI/Effects/Position As UV1", 16)]
+ public class PositionAsUV1 : BaseMeshEffect
+ {
+ protected PositionAsUV1()
+ {}
+
+ public override void ModifyMesh(VertexHelper vh)
+ {
+ UIVertex vert = new UIVertex();
+ for (int i = 0; i < vh.currentVertCount; i++)
+ {
+ vh.PopulateUIVertex(ref vert, i);
+ vert.uv1 = new Vector2(vert.position.x, vert.position.y);
+ vh.SetUIVertex(vert, i);
+ }
+ }
+ }
+}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/PositionAsUV1.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/PositionAsUV1.cs.meta
new file mode 100644
index 0000000..847c79f
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/PositionAsUV1.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 19ed27a46ca366b439439e63862c762b
+timeCreated: 1602119377
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Shadow.cs b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Shadow.cs
new file mode 100644
index 0000000..e0a813c
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Shadow.cs
@@ -0,0 +1,126 @@
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace UnityEngine.UI
+{
+ [AddComponentMenu("UI/Effects/Shadow", 14)]
+ public class Shadow : BaseMeshEffect
+ {
+ [SerializeField]
+ private Color m_EffectColor = new Color(0f, 0f, 0f, 0.5f);
+
+ [SerializeField]
+ private Vector2 m_EffectDistance = new Vector2(1f, -1f);
+
+ [SerializeField]
+ private bool m_UseGraphicAlpha = true;
+
+ private const float kMaxEffectDistance = 600f;
+
+ protected Shadow()
+ {}
+
+#if UNITY_EDITOR
+ protected override void OnValidate()
+ {
+ effectDistance = m_EffectDistance;
+ base.OnValidate();
+ }
+
+#endif
+
+ public Color effectColor
+ {
+ get { return m_EffectColor; }
+ set
+ {
+ m_EffectColor = value;
+ if (graphic != null)
+ graphic.SetVerticesDirty();
+ }
+ }
+
+ public Vector2 effectDistance
+ {
+ get { return m_EffectDistance; }
+ set
+ {
+ if (value.x > kMaxEffectDistance)
+ value.x = kMaxEffectDistance;
+ if (value.x < -kMaxEffectDistance)
+ value.x = -kMaxEffectDistance;
+
+ if (value.y > kMaxEffectDistance)
+ value.y = kMaxEffectDistance;
+ if (value.y < -kMaxEffectDistance)
+ value.y = -kMaxEffectDistance;
+
+ if (m_EffectDistance == value)
+ return;
+
+ m_EffectDistance = value;
+
+ if (graphic != null)
+ graphic.SetVerticesDirty();
+ }
+ }
+
+ public bool useGraphicAlpha
+ {
+ get { return m_UseGraphicAlpha; }
+ set
+ {
+ m_UseGraphicAlpha = value;
+ if (graphic != null)
+ graphic.SetVerticesDirty();
+ }
+ }
+
+ //x,y是偏移量
+ protected void ApplyShadowZeroAlloc(List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
+ {
+ UIVertex vt;
+
+ var neededCapacity = verts.Count + end - start;
+ if (verts.Capacity < neededCapacity)
+ verts.Capacity = neededCapacity;
+
+ for (int i = start; i < end; ++i)
+ {
+ vt = verts[i];
+ verts.Add(vt);
+
+ Vector3 v = vt.position;
+ v.x += x;
+ v.y += y;
+ vt.position = v;
+
+ var newColor = color;
+ if (m_UseGraphicAlpha)
+ newColor.a = (byte)((newColor.a * verts[i].color.a) / 255);
+
+ vt.color = newColor;
+ verts[i] = vt;
+ }
+ }
+
+ protected void ApplyShadow(List<UIVertex> verts, Color32 color, int start, int end, float x, float y)
+ {
+ ApplyShadowZeroAlloc(verts, color, start, end, x, y);
+ }
+
+ public override void ModifyMesh(VertexHelper vh)
+ {
+ if (!IsActive())
+ return;
+
+ var output = ListPool<UIVertex>.Get();
+ vh.GetUIVertexStream(output);
+
+ ApplyShadow(output, effectColor, 0, output.Count, effectDistance.x, effectDistance.y);
+ vh.Clear();
+ vh.AddUIVertexTriangleStream(output);
+ ListPool<UIVertex>.Release(output);
+ }
+ }
+}
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Shadow.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Shadow.cs.meta
new file mode 100644
index 0000000..75dc2fc
--- /dev/null
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/UI/Core/VertexModifiers/Shadow.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 128369c085053c246bab60ca7bb68a64
+timeCreated: 1602119377
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: