| 12345678910111213141516171819 |
- using UnityEngine;
- using UnityEngine.UI;
- namespace DevilLink2.UI
- {
- [RequireComponent(typeof(Graphic))]
- public sealed class UIGradient : BaseMeshEffect
- {
- public Color Top = Color.white, Bottom = Color.white;
- public override void ModifyMesh(VertexHelper mesh)
- {
- if (!IsActive() || mesh.currentVertCount == 0) return;
- var vertex = new UIVertex(); float min = float.MaxValue, max = float.MinValue;
- for (int i = 0; i < mesh.currentVertCount; i++) { mesh.PopulateUIVertex(ref vertex, i); min = Mathf.Min(min, vertex.position.y); max = Mathf.Max(max, vertex.position.y); }
- for (int i = 0; i < mesh.currentVertCount; i++)
- { mesh.PopulateUIVertex(ref vertex, i); vertex.color = Color.Lerp(Bottom, Top, Mathf.InverseLerp(min, max, vertex.position.y)); mesh.SetUIVertex(vertex, i); }
- }
- }
- }
|