using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
[AddComponentMenu("UI/Effects/Gradient")]
public class Gradient : BaseMeshEffect
{
public Color32 topColor = Color.white;
public Color32 bottomColor = Color.black;
public override void ModifyMesh(VertexHelper vh)
{
if (!IsActive())
{
return;
}
var count = vh.currentVertCount;
if (count == 0)
return;
var vertexs = new List<UIVertex>();
for (var i = 0; i < count; i++)
{
var vertex = new UIVertex();
vh.PopulateUIVertex(ref vertex, i);
vertexs.Add(vertex);
}
var topY = vertexs[0].position.y;
var bottomY = vertexs[0].position.y;
for (var i = 1; i < count; i++)
{
var y = vertexs[i].position.y;
if (y > topY)
{
topY = y;
}
【Unity】Image 设置渐变色
于 2022-01-05 14:57:32 首次发布
本文介绍了一种在Unity3D中为UGUI界面创建颜色渐变效果的方法,通过使用Gradient类和BaseMeshEffect基类,实现从上至下的颜色平滑过渡。代码示例展示了如何修改顶点颜色,以达到自定义的顶部和底部颜色渐变效果。

最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



