Skip to content

Instantly share code, notes, and snippets.

@ruccho
Last active June 16, 2019 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruccho/0330247fb8771cad78b10f23872bb7df to your computer and use it in GitHub Desktop.
Save ruccho/0330247fb8771cad78b10f23872bb7df to your computer and use it in GitHub Desktop.
uGUIのアウトラインをドットのフォントでキレイに表示するやつ。Textにアタッチして使えます。
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Ruccho.Utilities
{
public class PixelOutline : Shadow
{
[SerializeField]
private bool EightDirection;
protected PixelOutline()
{ }
public override void ModifyMesh(VertexHelper vh)
{
if (!IsActive())
return;
var verts = new List<UIVertex>();
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, 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);
if (EightDirection)
{
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);
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);
}
vh.Clear();
vh.AddUIVertexTriangleStream(verts);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment