Unity 2017 文字颜色渐变

 1 using System.Collections;
 2 using System.Collections.Generic;
 3 using UnityEngine;
 4 using UnityEngine.UI;
 5 
 6 [AddComponentMenu("UI/Effects/GradientText")]
 7 public class GradientText : BaseMeshEffect
 8 {
 9     [SerializeField]
10     private Color32 topColor = Color.white;
11 
12     [SerializeField]
13     private Color32 bottomColor = Color.black;
14 
15     public override void ModifyMesh(VertexHelper vh)
16     {
17         if (!IsActive() || vh.currentVertCount == 0)
18             return;
19         List<UIVertex> vertices =  new List<UIVertex>();
20         vh.GetUIVertexStream(vertices);
21         float bottomY = vertices[0].position.y;
22         float topY = vertices[0].position.y;
23         for (int i = 1; i < vertices.Count; i++ )
24         {
25            if( vertices[i].position.y > topY) {
26                 topY = vertices[i].position.y;
27             }
28             else if (vertices[i].position.y < bottomY)
29             {
30                 bottomY = vertices[i].position.y;
31             }
32         }
33         float uiElementHeight = topY- bottomY;
34         UIVertex v = new UIVertex();
35         for (int i = 0; i<vh.currentVertCount; i++)
36         {
37         vh.PopulateUIVertex(ref v, i);
38         v.color = Color32.Lerp(bottomColor, topColor, (v.position.y - bottomY) / uiElementHeight);
39         vh.SetUIVertex(v, i);
40         }
41     }
42 }

 

转载于:https://www.cnblogs.com/pmsl/p/7615891.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值