using UnityEngine; namespace TKS { /// /// 슬링샷 방향 결정 UI — IB(쿠로네코) GameTouchArrow 이식(PD 2026-11-10 「IB 와 같이 슬링샷 조작 시 방향 결정 UI 등을 그대로 이식」). /// 프리팹 = Resources/Fx/TKS_Fx_IB_GameArrow(원본 Assets/VFX/IB/AssetResources/Game/GameArrow · 사본 = Tools/make_ib_fx_copies.cs · IB 스크립트 제거). /// IB 와 같은 동작: 누르면(Ready) 유닛 둘레에 고리 1개 + 퍼지는 고리 3개(3초 동안 0 → 1.3배 · 투명해짐 · 1초 간격 · 반복) · /// 당기면 화살표가 쏠 방향으로 돌고(정면 +Y) 당긴 세기만큼 길어짐(가로 0.8 + v × 0.2 · 세로 v · v = 0.5~1.5) · 화살 끝이 전장 밖이면 안으로 밀어 넣음 · 놓으면(End) 숨김. /// IB 세기 v = 당긴 거리 × 0.6 → 이 게임은 슬링샷 최대 거리 대비 비율로 0.5~1.5 에 맞춘다. 색 = IB 공격 종류 3(하늘색 · 프리팹 기본값). /// public class IbAimArrow : MonoBehaviour { public const string PrefabName = "TKS_Fx_IB_GameArrow"; /// IB GameArrow 공격 종류 3 색(하늘색 · 원본 프리팹 color[2]). static readonly Color RingColor = new Color(0.468f, 0.866f, 0.897f, 1f); const float RingPulseSeconds = 3f; const float RingPulseScale = 1.3f; const float RingStagger = 1f; /// 바닥 고리 정렬(사거리 원 −10·−9 와 같은 바닥 층) · 화살표 = 유닛(0) 아래 층(PD 2026-11-16 「화살표 끝이 유닛을 벗어나지 않게 유닛 레이어 하단으로」 · 표 order_arrow). const int RingOrder = -9; const int ArrowOrder = 10; // 유닛·체력 바 위(PD 2026-11-16 「화살표는 항상 적이나 아군에게 가려지지 않도록」 · 같은 날 앞서 −6 = 유닛 아래로 내렸던 것을 되돌림 · 꼬리 끝은 유닛 가운데에서 시작) Transform root; SpriteRenderer arrow; Transform arrowTip; SpriteRenderer ring; Color ringColor = RingColor; SpriteRenderer[] pulses = new SpriteRenderer[0]; float readyTime; bool ready; Board board; public bool Ready { get { return ready; } } public bool ArrowVisible { get { return arrow != null && arrow.gameObject.activeSelf && ready; } } public void Init(Board b) { board = b; var prefab = SkillVfx.LoadFx(PrefabName); if (prefab == null) return; var go = Instantiate(prefab, transform); go.name = PrefabName; root = go.transform; foreach (var sr in go.GetComponentsInChildren(true)) { if (sr.name == "arrow") arrow = sr; else if (sr.name == "ring01") ring = sr; } var list = new System.Collections.Generic.List(); foreach (var n in new[] { "ring02-01", "ring02-02", "ring02-03" }) { var t = root.Find(n); if (t != null && t.GetComponent() != null) list.Add(t.GetComponent()); } pulses = list.ToArray(); int ringOrder = Mathf.RoundToInt(IbUi.Num("order_ground", RingOrder)); if (arrow != null) { arrowTip = arrow.transform.Find("object"); arrow.sortingOrder = Mathf.RoundToInt(IbUi.Num("order_arrow", ArrowOrder)); var rim = arrow.transform.Find("arrow_rim"); // 하얀 안쪽 테두리 겹그림(색을 곱하지 않음 · PD 2026-11-11 「아웃라인이 사라짐」 · Tools/make_aim_arrow.py) if (rim != null && rim.GetComponent() != null) rim.GetComponent().sortingOrder = arrow.sortingOrder + 1; } if (ring != null) { ring.sortingOrder = ringOrder; ring.color = RingColor; } foreach (var p in pulses) p.sortingOrder = ringOrder; go.SetActive(false); } /// IB Ready: 유닛을 누른 순간 — 고리 표시 · 화살표는 당길 때까지 숨김. public void Begin(Unit u) { if (root == null || u == null) return; ready = true; readyTime = Time.time; root.gameObject.SetActive(true); ApplyCampColor(u); Place(u); if (arrow != null) arrow.gameObject.SetActive(false); } /// /// 유닛 크기에 맞춰 놓기 — IB 와 같은 비율(PD 2026-11-10 「IB 와 화살표 크기도 다름」): 배율 = 이 게임 유닛 반지름 / IB 유닛 반지름 0.496(표 ib_ui.csv) · /// 그러면 고리 지름 = 반지름 × 5.4 · 화살표 = 반지름 × 5.9~17.8 길이(IB 실측 · 화살 그림 피벗 y 0.3 = 유닛 가운데). /// void Place(Unit u) { root.position = new Vector3(u.Position.x, u.Position.y, 0f); float k = IbUi.Scale(u); root.localScale = new Vector3(k, k, 1f); } /// /// 조준 중(게이지 조작 · PD 2026-11-16): dir = 쏠 방향(크기는 쓰지 않음 · 0 이면 화살표 숨김 = 고리만) · power = 이동할 거리 / 최대 거리(0~1 = 게이지) → /// 화살표 길이 s = arrow_s_min~arrow_s_max 사이(가로 arrow_width · 세로 s · 전체 × arrow_scale) — 표의 두 값이 같으면 길이 고정 /// (PD 2026-11-16 4차: 순환 게이지를 따라 길이가 늘다 뚝 줄어드는 움직임이 부자연스러워 고정 · 게이지는 세로 막대가 보여 준다) · /// 화살표는 꼬리 끝이 유닛 가운데에서 시작한다(유닛 뒤로 뻗어 나오지 않음) · 방향만 보이면 되므로 짧게(PD 2026-11-16 3차 · 게이지는 세로 막대가 보여 준다). /// public void Aim(Unit u, Vector2 dir, float power) { if (root == null || u == null) return; if (!ready) Begin(u); Place(u); if (arrow == null) return; bool on = dir.sqrMagnitude > 1e-6f; if (arrow.gameObject.activeSelf != on) arrow.gameObject.SetActive(on); bool drag = AimRules.DragMode && arrow.sprite != null; ShowSplit(on && drag); if (!on) return; if (drag) { AimSplit(u, dir, power); return; } arrow.transform.localPosition = Vector3.zero; arrow.transform.rotation = Quaternion.FromToRotation(Vector3.up, new Vector3(dir.x, dir.y, 0f)); float v = Mathf.Lerp(IbUi.Num("arrow_s_min", 0.5f), IbUi.Num("arrow_s_max", 1.5f), Mathf.Clamp01(power)); float size = IbUi.Num("arrow_scale", 1f); // 화살표 전체 크기 배율(PD 2026-11-16 「조금 더 줄이고」) float width = IbUi.Num("arrow_width", 1f); // 끌기 조준은 위에서 AimSplit(촉 + 화살대)으로 따로 그림 // 가로 = 표 arrow_width(길이와 따로 · PD 2026-11-16 4차 「짧아진 만큼 좌우가 넓어지면」 · 그 전 IB 공식 0.8 + 0.2 s) arrow.transform.localScale = new Vector3(width * size, v * size, 1f); // 꼬리 끝(그림 아래 끝)을 유닛 가운데에 둔다 — 그림 피벗이 꼬리 끝보다 앞(IB = 유닛 가운데)이라 꼬리가 유닛 뒤로 길게 뻗어 나오던 것(PD 2026-11-16 3차 「꼬리쪽이 길게 영웅을 뻗어나옴」) if (arrow.sprite != null) arrow.transform.position += arrow.transform.up * (-arrow.sprite.bounds.min.y * arrow.transform.lossyScale.y); // IB LateUpdate: 화살 끝이 벽(전장 밖)을 넘으면 화살 전체를 안으로 밀어 넣음 if (board != null && arrowTip != null) { Vector2 tip = arrowTip.position; Vector2 inside = board.ClampInside(tip, 0f); if ((inside - tip).sqrMagnitude > 1e-6f) arrow.transform.position += (Vector3)(inside - tip); } } // ---------- 끌기 조준 화살표 = 한 덩어리 도형(PD 2026-11-18 「이어 붙인 그림이 부자연스럽다」 → 촉 · 미늘 · 사선 홈 · 가늘어지는 화살대를 하나로 그림) ---------- Transform shape; Mesh shapeMesh; MeshRenderer shapeRenderer; LineRenderer shapeLine; SpriteRenderer rimSr; readonly Vector3[] sv = new Vector3[14]; readonly Color[] sc = new Color[14]; static readonly int[] ShapeTris = { 0, 1, 2, 0, 2, 3, 3, 2, 4, 3, 4, 5, 6, 7, 8, 6, 8, 9, 9, 8, 10, 9, 10, 11 }; /// 도형 메시(좌 · 우 두 톤) + 테두리 선을 한 번 만든다(root 아래 · root 와 함께 켜고 끔). void BuildShape() { if (shape != null || root == null) return; var rimT = arrow != null ? arrow.transform.Find("arrow_rim") : null; rimSr = rimT != null ? rimT.GetComponent() : null; var go = new GameObject("DragArrowShape"); shape = go.transform; shape.SetParent(root, false); var mat = new Material(Shader.Find("Sprites/Default")); shapeMesh = new Mesh { name = "DragArrow" }; shapeMesh.MarkDynamic(); go.AddComponent().sharedMesh = shapeMesh; shapeRenderer = go.AddComponent(); shapeRenderer.sharedMaterial = mat; shapeRenderer.sortingOrder = arrow != null ? arrow.sortingOrder : ArrowOrder; shapeLine = go.AddComponent(); shapeLine.sharedMaterial = mat; shapeLine.useWorldSpace = true; shapeLine.loop = true; shapeLine.positionCount = 7; shapeLine.numCornerVertices = 2; shapeLine.sortingOrder = shapeRenderer.sortingOrder + 1; shape.gameObject.SetActive(false); } void ShowSplit(bool on) { if (on) BuildShape(); if (shape != null && shape.gameObject.activeSelf != on) shape.gameObject.SetActive(on); if (arrow != null) arrow.enabled = !on; // 한 장 그림은 끌기 조준 동안 숨김(촉 끝 표식 object 는 그대로) if (rimSr != null) rimSr.enabled = !on; } /// /// 꼬리 = 유닛 가장자리(drag_arrow_tail) · 전체 길이 = 이동 거리 × drag_arrow_ratio · 크기 = 유닛 반지름 배수(표 drag_head_len · drag_head_half · drag_shaft_half · drag_shaft_tail · drag_notch) · /// 전체가 촉보다 짧으면 도형 전체를 같은 비율로 줄인다 · 좌 = 진영 색 · 우 = × drag_tone_right(기존 화살표의 두 톤) · 테두리 = drag_outline_color · drag_outline_w. /// void AimSplit(Unit u, Vector2 dir, float power) { if (shape == null) return; float r = u.Radius; Vector2 d = dir.normalized, right = new Vector2(d.y, -d.x); float L = Mathf.Max(r * 0.5f, Mathf.Clamp01(power) * SkillMods.SlingMax(u) * IbUi.Num("drag_arrow_ratio", 0.25f)); float H = r * IbUi.Num("drag_head_len", 1.22f), Wh = r * IbUi.Num("drag_head_half", 1.32f), Ws = r * IbUi.Num("drag_shaft_half", 0.56f); float f = L < H * 1.3f ? L / (H * 1.3f) : 1f; // 짧으면 도형을 함께 줄임 H *= f; Wh *= f; Ws *= f; float Wt = Ws * IbUi.Num("drag_shaft_tail", 0.5f), yN = L - H * IbUi.Num("drag_notch", 0.72f), yB = L - H; Vector2 o = u.Position + d * (r * IbUi.Num("drag_arrow_tail", 1f)); System.Func P = (x, y) => shape.InverseTransformPoint(o + d * y + right * x); for (int s = 0; s < 2; s++) { float m = s == 0 ? -1f : 1f; // 0 = 왼쪽 · 1 = 오른쪽 int b = s * 6; sv[b + 0] = P(0f, L); // 촉 끝 sv[b + 1] = P(m * Wh, yB); // 미늘 끝 sv[b + 2] = P(m * Ws, yN); // 홈(미늘 안쪽이 화살대와 만나는 곳) sv[b + 3] = P(0f, yN); // 가운데 sv[b + 4] = P(m * Wt, 0f); // 화살대 꼬리 sv[b + 5] = P(0f, 0f); // 꼬리 가운데 } Color c = arrow != null ? arrow.color : Color.green; c.a *= IbUi.Num("drag_arrow_alpha", 0.87f); float tone = IbUi.Num("drag_tone_right", 0.86f); Color cr = new Color(c.r * tone, c.g * tone, c.b * tone, c.a); for (int i = 0; i < 12; i++) sc[i] = i < 6 ? c : cr; shapeMesh.Clear(); shapeMesh.SetVertices(sv, 0, 12); shapeMesh.SetColors(sc, 0, 12); shapeMesh.SetTriangles(ShapeTris, 0); shapeMesh.RecalculateBounds(); var lc = IbUi.Col("drag_outline_color", new Color(1f, 1f, 1f, 0.75f)); shapeLine.startColor = shapeLine.endColor = lc; float lw = IbUi.Num("drag_outline_w", 0.022f) * Mathf.Max(0.5f, f); shapeLine.startWidth = shapeLine.endWidth = lw; // 기존 화살표처럼 테두리를 도형 안쪽에 깐다(PD 2026-11-18 「아웃라인이 너무 튄다」): 선 두께 절반만큼 안으로 들여 그림(뾰족한 끝은 조금 더) float k0 = lw * 0.5f; System.Func W = (x, y) => (Vector3)(o + d * y + right * x); shapeLine.SetPosition(0, W(0f, L - k0 * 2f)); shapeLine.SetPosition(1, W(-(Wh - k0 * 2f), yB + k0)); shapeLine.SetPosition(2, W(-(Ws - k0), yN)); shapeLine.SetPosition(3, W(-Mathf.Max(0f, Wt - k0), k0)); shapeLine.SetPosition(4, W(Mathf.Max(0f, Wt - k0), k0)); shapeLine.SetPosition(5, W(Ws - k0, yN)); shapeLine.SetPosition(6, W(Wh - k0 * 2f, yB + k0)); } /// /// 진영별 색(PD 2026-11-11 「촉 진영 유닛을 선택할 때는 화살표를 녹색 계열 · 캐릭터 반경 파란 원도 녹색」): 표 ib_ui.csv aim_arrow_color_<진영> · aim_ring_color_<진영> /// (없으면 aim_arrow_color · aim_ring_color) · 화살표 그림 = 흰 그림(skill-arrow_b_filled)에 색을 곱함. /// void ApplyCampColor(Unit u) { string camp = u != null && !string.IsNullOrEmpty(u.Camp) ? u.Camp.ToLowerInvariant() : "none"; ringColor = IbUi.Col("aim_ring_color_" + camp, IbUi.Col("aim_ring_color", RingColor)); if (ring != null) ring.color = ringColor; if (arrow != null) arrow.color = IbUi.Col("aim_arrow_color_" + camp, IbUi.Col("aim_arrow_color", Color.white)); } /// IB End: 놓거나 취소 — 모두 숨김. public void End() { ready = false; if (root != null) root.gameObject.SetActive(false); } void Update() { if (!ready || root == null) return; float t = Time.time - readyTime; for (int i = 0; i < pulses.Length; i++) { float local = t - i * RingStagger; var p = pulses[i]; if (local < 0f) { p.transform.localScale = Vector3.zero; continue; } float k = (local % RingPulseSeconds) / RingPulseSeconds; p.transform.localScale = new Vector3(RingPulseScale * k, RingPulseScale * k, 1f); var c = ringColor; c.a = 1f - k; p.color = c; } } } }