85 lines
3.2 KiB
C#
85 lines
3.2 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
[RequireComponent(typeof(CanvasRenderer))]
|
|
public class MenuEchoWaveRenderer : MaskableGraphic
|
|
{
|
|
[Range(24, 120)]
|
|
public int segments = 72;
|
|
|
|
[Tooltip("Текущий радиус кольца в пикселях")]
|
|
public float radius = 0f;
|
|
|
|
[Tooltip("Толщина светящейся полосы волны")]
|
|
public float thickness = 28f;
|
|
|
|
[Tooltip("Яркость/прозрачность волны (0 - 1)")]
|
|
[Range(0f, 1f)]
|
|
public float waveAlpha = 1f;
|
|
|
|
[Header("Цвета свечения")]
|
|
public Color waveColor = new Color(0.00f, 0.90f, 1.0f, 1.0f); // Неоновый циан
|
|
public Color coreColor = new Color(0.40f, 1.00f, 0.95f, 1.0f); // Яркое ядро
|
|
|
|
public void SetWave(float currentRadius, float currentThickness, float currentAlpha, Color baseColor, Color highlightColor)
|
|
{
|
|
radius = currentRadius;
|
|
thickness = currentThickness;
|
|
waveAlpha = Mathf.Clamp01(currentAlpha);
|
|
waveColor = baseColor;
|
|
coreColor = highlightColor;
|
|
SetVerticesDirty();
|
|
}
|
|
|
|
protected override void OnPopulateMesh(VertexHelper vh)
|
|
{
|
|
vh.Clear();
|
|
if (radius <= 0.5f || thickness <= 0.5f || waveAlpha <= 0.001f) return;
|
|
|
|
float halfThick = thickness * 0.5f;
|
|
float rInner = Mathf.Max(0f, radius - halfThick);
|
|
float rCenter = radius;
|
|
float rOuter = radius + halfThick;
|
|
|
|
Color edgeCol = new Color(waveColor.r, waveColor.g, waveColor.b, 0f);
|
|
Color midCol = new Color(coreColor.r, coreColor.g, coreColor.b, coreColor.a * waveAlpha);
|
|
|
|
float angleStep = 360f / segments;
|
|
|
|
for (int i = 0; i < segments; i++)
|
|
{
|
|
float a1 = i * angleStep * Mathf.Deg2Rad;
|
|
float a2 = (i + 1) * angleStep * Mathf.Deg2Rad;
|
|
|
|
Vector2 dir1 = new Vector2(Mathf.Cos(a1), Mathf.Sin(a1));
|
|
Vector2 dir2 = new Vector2(Mathf.Cos(a2), Mathf.Sin(a2));
|
|
|
|
Vector2 pIn1 = dir1 * rInner;
|
|
Vector2 pIn2 = dir2 * rInner;
|
|
Vector2 pMid1 = dir1 * rCenter;
|
|
Vector2 pMid2 = dir2 * rCenter;
|
|
Vector2 pOut1 = dir1 * rOuter;
|
|
Vector2 pOut2 = dir2 * rOuter;
|
|
|
|
// 1. Полоса: от внутреннего прозрачного края к яркому центру
|
|
int idx1 = vh.currentVertCount;
|
|
vh.AddVert(pIn1, edgeCol, Vector2.zero);
|
|
vh.AddVert(pMid1, midCol, Vector2.zero);
|
|
vh.AddVert(pMid2, midCol, Vector2.zero);
|
|
vh.AddVert(pIn2, edgeCol, Vector2.zero);
|
|
vh.AddTriangle(idx1, idx1 + 1, idx1 + 2);
|
|
vh.AddTriangle(idx1, idx1 + 2, idx1 + 3);
|
|
|
|
// 2. Полоса: от яркого центра к внешнему прозрачному краю
|
|
int idx2 = vh.currentVertCount;
|
|
vh.AddVert(pMid1, midCol, Vector2.zero);
|
|
vh.AddVert(pOut1, edgeCol, Vector2.zero);
|
|
vh.AddVert(pOut2, edgeCol, Vector2.zero);
|
|
vh.AddVert(pMid2, midCol, Vector2.zero);
|
|
vh.AddTriangle(idx2, idx2 + 1, idx2 + 2);
|
|
vh.AddTriangle(idx2, idx2 + 2, idx2 + 3);
|
|
}
|
|
}
|
|
}
|