纳金网

标题: UGUI Text渐变效果实现(Gradient) [打印本页]

作者: 烟雨    时间: 2015-6-25 07:41
标题: UGUI Text渐变效果实现(Gradient)
UGUI自带两个字体效果--Outline 和 Shadow
而渐变效果实现木有,以下是社区中的实现,供参考使用:https://www.youtube.com/watch?v=gkGSrjZNEzQ(此视频是一个专业插件,很强大)
另外一个简单实现:
  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.         [SerializeField]
  8.         private Color32 topColor = Color.white;
  9.         [SerializeField]
  10.         private Color32 bottomColor = Color.black;
  11.        
  12.         public override void ModifyVertices(List<UIVertex> vertexList) {
  13.                 if (!IsActive()) {
  14.                         return;
  15.                 }
  16.                
  17.                 int count = vertexList.Count;
  18.                 float bottomY = vertexList[0].position.y;
  19.                 float topY = vertexList[0].position.y;
  20.                
  21.                 for (int i = 1; i < count; i++) {
  22.                         float y = vertexList[i].position.y;
  23.                         if (y > topY) {
  24.                                 topY = y;
  25.                         }
  26.                         else if (y < bottomY) {
  27.                                 bottomY = y;
  28.                         }
  29.                 }
  30.                
  31.                 float uiElementHeight = topY - bottomY;
  32.                
  33.                 for (int i = 0; i < count; i++) {
  34.                         UIVertex uiVertex = vertexList[i];
  35.                         uiVertex.color = Color32.Lerp(bottomColor, topColor, (uiVertex.position.y - bottomY) / uiElementHeight);
  36.                         vertexList[i] = uiVertex;
  37.                 }
  38.         }
  39. }
复制代码





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