|
@@ -0,0 +1,47 @@
|
|
|
+using UnityEngine;
|
|
|
+using UnityEngine.UI;
|
|
|
+using System.Collections.Generic;
|
|
|
+
|
|
|
+[AddComponentMenu("UI/Effects/Nicer Outline", 15)]
|
|
|
+public class NicerOutline : BaseMeshEffect
|
|
|
+{
|
|
|
+ [SerializeField] private Color effectColor = new Color(0f, 0f, 0f, 1f);
|
|
|
+ [SerializeField] private float effectDistanceX = 2f;
|
|
|
+ [SerializeField] private float effectDistanceY = 2f;
|
|
|
+ [SerializeField] private int samplingRate = 10;
|
|
|
+
|
|
|
+ private static readonly List<UIVertex> vertexList = new List<UIVertex>();
|
|
|
+ private static readonly List<UIVertex> tempVertexList = new List<UIVertex>();
|
|
|
+
|
|
|
+ public override void ModifyMesh(VertexHelper vh)
|
|
|
+ {
|
|
|
+ if (!IsActive()) return;
|
|
|
+
|
|
|
+ vertexList.Clear();
|
|
|
+ tempVertexList.Clear();
|
|
|
+ vh.GetUIVertexStream(vertexList);
|
|
|
+
|
|
|
+ int count = vertexList.Count;
|
|
|
+ for (int j = 0; j < samplingRate; j++)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < count; i++)
|
|
|
+ {
|
|
|
+ UIVertex v = vertexList[i];
|
|
|
+ float angle = j * Mathf.PI * 2f / samplingRate;
|
|
|
+ Vector2 offset = new Vector2(Mathf.Cos(angle) * effectDistanceX, Mathf.Sin(angle) * effectDistanceY);
|
|
|
+ UIVertex outlinedVert = new UIVertex();
|
|
|
+ outlinedVert.position = v.position + (Vector3)offset;
|
|
|
+ outlinedVert.normal = v.normal;
|
|
|
+ outlinedVert.tangent = v.tangent;
|
|
|
+ outlinedVert.uv0 = v.uv0;
|
|
|
+ outlinedVert.uv1 = v.uv1;
|
|
|
+ outlinedVert.color = effectColor;
|
|
|
+ tempVertexList.Add(outlinedVert);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tempVertexList.AddRange(vertexList);
|
|
|
+ vh.Clear();
|
|
|
+ vh.AddUIVertexTriangleStream(tempVertexList);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|