纳金网

标题: UGUI文字渐变效果(转载guojia) [打印本页]

作者: 雅雅    时间: 2016-1-29 23:55
标题: UGUI文字渐变效果(转载guojia)
UGUI中没有文字渐变的功能,但有些时候为了让文字看起来更漂亮,需要去实现这项功能。本人用的unity4.9。
废话不多少了,上代码:
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine.UI;

  5. [AddComponentMenu("UI/Effects/Gradient")]
  6. public class Gradient : BaseVertexEffect
  7. {
  8.     [SerializeField]
  9.     private Color32 leftTopColor = Color.white;
  10.     [SerializeField]
  11.     private Color32 rightTopColor = Color.black;
  12.     [SerializeField]
  13.     private Color32 leftBottomColor = Color.black;
  14.     [SerializeField]
  15.     private Color32 rightBottomColor = Color.black;

  16.     public override void ModifyVertices(List<UIVertex> vertexList)
  17.     {
  18.         if (!IsActive())
  19.         {
  20.             return;
  21.         }

  22.         for (int i = 0; i < vertexList.Count; )
  23.         {
  24.             ChangeColor(ref vertexList, i, leftTopColor);
  25.             ChangeColor(ref vertexList, i + 1, rightTopColor);
  26.             ChangeColor(ref vertexList, i + 2, rightBottomColor);
  27.             ChangeColor(ref vertexList, i + 3, leftBottomColor);
  28.             i += 4;
  29.         }

  30.     }
  31.     private void ChangeColor(ref List<UIVertex> verList, int index, Color color)
  32.     {
  33.         UIVertex temp = verList[index];
  34.         temp.color = color;
  35.         verList[index] = temp;
  36.     }
  37. }
复制代码
210104ffcw7rlf883hdhvy.png







欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5