查看: 3737|回复: 0
打印 上一主题 下一主题

[经验分享] UGUI Text渐变效果实现(Gradient)

[复制链接]

9903

主题

126

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
53456
精华
316

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2015-6-25 07:41:45 |只看该作者 |倒序浏览
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. }
复制代码
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-4 08:08 , Processed in 0.082316 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部