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;
@ -10,12 +10,15 @@ namespace UnityEngine.UI.Extensions
{ {
[SerializeField] [SerializeField]
private Color m_EffectColor = new Color (0f, 0f, 0f, 0.5f); private Color m_EffectColor = new Color (0f, 0f, 0f, 0.5f);
[SerializeField] [SerializeField]
private Vector2 m_EffectDistance = new Vector2 (1f, -1f); private Vector2 m_EffectDistance = new Vector2 (1f, -1f);
[SerializeField] [SerializeField]
private bool m_UseGraphicAlpha = true; private bool m_UseGraphicAlpha = true;
private List < UIVertex > m_Verts = new List<UIVertex>();
// //
// Properties // Properties
// //
@ -34,7 +37,7 @@ namespace UnityEngine.UI.Extensions
} }
} }
} }
public Vector2 effectDistance public Vector2 effectDistance
{ {
get get
@ -70,7 +73,7 @@ namespace UnityEngine.UI.Extensions
} }
} }
} }
public bool useGraphicAlpha public bool useGraphicAlpha
{ {
get get
@ -128,16 +131,17 @@ 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>();
float best_fit_adjustment = 1f; 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; 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