Created
September 14, 2018 02:22
-
-
Save as8190255/4c8518572ca0725968d7a4c6a787e280 to your computer and use it in GitHub Desktop.
unity 渐变 文字
This file contains 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
public class ColorGradientText : BaseMeshEffect | |
{ | |
#region implemented abstract members of BaseMeshEffect | |
public override void ModifyMesh(VertexHelper vh) | |
{ | |
if (!IsActive()) { return; } | |
var count = vh.currentVertCount; | |
Debug.Log(count); | |
if (count == 0) return; | |
var vertexs = new List<UIVertex>(); | |
for (var i = 0; i < count; i++) | |
{ | |
var vertex = new UIVertex(); | |
vh.PopulateUIVertex(ref vertex, i); | |
vertexs.Add(vertex); | |
} | |
var topY = vertexs.Max(k => k.position.y);//[0].position.y; | |
var bottomY = vertexs.Min(k => k.position.y); //[0].position.y; | |
var height = topY - bottomY; | |
for (var i = 0; i < count; i++) | |
{ | |
var vertex = vertexs[i]; | |
vertex.color = Color32.Lerp(Color.red, Color.green, (vertex.position.y - bottomY) / height); | |
vh.SetUIVertex(vertex, i); | |
} | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment