因为项目原因,采用的是比较老的NGUI(2.7),文本控件UILabel没有类似于UGUI的Gradient渐变效果的选项,所以需要自己动手添加.
先瞧瞧成品后的效果:
再来看看UGUI的Gradient效果,很方便,直接挂脚本就生效.
代码如下:
public class Gradient : BaseMeshEffect
{
public Color32 topColor = Color.white;
public Color32 bottomColor = Color.black;
public override void ModifyMesh(VertexHelper helper)
{
if (!IsActive() || helper.currentVertCount == 0)
return;
List<UIVertex> vertices = new List<UIVertex>();
helper.GetUIVertexStream(vertices);
float bottomY = vertices[0].position.y;
float topY = vertices[0].position.y;