思路和纵向渐变一样,区别只在于纵向渐变是取顶点距离最底部距离/总渐变高度参与插值计算,而横向渐变则是取顶点距离最左侧距离/总渐变宽度参与插值计算
代码:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[AddComponentMenu("UI/Effect/HorizontalGradient")]
[RequireComponent(typeof(UnityEngine.UI.Text))]
public class HorizontalGradient : BaseMeshEffect
{
public Color32 leftColor = new Color32(255, 255, 255, 255);
public Color32 rightColor = new Color32(0, 0, 0, 255);
public override void ModifyMesh(VertexHelper vh)
{
if (!IsActive() || vh.currentVertCount < 4)
{
return;
}