查看: 2068|回复: 2
打印 上一主题 下一主题

[经验分享] Unity文字渐变Gradient 5.4更改

[复制链接]

2

主题

7

听众

770

积分

初级设计师

Rank: 3Rank: 3

纳金币
60
精华
0

最佳新人 活跃会员 热心会员 灌水之王 突出贡献

跳转到指定楼层
楼主
发表于 2016-9-3 21:08:41 |只看该作者 |倒序浏览
从5.22开始就遇到这个问题,
现在又遇到了,研究修改了1个多小时终于解决不报错了,分享给大家

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using System;

[AddComponentMenu("UI/Effects/Gradient")]
public class Gradient : BaseMeshEffect
{
    [SerializeField]
    private Color32 topColor = Color.white;
    [SerializeField]
    private Color32 bottomColor = Color.black;

    public override void ModifyMesh(VertexHelper vh)
    {
        if (!this.IsActive())
            return;

        List<UIVertex> vertexList = new List<UIVertex>();
        vh.GetUIVertexStream(vertexList);

        ModifyVertices(vertexList);

        vh.Clear();
        vh.AddUIVertexTriangleStream(vertexList);
    }

    public void ModifyVertices(List<UIVertex> vertexList)
    {
        if (!IsActive())
        {
            return;
        }

        int count = vertexList.Count;
        if (count > 0)
        {
            float bottomY = vertexList[0].position.y;
            float topY = vertexList[0].position.y;

            for (int i = 1; i < count; i++)
            {
                float y = vertexList[i].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[i];
                uiVertex.color = Color32.Lerp(bottomColor, topColor, (uiVertex.position.y - bottomY) / uiElementHeight);
                vertexList[i] = uiVertex;
            }
        }
    }
}

分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

0

主题

1

听众

40

积分

设计初学者

Rank: 1

纳金币
2
精华
0
沙发
发表于 2016-9-4 20:25:48 |只看该作者
虽然看不懂但是 感觉很吊的样子
回复

使用道具 举报

0

主题

1

听众

322

积分

设计实习生

Rank: 2

纳金币
5
精华
0
板凳
发表于 2016-12-29 17:10:36 |只看该作者
给力   我下的一个旧插件正好报这个错。=w=
回复

使用道具 举报

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

关闭

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

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

GMT+8, 2024-5-14 21:35 , Processed in 0.077407 second(s), 28 queries .

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

© 2008-2019 Narkii Inc.

回顶部