Last active
June 16, 2019 15:31
-
-
Save ruccho/0330247fb8771cad78b10f23872bb7df to your computer and use it in GitHub Desktop.
uGUIのアウトラインをドットのフォントでキレイに表示するやつ。Textにアタッチして使えます。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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