Use a member variable for the list of verts to stop garbage generation.
parent
d3671c3711
commit
fbfb5afc8e
|
@ -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<UIVertex>();
|
||||
|
||||
//
|
||||
// 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<UIVertex>();
|
||||
vh.GetUIVertexStream(verts);
|
||||
|
||||
m_Verts.Clear();
|
||||
vh.GetUIVertexStream(m_Verts);
|
||||
|
||||
Text foundtext = GetComponent<Text>();
|
||||
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue