using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace TKS.OutGame { /// /// 세로 그러데이션(위 색 → 아래 색 · 그래픽 색에 곱함) — 정점 색만 바꿔 텍스처 · 드로우콜이 늘지 않는다(9 분할 판에도 그대로). /// 이벤트 화면(PD 2026-11-19) 마지막 날 금 칸 · 고른 일차 탭 · 점수 막대 · 화면 바탕(시안 build_mock_e*.py grad()). /// [RequireComponent(typeof(Graphic))] public class UiGradient : BaseMeshEffect { public Color top = Color.white; public Color bottom = Color.white; static readonly List verts = new List(); public static UiGradient Add(Graphic g, Color top, Color bottom) { var gr = g.gameObject.GetComponent(); if (gr == null) gr = g.gameObject.AddComponent(); gr.top = top; gr.bottom = bottom; g.SetVerticesDirty(); return gr; } public override void ModifyMesh(VertexHelper vh) { if (!IsActive() || vh.currentVertCount == 0) return; var rect = graphic.rectTransform.rect; float h = Mathf.Max(0.0001f, rect.height); verts.Clear(); vh.GetUIVertexStream(verts); for (int i = 0; i < verts.Count; i++) { var v = verts[i]; float t = Mathf.Clamp01((v.position.y - rect.yMin) / h); // 0 = 아래 · 1 = 위 Color c = Color.Lerp(bottom, top, t); Color32 o = v.color; v.color = new Color32((byte)(o.r * c.r), (byte)(o.g * c.g), (byte)(o.b * c.b), (byte)(o.a * c.a)); verts[i] = v; } vh.Clear(); vh.AddUIVertexTriangleStream(verts); } } }