2015-02-03 07:07:31 +08:00
|
|
|
|
/// Credit Melang
|
|
|
|
|
/// Sourced from - http://forum.unity3d.com/members/melang.593409/
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
namespace UnityEngine.UI.Extensions
|
|
|
|
|
{
|
|
|
|
|
[AddComponentMenu("UI/Effects/Extensions/BestFit Outline")]
|
|
|
|
|
public class BestFitOutline : Shadow
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// Constructors
|
|
|
|
|
//
|
|
|
|
|
protected BestFitOutline ()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Methods
|
|
|
|
|
//
|
|
|
|
|
public override void ModifyVertices (List<UIVertex> verts)
|
|
|
|
|
{
|
|
|
|
|
if (!this.IsActive ())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Text foundtext = GetComponent<Text>();
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
base.ApplyShadow (verts, base.effectColor, start, verts.Count, base.effectDistance.x*best_fit_adjustment, base.effectDistance.y*best_fit_adjustment);
|
|
|
|
|
start = count;
|
|
|
|
|
count = verts.Count;
|
|
|
|
|
base.ApplyShadow (verts, base.effectColor, start, verts.Count, base.effectDistance.x*best_fit_adjustment, -base.effectDistance.y*best_fit_adjustment);
|
|
|
|
|
start = count;
|
|
|
|
|
count = verts.Count;
|
|
|
|
|
base.ApplyShadow (verts, base.effectColor, start, verts.Count, -base.effectDistance.x*best_fit_adjustment, base.effectDistance.y*best_fit_adjustment);
|
|
|
|
|
start = count;
|
|
|
|
|
count = verts.Count;
|
|
|
|
|
base.ApplyShadow (verts, base.effectColor, start, verts.Count, -base.effectDistance.x*best_fit_adjustment, -base.effectDistance.y*best_fit_adjustment);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|