Skip to content

Instantly share code, notes, and snippets.

@RimuruDev
Created August 1, 2024 08:26
Show Gist options
  • Save RimuruDev/716340bc7d80b7e02d1716928da0f3c7 to your computer and use it in GitHub Desktop.
Save RimuruDev/716340bc7d80b7e02d1716928da0f3c7 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
public class VerticalGradient : BaseMeshEffect
{
public Color topColor = Color.white;
public Color bottomColor = Color.white;
public override void ModifyMesh(VertexHelper vertexHelper)
{
if (this.enabled)
{
UIVertex vertex = default;
float[] t = new float[4] { 0f, 1f, 1f, 0f };
for (int i = 0; i < vertexHelper.currentVertCount; i++)
{
vertexHelper.PopulateUIVertex(ref vertex, i);
vertex.color *= Color.Lerp(this.bottomColor, this.topColor, t[i]);
vertexHelper.SetUIVertex(vertex, i);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment