Merged in empika/unity-ui-extensions (pull request #29)

Use a member variable for the list of verts to stop garbage generation.
pull/413/head
Edward Parris 2018-01-06 11:34:24 +00:00 committed by Simon Jackson
commit dcbe1920f1
1 changed files with 32 additions and 28 deletions

View File

@ -1,4 +1,4 @@
/// Credit Melang /// Credit Melang
/// Sourced from - http://forum.unity3d.com/members/melang.593409/ /// Sourced from - http://forum.unity3d.com/members/melang.593409/
using System.Collections.Generic; using System.Collections.Generic;
@ -16,6 +16,9 @@ namespace UnityEngine.UI.Extensions
[SerializeField] [SerializeField]
private bool m_UseGraphicAlpha = true; private bool m_UseGraphicAlpha = true;
private List < UIVertex > m_Verts = new List<UIVertex>();
// //
// Properties // Properties
// //
@ -128,8 +131,9 @@ namespace UnityEngine.UI.Extensions
{ {
return; return;
} }
List < UIVertex > verts = new List<UIVertex>();
vh.GetUIVertexStream(verts); m_Verts.Clear();
vh.GetUIVertexStream(m_Verts);
Text foundtext = GetComponent<Text>(); Text foundtext = GetComponent<Text>();
@ -145,34 +149,34 @@ namespace UnityEngine.UI.Extensions
float distanceY = this.effectDistance.y * best_fit_adjustment; float distanceY = this.effectDistance.y * best_fit_adjustment;
int start = 0; int start = 0;
int count = verts.Count; int count = m_Verts.Count;
this.ApplyShadow (verts, this.effectColor, start, verts.Count, distanceX, distanceY); this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, distanceX, distanceY);
start = count; start = count;
count = verts.Count; count = m_Verts.Count;
this.ApplyShadow (verts, this.effectColor, start, verts.Count, distanceX, -distanceY); this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, distanceX, -distanceY);
start = count; start = count;
count = verts.Count; count = m_Verts.Count;
this.ApplyShadow (verts, this.effectColor, start, verts.Count, -distanceX, distanceY); this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, -distanceX, distanceY);
start = count; start = count;
count = verts.Count; count = m_Verts.Count;
this.ApplyShadow (verts, this.effectColor, start, verts.Count, -distanceX, -distanceY); this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, -distanceX, -distanceY);
start = count; start = count;
count = verts.Count; count = m_Verts.Count;
this.ApplyShadow (verts, this.effectColor, start, verts.Count, distanceX, 0); this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, distanceX, 0);
start = count; start = count;
count = verts.Count; count = m_Verts.Count;
this.ApplyShadow (verts, this.effectColor, start, verts.Count, -distanceX, 0); this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, -distanceX, 0);
start = count; start = count;
count = verts.Count; count = m_Verts.Count;
this.ApplyShadow (verts, this.effectColor, start, verts.Count, 0, distanceY); this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, 0, distanceY);
start = count; start = count;
count = verts.Count; count = m_Verts.Count;
this.ApplyShadow (verts, this.effectColor, start, verts.Count, 0, -distanceY); this.ApplyShadow (m_Verts, this.effectColor, start, m_Verts.Count, 0, -distanceY);
vh.Clear(); vh.Clear();
vh.AddUIVertexTriangleStream(verts); vh.AddUIVertexTriangleStream(m_Verts);
} }
#if UNITY_EDITOR #if UNITY_EDITOR