diff --git a/Scripts/NicerOutline.cs b/Scripts/NicerOutline.cs index 797d69f..b284765 100644 --- a/Scripts/NicerOutline.cs +++ b/Scripts/NicerOutline.cs @@ -8,6 +8,8 @@ namespace UnityEngine.UI.Extensions [AddComponentMenu("UI/Effects/Extensions/Nicer Outline")] public class NicerOutline : BaseMeshEffect { + private const int VERTICES_PER_QUAD = 6; + [SerializeField] private Color m_EffectColor = new Color (0f, 0f, 0f, 0.5f); @@ -91,10 +93,6 @@ namespace UnityEngine.UI.Extensions { UIVertex vt; - var neededCpacity = verts.Count * 2; - if (verts.Capacity < neededCpacity) - verts.Capacity = neededCpacity; - for (int i = start; i < end; ++i) { vt = verts[i]; @@ -114,10 +112,6 @@ namespace UnityEngine.UI.Extensions protected void ApplyShadow(List verts, Color32 color, int start, int end, float x, float y) { - var neededCpacity = verts.Count * 2; - if (verts.Capacity < neededCpacity) - verts.Capacity = neededCpacity; - ApplyShadowZeroAlloc(verts, color, start, end, x, y); } @@ -128,8 +122,12 @@ namespace UnityEngine.UI.Extensions { return; } - List < UIVertex > verts = new List(); - using (var helper = new VertexHelper(mesh)) + + // Initilize a list with the correct capacity, to avoid unneeded allocations later. + // The list will hold 9 copies of the vertex data (original + 8 copies). + List < UIVertex > verts = new List(9 * (mesh.vertices.Length / 4 * VERTICES_PER_QUAD)); + + using (var helper = new VertexHelper(mesh)) { helper.GetUIVertexStream(verts); }