From fbfb5afc8ecfcce36768c792ddc88e6eb1a6970b Mon Sep 17 00:00:00 2001 From: Eddy Parris Date: Thu, 7 Dec 2017 13:34:55 +0000 Subject: [PATCH] Use a member variable for the list of verts to stop garbage generation. --- Scripts/Effects/NicerOutline.cs | 60 ++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/Scripts/Effects/NicerOutline.cs b/Scripts/Effects/NicerOutline.cs index 8f3cd88..039444e 100644 --- a/Scripts/Effects/NicerOutline.cs +++ b/Scripts/Effects/NicerOutline.cs @@ -1,4 +1,4 @@ -/// Credit Melang +/// Credit Melang /// Sourced from - http://forum.unity3d.com/members/melang.593409/ using System.Collections.Generic; @@ -10,12 +10,15 @@ namespace UnityEngine.UI.Extensions { [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 List < UIVertex > m_Verts = new List(); + // // Properties // @@ -34,7 +37,7 @@ namespace UnityEngine.UI.Extensions } } } - + public Vector2 effectDistance { get @@ -70,7 +73,7 @@ namespace UnityEngine.UI.Extensions } } } - + public bool useGraphicAlpha { get @@ -128,16 +131,17 @@ namespace UnityEngine.UI.Extensions { return; } - List < UIVertex > verts = new List(); - vh.GetUIVertexStream(verts); + + m_Verts.Clear(); + vh.GetUIVertexStream(m_Verts); Text foundtext = GetComponent(); - + float best_fit_adjustment = 1f; - - if (foundtext && foundtext.resizeTextForBestFit) + + if (foundtext && foundtext.resizeTextForBestFit) { - best_fit_adjustment = (float)foundtext.cachedTextGenerator.fontSizeUsedForBestFit / (foundtext.resizeTextMaxSize-1); //max size seems to be exclusive + best_fit_adjustment = (float)foundtext.cachedTextGenerator.fontSizeUsedForBestFit / (foundtext.resizeTextMaxSize-1); //max size seems to be exclusive } @@ -145,34 +149,34 @@ namespace UnityEngine.UI.Extensions float distanceY = this.effectDistance.y * best_fit_adjustment; int start = 0; - int count = verts.Count; - this.ApplyShadow (verts, this.effectColor, start, verts.Count, distanceX, distanceY); + int count = m_Verts.Count; + this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, distanceX, distanceY); start = count; - count = verts.Count; - this.ApplyShadow (verts, this.effectColor, start, verts.Count, distanceX, -distanceY); + count = m_Verts.Count; + this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, distanceX, -distanceY); start = count; - count = verts.Count; - this.ApplyShadow (verts, this.effectColor, start, verts.Count, -distanceX, distanceY); + count = m_Verts.Count; + this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, -distanceX, distanceY); start = count; - count = verts.Count; - this.ApplyShadow (verts, this.effectColor, start, verts.Count, -distanceX, -distanceY); + count = m_Verts.Count; + this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, -distanceX, -distanceY); start = count; - count = verts.Count; - this.ApplyShadow (verts, this.effectColor, start, verts.Count, distanceX, 0); + count = m_Verts.Count; + this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, distanceX, 0); start = count; - count = verts.Count; - this.ApplyShadow (verts, this.effectColor, start, verts.Count, -distanceX, 0); + count = m_Verts.Count; + this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, -distanceX, 0); start = count; - count = verts.Count; - this.ApplyShadow (verts, this.effectColor, start, verts.Count, 0, distanceY); + count = m_Verts.Count; + this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, 0, distanceY); start = count; - count = verts.Count; - this.ApplyShadow (verts, this.effectColor, start, verts.Count, 0, -distanceY); + count = m_Verts.Count; + this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, 0, -distanceY); vh.Clear(); - vh.AddUIVertexTriangleStream(verts); + vh.AddUIVertexTriangleStream(m_Verts); } #if UNITY_EDITOR