using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;
namespace Effects
{
[RequireComponent(typeof(Text))]
[AddComponentMenu("UI/Effects/BoldOutline")]
public class BoldOutline : Shadow
{
public bool IsEcoMode = true;
public static List<UIVertex> verts = new List<UIVertex>();
const int OUTLINE_BUDGET = 50;
static int frameNo = 0;
static int iBudgetUsed = 0;
public override void ModifyMesh(VertexHelper vh)
{
bool bIsBudgetEnough = true;
if(Time.frameCount ==frameNo)
{
if (iBudgetUsed >= OUTLINE_BUDGET)
{
bIsBudgetEnough = false;
}
else
{
iBudgetUsed++;
}
}
else
{
frameNo = Time.frameCount;
iBudgetUsed = 0;
}
if (!IsActive())
return;
verts.Clear();
vh.GetUIVertexStream(verts);
var neededCpacity = verts.Count * 5;
if (verts.Capacity < neededCpacity)
verts.Capacity = neededCpacity;
var start = 0;
var end = verts.Count;
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, effectDistance.y);
start = end;
end = verts.Count;
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, -effectDistance.y);
if(bIsBudgetEnough)
{
start = end;
end = verts.Count;
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, -effectDistance.y);
start = end;
end = verts.Count;
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, effectDistance.y);
}
if(!IsEcoMode)
{
start = end;
end = verts.Count;
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, effectDistance.x, 0);
start = end;
end = verts.Count;
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, -effectDistance.x, 0);
start = end;
end = verts.Count;
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, 0, effectDistance.y);
start = end;
end = verts.Count;
ApplyShadowZeroAlloc(verts, effectColor, start, verts.Count, 0, -effectDistance.y);
}
vh.Clear();
vh.AddUIVertexTriangleStream(verts);
verts.Clear();
}
}
}
unity3d:text描边
最新推荐文章于 2024-05-21 18:54:53 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)