- 最后登录
- 2017-6-30
- 注册时间
- 2012-12-27
- 阅读权限
- 90
- 积分
- 10267
- 纳金币
- 6520
- 精华
- 14
|
UGUI中没有文字渐变的功能,但有些时候为了让文字看起来更漂亮,需要去实现这项功能。本人用的unity4.9。
废话不多少了,上代码:- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- [AddComponentMenu("UI/Effects/Gradient")]
- public class Gradient : BaseVertexEffect
- {
- [SerializeField]
- private Color32 leftTopColor = Color.white;
- [SerializeField]
- private Color32 rightTopColor = Color.black;
- [SerializeField]
- private Color32 leftBottomColor = Color.black;
- [SerializeField]
- private Color32 rightBottomColor = Color.black;
- public override void ModifyVertices(List<UIVertex> vertexList)
- {
- if (!IsActive())
- {
- return;
- }
- for (int i = 0; i < vertexList.Count; )
- {
- ChangeColor(ref vertexList, i, leftTopColor);
- ChangeColor(ref vertexList, i + 1, rightTopColor);
- ChangeColor(ref vertexList, i + 2, rightBottomColor);
- ChangeColor(ref vertexList, i + 3, leftBottomColor);
- i += 4;
- }
- }
- private void ChangeColor(ref List<UIVertex> verList, int index, Color color)
- {
- UIVertex temp = verList[index];
- temp.color = color;
- verList[index] = temp;
- }
- }
复制代码
|
|