using System.Collections.Generic;
using UnityEngine;
namespace TKS
{
///
/// 스킬 범위 모양 표(Resources/Skills/skill_indicator.csv · C45 · PD 2026-11-24 「스킬 범위까지 게임에 모두 반영」) —
/// 효과 키(shot_laser · shot_fan …) 또는 범위 종류(radius · point) → 모양(circle · sector · line · none) · 켜기(on).
///
public static class SkillIndicatorTable
{
public const string TablePath = "Skills/skill_indicator";
static Dictionary shapes;
static Dictionary ons;
public static void Reload()
{
shapes = null;
ons = null;
}
static void Ensure()
{
if (shapes != null) return;
shapes = new Dictionary();
ons = new Dictionary();
var ta = Resources.Load(TablePath);
if (ta == null) return;
bool head = true;
foreach (var raw in ta.text.Replace("\r", "").Split('\n'))
{
var line = raw.TrimStart('');
if (line.Trim().Length == 0 || line.TrimStart().StartsWith("#")) continue;
if (head)
{
head = false;
continue;
}
var c = SkillVfx.SplitCsv(line);
if (c.Length < 3) continue;
string key = c[0].Trim();
shapes[key] = c[1].Trim().ToLowerInvariant();
ons[key] = c[2].Trim() != "0";
}
}
/// 모양(circle · sector · line · none) · 줄이 없으면 def.
public static string Shape(string key, string def)
{
Ensure();
string v;
return key != null && shapes.TryGetValue(key, out v) && v.Length > 0 ? v : def;
}
/// 켜기(줄이 없으면 def).
public static bool On(string key, bool def)
{
Ensure();
bool v;
return key != null && ons.TryGetValue(key, out v) ? v : def;
}
}
///
/// 조준 중 스킬 범위 표시(PD 2026-11-24) — 직선(끝에 화살촉 · 양옆 두 줄 · 끝으로 갈수록 옅어지는 띠 · PD 예시) · 부채꼴 · 원(공격 인디케이터 = VectorRing).
/// 모든 부품 = 유닛(정렬 0)보다 아래 층(표 ib_ui skill_shape_order · PD 「레이어를 영웅보다 하단」 = 부채꼴 · 직선이 시작하는 점이 쓰는 영웅 그림에 가려짐) ·
/// 선 두께 = 기준 화면(1080×1920) px(화면 크기에 맞춰 커짐) · 색 · 알파 · 크기 = 표 ib_ui skill_line_* · skill_sector_*.
/// 모양 · 길이 · 폭 = ActionResolver.SkillAim(실제 사격과 같은 궤적 질의) · 어떤 모양으로 그릴지 = 표 skill_indicator.csv.
///
public class SkillShapeIndicator : MonoBehaviour
{
public enum Kind { None, Circle, Sector, Line }
const int ArcSegs = 48;
const int BandSegs = 16;
Mesh fillMesh;
MeshRenderer fillR;
LineRenderer outline;
LineRenderer outlineUnder;
LineRenderer sideL;
LineRenderer sideR;
LineRenderer sideLU;
LineRenderer sideRU;
LineRenderer innerArc;
SpriteRenderer dot;
VectorRing ring;
Material mat;
Kind kind;
ActionResolver.SkillAimShape shape;
readonly List verts = new List();
readonly List cols = new List();
readonly List tris = new List();
/// 지금 그리는 모양(None = 숨김).
public Kind Current { get { return gameObject.activeSelf ? kind : Kind.None; } }
/// 지금 그리는 범위(효과 키 · 시작점 · 길이 · 폭 · 각 · 원).
public ActionResolver.SkillAimShape Shape { get { return shape; } }
/// 부품 정렬 값 중 가장 높은 것(시험 · 유닛 0 보다 작아야 함).
public int TopOrder { get { return outline != null ? outline.sortingOrder : 0; } }
public static SkillShapeIndicator Create(Transform parent, string name)
{
var go = new GameObject(name);
go.transform.SetParent(parent, false);
var si = go.AddComponent();
si.Build();
go.SetActive(false);
return si;
}
void Build()
{
int top = Mathf.Min(-1, Mathf.RoundToInt(IbUi.Num("skill_shape_order", -6f))); // 유닛(0) 아래 · 사거리 원(−8 ~ −11) 위
mat = new Material(Shader.Find("Sprites/Default"));
var fgo = new GameObject("Fill");
fgo.transform.SetParent(transform, false);
fillMesh = new Mesh { name = "SkillShapeFill" };
fillMesh.MarkDynamic();
fgo.AddComponent().sharedMesh = fillMesh;
fillR = fgo.AddComponent();
fillR.sharedMaterial = mat;
fillR.sortingOrder = top - 2;
outlineUnder = NewLine("OutlineUnder", top - 1, true);
outline = NewLine("Outline", top, true);
sideLU = NewLine("SideLUnder", top - 1, false);
sideRU = NewLine("SideRUnder", top - 1, false);
sideL = NewLine("SideL", top, false);
sideR = NewLine("SideR", top, false);
innerArc = NewLine("InnerArc", top, false);
dot = ProceduralSprites.NewSprite(transform, "Dot", ProceduralSprites.RadialGlow, Color.white, 1f, top - 3);
ring = VectorRing.Create(transform, "Ring", top);
ring.gameObject.SetActive(false);
}
LineRenderer NewLine(string name, int order, bool loop)
{
var g = new GameObject(name);
g.transform.SetParent(transform, false);
var lr = g.AddComponent();
lr.useWorldSpace = true;
lr.loop = loop;
lr.numCapVertices = 0;
lr.numCornerVertices = 2;
lr.alignment = LineAlignment.View;
lr.sharedMaterial = mat;
lr.sortingOrder = order;
return lr;
}
/// 표(skill_indicator.csv)가 정한 모양으로 그린다 · 줄이 없거나 꺼져 있으면 숨김.
public void Show(ActionResolver.SkillAimShape s)
{
string sh = SkillIndicatorTable.On(s.Key, true) ? SkillIndicatorTable.Shape(s.Key, "none") : "none";
Kind k = sh == "line" ? Kind.Line : sh == "sector" ? Kind.Sector : sh == "circle" ? Kind.Circle : Kind.None;
if (k == Kind.None)
{
Hide();
return;
}
shape = s;
kind = k;
if (k != Kind.Line) DrawnLength = 0f;
if (!gameObject.activeSelf) gameObject.SetActive(true);
bool lineParts = k == Kind.Line;
bool sectorParts = k == Kind.Sector;
fillR.gameObject.SetActive(lineParts || sectorParts);
outline.gameObject.SetActive(lineParts || sectorParts);
outlineUnder.gameObject.SetActive(lineParts || sectorParts);
sideL.gameObject.SetActive(lineParts);
sideR.gameObject.SetActive(lineParts);
sideLU.gameObject.SetActive(lineParts);
sideRU.gameObject.SetActive(lineParts);
innerArc.gameObject.SetActive(sectorParts);
dot.gameObject.SetActive(sectorParts && IbUi.Num("skill_sector_dot_px", 0f) > 0.5f);
if (k == Kind.Circle)
{
Vector2 c = s.Radius > 0f ? s.Center : s.From + s.Dir * s.Length;
float r = s.Radius > 0f ? s.Radius : Mathf.Max(s.HalfWidth, 0.5f);
ring.transform.position = new Vector3(c.x, c.y, 0f);
if (!ring.gameObject.activeSelf || Mathf.Abs(ring.Radius - r) > 1e-4f)
{
ring.gameObject.SetActive(true);
ring.UseSkillStyle(IbUi.Num("skill_area_disc_alpha", 0.16f));
ring.SetRadius(r);
}
}
else if (ring.gameObject.activeSelf) ring.gameObject.SetActive(false);
Redraw();
}
public void Hide()
{
kind = Kind.None;
if (gameObject.activeSelf) gameObject.SetActive(false);
}
void LateUpdate()
{
if (kind == Kind.Line || kind == Kind.Sector) Redraw(); // 카메라 확대(선 두께) · 숨쉬기
}
static float Wpp()
{
var cam = Camera.main;
return cam != null && cam.orthographic ? cam.orthographicSize * 2f / 1920f : 0.01f; // 기준 화면 1 px 의 월드 길이
}
float Pulse()
{
float sec = Mathf.Max(0.1f, IbUi.Num("skill_ind_pulse_sec", 1.4f));
return 0.8f + 0.2f * Mathf.Sin(Time.unscaledTime * Mathf.PI * 2f / sec);
}
static Color A(Color c, float a)
{
return new Color(c.r, c.g, c.b, Mathf.Clamp01(a));
}
/// 줄 색: 꼬리(0) = tailA → fadeFrac 지점부터 headA(꼬리 쪽만 옅어짐).
static void SetFade(LineRenderer lr, Color c, float tailA, float headA, float fadeFrac)
{
float f = Mathf.Clamp(fadeFrac, 0.02f, 0.98f);
var g = new Gradient();
g.SetKeys(new[] { new GradientColorKey(c, 0f), new GradientColorKey(c, 1f) },
new[] { new GradientAlphaKey(tailA, 0f), new GradientAlphaKey(Mathf.Lerp(tailA, headA, 0.6f), f * 0.5f), new GradientAlphaKey(headA, f), new GradientAlphaKey(headA, 1f) });
lr.colorGradient = g;
}
/// 지금 그린 직선 길이(보이는 전장 안으로 줄인 값 · 시험 · 캡처 기록).
public float DrawnLength { get; private set; }
///
/// 화살촉이 위 탑바 · 아래 정보판 밑에 숨지 않게 그리는 길이를 보이는 전장(카메라 시야 − 표 skill_line_view_*_px)까지로 줄인다
/// (레이저 = 화면 끝까지라 화살촉이 탑바 밑에 묻혔음 · 2026-11-24 1배 캡처 실측) · 쏘는 자리가 그 밖이면 그대로.
///
static float VisibleLength(Vector2 o, Vector2 d, float L, float wpp)
{
var cam = Camera.main;
if (cam == null || !cam.orthographic) return L;
float halfH = cam.orthographicSize, halfW = halfH * cam.aspect;
Vector2 c = cam.transform.position;
float top = c.y + halfH - IbUi.Num("skill_line_view_top_px", 250f) * wpp;
float bottom = c.y - halfH + IbUi.Num("skill_line_view_bottom_px", 380f) * wpp;
float side = IbUi.Num("skill_line_view_side_px", 24f) * wpp;
float left = c.x - halfW + side, right = c.x + halfW - side;
if (o.x < left || o.x > right || o.y < bottom || o.y > top) return L;
float t = L;
if (d.x > 1e-6f) t = Mathf.Min(t, (right - o.x) / d.x);
else if (d.x < -1e-6f) t = Mathf.Min(t, (left - o.x) / d.x);
if (d.y > 1e-6f) t = Mathf.Min(t, (top - o.y) / d.y);
else if (d.y < -1e-6f) t = Mathf.Min(t, (bottom - o.y) / d.y);
return Mathf.Max(0.01f, t);
}
void Redraw()
{
if (kind == Kind.Line) DrawLine();
else if (kind == Kind.Sector) DrawSector();
}
// ---------- 직선(PD 예시 = 끝에 화살촉 · 양옆 두 줄 · 끝으로 갈수록 옅어지는 띠 · 원형 인디케이터와 같은 청록) ----------
void DrawLine()
{
float wpp = Wpp();
float pulse = Pulse();
Color col = IbUi.Col("skill_line_color", new Color(0.25f, 0.85f, 1f, 1f));
Color under = IbUi.Col("skill_line_under_color", new Color(0.04f, 0.23f, 0.29f, 0.55f));
float lw = IbUi.Num("skill_line_px", 5f) * wpp;
float uw = lw + IbUi.Num("range_under_px", 2f) * wpp;
float headA = IbUi.Num("skill_line_alpha_head", 1f) * pulse;
float tailA = IbUi.Num("skill_line_alpha_tail", 0f);
float fillHead = IbUi.Num("skill_line_fill_head", 0.45f) * pulse;
float fillTail = IbUi.Num("skill_line_fill_tail", 0f);
float centerMul = IbUi.Num("skill_line_fill_center", 0.55f);
Color fillCol = IbUi.Col("skill_line_fill_color", new Color(0.59f, 0.92f, 0.96f, 1f)); // 띠 속 = 밝은 청록(모래 위에서 탁한 회갈색이 되지 않게 · QA r1 M2)
Vector2 o = shape.From, d = shape.Dir.sqrMagnitude > 1e-6f ? shape.Dir.normalized : Vector2.up;
Vector2 p = new Vector2(-d.y, d.x);
float L = VisibleLength(o, d, Mathf.Max(0.01f, shape.Length), wpp);
DrawnLength = L;
float hw = Mathf.Max(shape.HalfWidth, IbUi.Num("skill_line_min_half_px", 18f) * wpp);
float headLen = Mathf.Min(L * 0.45f, Mathf.Max(hw * IbUi.Num("skill_line_head_len", 1.3f), IbUi.Num("skill_line_head_min_px", 40f) * wpp));
float headHalf = hw * IbUi.Num("skill_line_head_width", 1.6f);
float bandEnd = L - headLen;
// 띠 = 화살촉 쪽 진함 → 쏘는 영웅 쪽으로 길이 따라 옅어짐(QA r1 B1 · PD 예시) · 양옆 줄 = 영웅 쪽 끝부분만 옅어짐
float fadeLen = Mathf.Max(0.01f, bandEnd * Mathf.Clamp(IbUi.Num("skill_line_fade_frac", 1f), 0.05f, 1f));
float fadeFrac = Mathf.Clamp(IbUi.Num("skill_line_side_fade_frac", 0.45f), 0.02f, 0.98f);
float bw = hw * Mathf.Clamp(IbUi.Num("skill_line_band_frac", 0.7f), 0.1f, 1f); // 띠 반폭 < 줄 간격 = 띠와 양옆 줄 사이 틈(QA r1 M5 · PD 예시 세 줄 구조)
System.Func W = (along, side) => { var v = o + d * along + p * side; return new Vector3(v.x, v.y, 0f); };
// 띠(가로 = 가장자리 진하고 가운데 옅게)
verts.Clear();
cols.Clear();
tris.Clear();
for (int i = 0; i <= BandSegs; i++)
{
float s = bandEnd * i / BandSegs;
float a = Mathf.Lerp(fillHead, fillTail, Mathf.Clamp01((bandEnd - s) / fadeLen)); // 화살촉 쪽(s = bandEnd) = fillHead · 영웅 쪽 = fillTail
verts.Add(W(s, -bw));
verts.Add(W(s, 0f));
verts.Add(W(s, bw));
cols.Add(A(fillCol, a));
cols.Add(A(fillCol, a * centerMul));
cols.Add(A(fillCol, a));
if (i == 0) continue;
int b = (i - 1) * 3;
for (int k = 0; k < 2; k++)
{
int q = b + k;
tris.Add(q); tris.Add(q + 3); tris.Add(q + 4);
tris.Add(q); tris.Add(q + 4); tris.Add(q + 1);
}
}
// 화살촉 채움
int h0 = verts.Count;
verts.Add(W(bandEnd, -headHalf));
verts.Add(W(L, 0f));
verts.Add(W(bandEnd, headHalf));
float ha = IbUi.Num("skill_line_head_fill", 0.45f) * pulse;
cols.Add(A(fillCol, ha));
cols.Add(A(fillCol, ha * 1.2f));
cols.Add(A(fillCol, ha));
tris.Add(h0); tris.Add(h0 + 1); tris.Add(h0 + 2);
ApplyMesh();
// 양옆 두 줄(꼬리에서 옅어짐) + 짙은 받침 선
sideL.positionCount = sideR.positionCount = sideLU.positionCount = sideRU.positionCount = 2;
sideL.SetPosition(0, W(0f, -hw)); sideL.SetPosition(1, W(bandEnd, -hw));
sideR.SetPosition(0, W(0f, hw)); sideR.SetPosition(1, W(bandEnd, hw));
sideLU.SetPosition(0, W(0f, -hw)); sideLU.SetPosition(1, W(bandEnd, -hw));
sideRU.SetPosition(0, W(0f, hw)); sideRU.SetPosition(1, W(bandEnd, hw));
sideL.widthMultiplier = sideR.widthMultiplier = lw;
sideLU.widthMultiplier = sideRU.widthMultiplier = uw;
SetFade(sideL, col, tailA, headA, fadeFrac);
SetFade(sideR, col, tailA, headA, fadeFrac);
SetFade(sideLU, under, tailA * under.a, under.a, fadeFrac);
SetFade(sideRU, under, tailA * under.a, under.a, fadeFrac);
// 화살촉 테두리(밑변 포함 닫힌 세모)
outline.positionCount = outlineUnder.positionCount = 3;
outline.SetPosition(0, W(bandEnd, -headHalf)); outline.SetPosition(1, W(L, 0f)); outline.SetPosition(2, W(bandEnd, headHalf));
outlineUnder.SetPosition(0, W(bandEnd, -headHalf)); outlineUnder.SetPosition(1, W(L, 0f)); outlineUnder.SetPosition(2, W(bandEnd, headHalf));
outline.widthMultiplier = lw;
outlineUnder.widthMultiplier = uw;
outline.colorGradient = Solid(A(col, headA));
outlineUnder.colorGradient = Solid(under);
}
// ---------- 부채꼴(PD 예시 = 붉은 부채꼴 · 원형 인디케이터와 같은 결 = 가장자리가 진한 바닥 빛 + 안쪽 호 + 숨쉬기 · 중심점 = 영웅 그림 밑) ----------
void DrawSector()
{
float wpp = Wpp();
float pulse = Pulse();
Color col = IbUi.Col("skill_sector_color", new Color(1f, 0.35f, 0.24f, 1f));
Color under = IbUi.Col("skill_sector_under_color", new Color(0.29f, 0.06f, 0.04f, 0.55f));
float lw = IbUi.Num("skill_sector_line_px", 6f) * wpp;
float uw = lw + IbUi.Num("range_under_px", 2f) * wpp;
float edgeA = IbUi.Num("skill_sector_fill_edge", 0.38f) * pulse;
float midA = IbUi.Num("skill_sector_fill_mid", 0.1f);
float centerA = IbUi.Num("skill_sector_fill_center", 0.04f);
float glowFrac = Mathf.Clamp(IbUi.Num("skill_sector_glow_frac", 0.3f), 0.05f, 0.95f);
float innerFrac = IbUi.Num("skill_ind_inner", 0.8f);
Vector2 o = shape.From, d = shape.Dir.sqrMagnitude > 1e-6f ? shape.Dir.normalized : Vector2.up;
float R = Mathf.Max(0.05f, shape.Length);
float ang = shape.Angle > 0.1f ? shape.Angle : IbUi.Num("skill_sector_default_angle", 60f);
ang = Mathf.Clamp(ang, 1f, 359f);
float a0 = Mathf.Atan2(d.y, d.x) - ang * 0.5f * Mathf.Deg2Rad;
float step = ang * Mathf.Deg2Rad / ArcSegs;
System.Func P = (i, r) => { float a = a0 + step * i; return new Vector3(o.x + Mathf.Cos(a) * r, o.y + Mathf.Sin(a) * r, 0f); };
verts.Clear();
cols.Clear();
tris.Clear();
verts.Add(new Vector3(o.x, o.y, 0f));
cols.Add(A(col, centerA));
for (int i = 0; i <= ArcSegs; i++)
{
verts.Add(P(i, R * (1f - glowFrac)));
verts.Add(P(i, R));
cols.Add(A(col, midA));
cols.Add(A(col, edgeA));
if (i == 0) continue;
int b = 1 + (i - 1) * 2;
tris.Add(0); tris.Add(b + 2); tris.Add(b);
tris.Add(b); tris.Add(b + 2); tris.Add(b + 3);
tris.Add(b); tris.Add(b + 3); tris.Add(b + 1);
}
ApplyMesh();
// 테두리 = 중심 → 호 → 중심(닫힘)
outline.positionCount = outlineUnder.positionCount = ArcSegs + 2;
outline.SetPosition(0, new Vector3(o.x, o.y, 0f));
outlineUnder.SetPosition(0, new Vector3(o.x, o.y, 0f));
for (int i = 0; i <= ArcSegs; i++)
{
outline.SetPosition(i + 1, P(i, R));
outlineUnder.SetPosition(i + 1, P(i, R));
}
outline.widthMultiplier = lw;
outlineUnder.widthMultiplier = uw;
outline.colorGradient = Solid(A(col, col.a * Mathf.Lerp(0.85f, 1f, pulse)));
outlineUnder.colorGradient = Solid(under);
// 안쪽 호(원형 인디케이터의 안쪽 고리와 같은 자리 · 가늘게)
innerArc.positionCount = ArcSegs + 1;
for (int i = 0; i <= ArcSegs; i++) innerArc.SetPosition(i, P(i, R * innerFrac));
innerArc.widthMultiplier = Mathf.Max(1.5f, IbUi.Num("skill_sector_line_px", 6f) * 0.45f) * wpp;
innerArc.colorGradient = Solid(A(col, col.a * 0.7f));
float dp = IbUi.Num("skill_sector_dot_px", 0f) * wpp;
if (dot.gameObject.activeSelf)
{
dot.transform.position = new Vector3(o.x, o.y, 0f);
dot.transform.localScale = new Vector3(dp, dp * 0.6f, 1f);
dot.color = A(col, 0.9f);
}
}
static Gradient Solid(Color c)
{
var g = new Gradient();
g.SetKeys(new[] { new GradientColorKey(c, 0f), new GradientColorKey(c, 1f) }, new[] { new GradientAlphaKey(c.a, 0f), new GradientAlphaKey(c.a, 1f) });
return g;
}
void ApplyMesh()
{
var t = fillR.transform; // 정점은 월드 좌표로 셈 → 채움 물체 기준으로 바꿈(부모 위치 · 크기와 무관)
for (int i = 0; i < verts.Count; i++) verts[i] = t.InverseTransformPoint(verts[i]);
fillMesh.Clear();
fillMesh.SetVertices(verts);
fillMesh.SetColors(cols);
fillMesh.SetTriangles(tris, 0);
fillMesh.RecalculateBounds();
}
}
}