[特效] UGUI Text渐变效果实现(Gradient)

查看:702 |回复:1 | 2021-10-8 10:02:34

您需要 登录 才可以下载或查看,没有账号?注册

x
UGUI Text渐变效果实现(Gradient)
UGUI自带两个字体效果--Outline 和 Shadow
而渐变效果实现木有,以下是社区中的实现,供参考使用:另外一个简单实现:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
[AddComponentMenu("UI/Effects/Gradient")]
public class Gradient : BaseVertexEffect {
        [SerializeField]
        private Color32 topColor = Color.white;
        [SerializeField]
        private Color32 bottomColor = Color.black;
        public override void ModifyVertices(List<UIVertex> vertexList) {
                if (!IsActive()) {
                        return;
                }
                int count = vertexList.Count;
                float bottomY = vertexList[0].position.y;
                float topY = vertexList[0].position.y;
                for (int i = 1; i < count; i++) {
                        float y = vertexList.position.y;
                        if (y > topY) {
                                topY = y;
                        }
                        else if (y < bottomY) {
                                bottomY = y;
                        }
                }
                float uiElementHeight = topY - bottomY;
                for (int i = 0; i < count; i++) {
                        UIVertex uiVertex = vertexList;
                        uiVertex.color = Color32.Lerp(bottomColor, topColor, (uiVertex.position.y - bottomY) / uiElementHeight);
                        vertexList = uiVertex;
                }
        }
}

[color=rgb(51, 102, 153) !important]复制代码%

2021-10-8 10:02:34  
 赞 赞 0

使用道具 登录

1个回答,把该问题分享到群,邀请大神一起回答。
2#
感谢分享
回复 收起回复
2021-10-8 14:50:03   回复
 赞 赞 1

使用道具 登录

CG 游戏行业专业问题

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

本版积分规则

快速回复 返回顶部 返回列表