using System.Collections; using System.Collections.Generic; using System.Globalization; using UnityEngine; namespace TKS { /// /// 타격감 화면 효과(PD 2026-11-10 「타격감을 위한 화면 효과(화면 흔들림 등)도 IB 를 참고해서 적용」) — 값 = 표 Resources/Skills/hit_feel.csv(코드 상수 없음 · C45). /// 키(s_event): hit = 행동 중 유닛이 상대에게 처음 피해를 준 순간(대상마다 1번 · SkillSystem.Hit) · 병종별 = hit_<병종>(있으면 hit 대신). /// 칸: f_shake_time 초 · f_shake_power 흔들림 크기(유닛 키 배수) · f_stop 멈춤(히트 스톱) 초 · f_stop_scale 멈춤 동안 시간 배속(0 = 완전 정지). /// Feel 충돌 연출(PD 2026-11-26 「적과 부딪힐 때 좀 더 임팩트 있게」 · ImpactFeel): f_squash 맞은 유닛 찌그러짐 세기(0~1) · f_squash_time 초 · f_knock 맞은 방향 덜컹(맞은 유닛 키 배수) · /// f_knock_time 초 · f_recoil 친 근접 유닛의 반동 찌그러짐 · f_crit 치명타 배율(흔들림 · 멈춤 · 찌그러짐 · 덜컹) · s_haptic / s_haptic_crit 휴대폰 진동(NiceVibrations 프리셋 이름 · 빈칸 = 없음). /// 가상 실행(Sim.Active · 적 AI 예측) 중에는 아무것도 하지 않는다. /// public static class HitFeel { public const string TablePath = "Skills/hit_feel"; public class Row { public string evt = ""; public float shakeTime; public float shakePower; public float stop; public float stopScale; public float squash, squashTime, knock, knockTime, recoil, crit = 1f; public string haptic = "", hapticCrit = ""; } static Dictionary rows; static Coroutine stopRoutine; static float stopRestoreScale = 1f; public static void Reload() { rows = null; } static void Ensure() { if (rows != null) return; rows = new Dictionary(); var ta = Resources.Load(TablePath); if (ta == null) return; string[] head = null; foreach (var raw in ta.text.Replace("\r", "").Split('\n')) { var line = raw.TrimStart(''); if (line.Trim().Length == 0 || line.TrimStart().StartsWith("#")) continue; var cells = SkillVfx.SplitCsv(line); if (head == null) { head = cells; continue; } var r = new Row(); for (int i = 0; i < head.Length && i < cells.Length; i++) { string k = head[i].Trim(), v = cells[i].Trim(); if (v.Length == 0) continue; switch (k) { case "s_event": r.evt = v.ToLowerInvariant(); break; case "f_shake_time": r.shakeTime = F(v); break; case "f_shake_power": r.shakePower = F(v); break; case "f_stop": r.stop = F(v); break; case "f_stop_scale": r.stopScale = F(v); break; case "f_squash": r.squash = F(v); break; case "f_squash_time": r.squashTime = F(v); break; case "f_knock": r.knock = F(v); break; case "f_knock_time": r.knockTime = F(v); break; case "f_recoil": r.recoil = F(v); break; case "f_crit": r.crit = Mathf.Max(0f, F(v)); break; case "s_haptic": r.haptic = v; break; case "s_haptic_crit": r.hapticCrit = v; break; } } if (r.evt.Length > 0) rows[r.evt] = r; } } static float F(string v) { float f; return float.TryParse(v, NumberStyles.Float, CultureInfo.InvariantCulture, out f) ? f : 0f; } /// 행동 중 유닛 actor 가 target 에 처음 피해를 준 순간(crit = 치명타). public static void OnHit(Unit actor, Unit target, bool crit = false) { if (Sim.Active || actor == null) return; Ensure(); Row r; if (!rows.TryGetValue("hit_" + actor.Type.ToString().ToLowerInvariant(), out r) && !rows.TryGetValue("hit", out r)) return; Play(r, actor, target, crit); } static float Height(Unit u) { return u.ArtHeight > 0f ? u.ArtHeight : u.Radius * 2f; } static void Play(Row r, Unit actor, Unit target, bool crit) { float m = crit ? Mathf.Max(1f, r.crit) : 1f; float h = Height(actor); var cam = Camera.main != null ? Camera.main.GetComponent() : null; if (cam != null && r.shakeTime > 0f && r.shakePower > 0f) cam.Shake(r.shakeTime * m, r.shakePower * h * m); // Feel(ImpactFeel): 맞은 유닛 = 찌그러짐 + 맞은 방향 덜컹 · 맞닿아 친 근접 유닛 = 반동 찌그러짐 · 휴대폰 진동 if (target != null) { Vector2 dir = target.Position - actor.Position; var tf = ImpactFeel.Of(target); if (tf != null) tf.Punch(Mathf.Min(0.9f, r.squash * m), r.squashTime, r.knock * Height(target) * m, r.knockTime, dir); bool touching = !UnitTypeInfo.IsRanged(actor.Type) && dir.magnitude <= actor.Radius + target.Radius + 0.3f; var af = touching ? ImpactFeel.Of(actor) : null; if (af != null) af.Punch(Mathf.Min(0.9f, r.recoil * m), r.squashTime, r.knock * 0.5f * h * m, r.knockTime, -dir); } ImpactFeel.Haptic(crit && r.hapticCrit.Length > 0 ? r.hapticCrit : r.haptic); if (r.stop > 0f && Fx.Runner != null) { if (stopRoutine != null) { Fx.Runner.StopCoroutine(stopRoutine); Time.timeScale = stopRestoreScale; } stopRoutine = Fx.Runner.StartCoroutine(HitStop(r.stop * m, r.stopScale)); } } /// 히트 스톱: 잠깐 시간 배속을 낮췄다가 원래대로(실시간 기준 · 자동 플레이 배속 4 등도 복원). static IEnumerator HitStop(float seconds, float scale) { stopRestoreScale = Time.timeScale; Time.timeScale = Mathf.Max(0f, scale) * stopRestoreScale; yield return new WaitForSecondsRealtime(seconds); Time.timeScale = stopRestoreScale; stopRoutine = null; } } }