using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
[AddComponentMenu("UI/Effects/MirrorText")]
public class MirrorText : BaseMeshEffect
{
//距离,限制范围0-30
[Range(0, 30)]
public float distance;
public override void ModifyMesh(VertexHelper vh)
{
if (!IsActive() || vh.currentVertCount == 0)
{
return;
}
List<UIVertex> vertexs = new List<UIVertex>();
vh.GetUIVertexStream(vertexs);
UIVertex vt;
int count = vertexs.Count;
float miny = vertexs[0].position.y;
float maxy = vertexs[0].position.y;
for (int i = 1; i < count; i++)
{
if (vertexs[i].position.y < miny)
{
miny = vertexs[i].position.y;
}
else if (vertexs[i].position.y > maxy)
{
maxy = vertexs[i].position.y;
}
}
float uiElementHeight = maxy - miny;
float mirrorMinY = -maxy + 2 * miny - distance;
Color32 top = GetComponent<Text>().color;
Color32 bottom = new Color(top.r, top.g, top.b, 0);
for (int i = 0; i < count; i++)
{
vt = vertexs[i];
vertexs.Add(vt);
Vector3 v = vt.position;
v.y = -v.y + 2 * miny - distance;
vt.position = v;
//透明度效果
vt.color = Color32.Lerp(bottom, top, (vt.position.y - mirrorMinY) / uiElementHeight);
vertexs[i + count] = vt;
}
vh.Clear();
vh.AddUIVertexTriangleStream(vertexs);
}
}
unity3dText倒影效果
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...