Project_WL/Assets/WL/Combat/AttackStepDriver.cs

170 lines
7.8 KiB
C#
Raw Normal View History

WL 리뉴얼 세션 2026-09-06~07 (#760~#800) — 전투·배경·UI·타격감 (조직 PD 로그 #746~#800 · 대화로그 §14~§24) - 전투: Knight@Attack1~3_S 3콤보(4 컨트롤러·클래스별 서브클립) · 타겟팅 4규칙(정면 우선·재타겟·즉시 공격·어그로 금지 · WLTargetingSettings) · 대쉬 후 공격(Stander@Chase_Start · DashDriver · 5 m · 사정거리+0.8 · 근거리 적 우선) · 공격 이동 FrameTable(발 접지 실측 표 · AttackRootMotion) · 충돌 반경/투사체 0.3 배(WLCollisionTuning) · 무적(임시)·펫 금지(WLGameplaySettings) - 검기: NamuFX Slash_B 배리언트 Effect_WLSwingArc 원 피팅 정합 배치 + 캘리브레이션(SlashArcMeasure · SlashTrailSettings) · 찌르기 Effect_WLStab 대기 · 램프 리본(BladeTrail · WL_BladeRibbon.shader · T_WL_BladeRibbonRamp) 보존(drawRibbon 0) - 타격감: Assets/WL/Feel(WLHitFeel · 히트스톱 0.03 · 셰이크 0.10 m · 몹 펀치 1.12 · Actor.Get_Damage 훅 1줄 · 원본 RealCamera 셰이크 결함 대체) - 배경/맵: LMHPOLY Demo_01~10 → WL_Nature01~10(프리팹·씬·NavMesh·스포너·BattleMapConfig) · 물(ToonWaterU) · 포스트 블룸 0.9/0.3 · 잔디(BruteForce·드레싱) 제거 · 마젠타 머티리얼 URP 변환 - UI: 세로 HUD(WL_HUD · 하단 5메뉴 폭 전체 · 채팅/전투 패드 숨김 · WLIngameUiOverride) · Title/TitleInfo 1080×1920 Expand + 배경 높이 fit(WLBackgroundFit) · 로딩 SortOrder_5(WLRawImageAspectSync · 초점표 8장) · Loading1~8 ASTC 6×6 - 도구: AgentScripts/*(LightProbe · WL_MapSwitch · WL760~WL800 프로브/집행/검증 · 상단 사용법 주석) · 에디터 락 프로토콜 파일(staging) - 제외(별도 커밋 예정): Assets/LMHPOLY(703 MB) · Assets/Feel(422 MB) · Assets/Shinabro(300 MB) — 에셋 스토어/구 WL 팩 원본 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-06 23:24:25 +00:00
// ─────────────────────────────────────────────────────────────────────────────
// AttackStepDriver.cs — 공격 모션에 맞춘 전진 이동 (PD 지시 #762)
//
// 클립의 `Move(float)` 애니메이션 이벤트가 들어오면 그 시점부터
// attackStepSeconds 동안 캐릭터 전방으로 (float × attackStepScale) m 를
// **NavMeshAgent.Move** 로 나눠서 밀어 준다.
//
// ── 왜 NavMeshAgent.Move 인가 ───────────────────────────────────────────────
// · transform.position 을 직접 더하면 지형·장애물을 통과하고 에이전트 내부 위치와
// 어긋나 다음 이동 명령에서 순간이동한다.
// · NavMeshAgent.Move 는 이동을 NavMesh 표면에 투영하고 에이전트 내부 상태도 함께
// 갱신한다 → 지형 관통이 없고 이후 조이스틱 이동과도 충돌하지 않는다.
// · CharacterController 는 이 프로젝트에 없다(Actor 는 NavMeshAgent 만 쓴다).
//
// ── 취소 조건 ───────────────────────────────────────────────────────────────
// 사망 · CC(피격/경직/넉백) · 정지(IsStop) · 공격 상태 이탈(회피·피격으로 전환)
// → PCActor.WL_CanAttackStep() 한 곳에서 판정한다(IsStop 이 protected 라 Actor 밖에서 못 읽는다).
//
// 대상은 PC 뿐이다. 펫·몬스터는 PCActor 가 아니므로 이 경로를 타지 않는다.
//
// 🔴 어셈블리 주의: Assets/WL/Combat/ 에 .asmdef 를 만들지 말 것.
// ─────────────────────────────────────────────────────────────────────────────
using UnityEngine;
using UnityEngine.AI;
namespace WL.Combat
{
/// <summary>
/// 공격 클립의 Move 이벤트를 받아 캐릭터를 전방으로 조금씩 밀어 준다.
/// 필요할 때 런타임으로 자동 부착되므로 프리팹을 미리 손댈 필요가 없다.
/// </summary>
[DisallowMultipleComponent]
public sealed class AttackStepDriver : MonoBehaviour
{
private PCActor _pc;
private NavMeshAgent _agent;
private WLCombatMotionSettings _cfg;
private bool _active;
private float _elapsed;
private float _duration;
private float _total; // 이번 스텝의 총 이동 거리(m)
private float _moved; // 지금까지 실제로 넣은 이동량(m · 계획값)
private Vector3 _dir;
private Vector3 _startPos;
// ── 검증용 (Play 중 CLI 로 읽는다 · 게임 로직은 쓰지 않는다) ────────────
/// <summary>마지막 전진의 계획 거리(m).</summary>
public static float LastPlannedDistance;
/// <summary>마지막 전진의 실제 이동 거리(m · NavMesh 투영 후).</summary>
public static float LastActualDistance;
/// <summary>지금까지 전진을 시작한 횟수.</summary>
public static int StepCount;
/// <summary>마지막 전진 요약(검증용 문자열).</summary>
public static string LastInfo;
/// <summary>전진 중인가.</summary>
public bool IsStepping { get { return _active; } }
/// <summary>
/// 전진을 시작한다. 대상이 PC 가 아니거나 설정이 없으면 아무 일도 하지 않는다.
/// <paramref name="b"/> = 클립 Move 이벤트의 float 파라미터(전진 거리 m).
/// </summary>
public static bool Begin(PCActor pc, float b)
{
if (pc == null || b <= 0f) return false;
var cfg = WLCombatMotionSettings.Instance;
if (cfg == null || !cfg.enableAttackStep) return false;
if (cfg.attackMoveMode != AttackMoveMode.FixedStep) return false; // PD #789/#791: 고정 전진은 FixedStep 모드에서만 (FrameTable/ClipRootMotion 과 이중 적용 방지)
var agent = pc.Get_Agent();
if (agent == null || !agent.enabled || !agent.isOnNavMesh) return false;
var driver = pc.GetComponent<AttackStepDriver>();
if (driver == null) driver = pc.gameObject.AddComponent<AttackStepDriver>();
return driver.BeginInternal(pc, agent, cfg, b);
}
private bool BeginInternal(PCActor pc, NavMeshAgent agent, WLCombatMotionSettings cfg, float b)
{
_pc = pc;
_agent = agent;
_cfg = cfg;
float dist = Mathf.Min(b * cfg.attackStepScale, Mathf.Max(cfg.attackStepMaxDistance, 0f));
if (dist <= 0.0001f) return false;
_dir = transform.forward;
_dir.y = 0f;
if (_dir.sqrMagnitude < 1e-6f) return false;
_dir.Normalize();
_total = dist;
_moved = 0f;
_elapsed = 0f;
_duration = Mathf.Max(cfg.attackStepSeconds, 0.01f);
_startPos = transform.position;
_active = true;
StepCount++;
LastPlannedDistance = dist;
#if UNITY_EDITOR
if (cfg.verboseLog)
Debug.Log(string.Format("[WL #762] 전진 시작 b={0:F2} → {1:F2}m / {2:F2}s anim={3}",
b, dist, _duration, pc.Get_CurAnim()), this);
#endif
return true;
}
/// <summary>전진을 즉시 멈춘다(피격·회피·사망).</summary>
public void Cancel()
{
if (!_active) return;
_active = false;
LastActualDistance = Vector3.Distance(_startPos, transform.position);
LastInfo = string.Format("cancel planned={0:F2} actual={1:F2}", _total, LastActualDistance);
}
private void Update()
{
if (!_active) return;
if (_pc == null || _agent == null || !_agent.enabled || !_agent.isOnNavMesh || !_pc.WL_CanAttackStep())
{
Cancel();
return;
}
// 대상을 통과해 지나가지 않도록, 이미 붙어 있으면 더 밀지 않는다.
if (_cfg != null && _cfg.attackStepStopDistance > 0f)
{
var target = _pc.Get_Target();
if (target != null && !target.IsDead())
{
Vector3 d = target.Get_position() - transform.position;
d.y = 0f;
if (d.magnitude <= _cfg.attackStepStopDistance) { Cancel(); return; }
}
}
_elapsed += Time.deltaTime;
float p = Mathf.Clamp01(_elapsed / _duration);
// ease-out: 앞이 빠르고 뒤가 느리다. 실측 루트 커브가 초반에 몰려 있는 형태와 맞는다.
float eased = (_cfg != null && _cfg.attackStepEaseOut) ? 1f - (1f - p) * (1f - p) : p;
float want = _total * eased - _moved;
if (want > 0f)
{
_moved += want;
_agent.Move(_dir * want); // NavMesh 표면에 투영된다 — 지형 관통 없음
}
if (p >= 1f)
{
_active = false;
LastActualDistance = Vector3.Distance(_startPos, transform.position);
LastInfo = string.Format("done planned={0:F2} actual={1:F2}", _total, LastActualDistance);
#if UNITY_EDITOR
if (_cfg != null && _cfg.verboseLog) Debug.Log("[WL #762] 전진 종료 " + LastInfo, this);
#endif
}
}
private void OnDisable() { Cancel(); }
}
}