2015-02-03 07:07:31 +08:00
|
|
|
|
/// Credit Melang
|
|
|
|
|
/// Sourced from - http://forum.unity3d.com/members/melang.593409/
|
2023-02-04 19:22:31 +08:00
|
|
|
|
/// NOT supported in Unity 2022
|
2015-02-03 07:07:31 +08:00
|
|
|
|
|
2023-02-04 19:22:31 +08:00
|
|
|
|
#if !UNITY_2022_1_OR_NEWER
|
2015-02-03 07:07:31 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
namespace UnityEngine.UI.Extensions
|
|
|
|
|
{
|
|
|
|
|
[AddComponentMenu("UI/Effects/Extensions/BestFit Outline")]
|
|
|
|
|
public class BestFitOutline : Shadow
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// Constructors
|
|
|
|
|
//
|
|
|
|
|
protected BestFitOutline ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Methods
|
|
|
|
|
//
|
2015-09-10 05:31:17 +08:00
|
|
|
|
public override void ModifyMesh (Mesh mesh)
|
2015-02-03 07:07:31 +08:00
|
|
|
|
{
|
|
|
|
|
if (!this.IsActive ())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-10 05:31:17 +08:00
|
|
|
|
List<UIVertex> verts = new List<UIVertex>();
|
|
|
|
|
using (var helper = new VertexHelper(mesh))
|
|
|
|
|
{
|
|
|
|
|
helper.GetUIVertexStream(verts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text foundtext = GetComponent<Text>();
|
2015-02-03 07:07:31 +08:00
|
|
|
|
|
|
|
|
|
float best_fit_adjustment = 1f;
|
|
|
|
|
|
|
|
|
|
if (foundtext && foundtext.resizeTextForBestFit)
|
|
|
|
|
{
|
|
|
|
|
best_fit_adjustment = (float)foundtext.cachedTextGenerator.fontSizeUsedForBestFit / (foundtext.resizeTextMaxSize-1); //max size seems to be exclusive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int start = 0;
|
|
|
|
|
int count = verts.Count;
|
2015-09-10 05:31:17 +08:00
|
|
|
|
base.ApplyShadowZeroAlloc(verts, base.effectColor, start, verts.Count, base.effectDistance.x*best_fit_adjustment, base.effectDistance.y*best_fit_adjustment);
|
2015-02-03 07:07:31 +08:00
|
|
|
|
start = count;
|
|
|
|
|
count = verts.Count;
|
2015-09-10 05:31:17 +08:00
|
|
|
|
base.ApplyShadowZeroAlloc(verts, base.effectColor, start, verts.Count, base.effectDistance.x*best_fit_adjustment, -base.effectDistance.y*best_fit_adjustment);
|
2015-02-03 07:07:31 +08:00
|
|
|
|
start = count;
|
|
|
|
|
count = verts.Count;
|
2015-09-10 05:31:17 +08:00
|
|
|
|
base.ApplyShadowZeroAlloc(verts, base.effectColor, start, verts.Count, -base.effectDistance.x*best_fit_adjustment, base.effectDistance.y*best_fit_adjustment);
|
2015-02-03 07:07:31 +08:00
|
|
|
|
start = count;
|
|
|
|
|
count = verts.Count;
|
2015-09-10 05:31:17 +08:00
|
|
|
|
base.ApplyShadowZeroAlloc(verts, base.effectColor, start, verts.Count, -base.effectDistance.x*best_fit_adjustment, -base.effectDistance.y*best_fit_adjustment);
|
|
|
|
|
|
|
|
|
|
using (var helper = new VertexHelper())
|
|
|
|
|
{
|
|
|
|
|
helper.AddUIVertexTriangleStream(verts);
|
|
|
|
|
helper.FillMesh(mesh);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-02-03 07:07:31 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-04 19:22:31 +08:00
|
|
|
|
#endif
|