77 lines
4.9 KiB
C#
77 lines
4.9 KiB
C#
// WL791_Probe.cs — #791 접지 발 슬라이딩 실측 (Play 전용 · 읽기 전용)
|
|
// unity command run_script --file AgentScripts/WL791_Probe.cs --entry WL791_Probe.Watch --args '[9.0]'
|
|
// unity command run_script --file AgentScripts/WL791_Probe.cs --entry WL791_Probe.Report
|
|
// 매 프레임 PC 의 좌/우 발(Humanoid LeftFoot/RightFoot) 월드 좌표와 접지 여부(발 높이 ≤ 지면+6 cm)를 기록.
|
|
// 접지가 연속되는 구간(플랜트)마다 발의 XZ 이동량 = "슬라이딩". 공격 클립별 최대/합계 슬라이딩(cm)과 액터 전진량을 낸다.
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
|
|
public static class WL791_Probe
|
|
{
|
|
const string Out = "Screenshots_WL/combat6/p_wl791.txt";
|
|
|
|
class Host : MonoBehaviour
|
|
{
|
|
class Plant { public string clip; public string foot; public Vector3 start; public float slide; public int frames; }
|
|
public IEnumerator Co(float seconds)
|
|
{
|
|
var sb = new StringBuilder();
|
|
var me = Object.FindObjectsByType<MyActor>(FindObjectsInactive.Exclude, FindObjectsSortMode.None).FirstOrDefault() as PCActor;
|
|
if (me == null) { Done(sb.AppendLine("PCActor none")); yield break; }
|
|
var anim = me.m_animation;
|
|
var lf = anim.GetBoneTransform(HumanBodyBones.LeftFoot); var rf = anim.GetBoneTransform(HumanBodyBones.RightFoot);
|
|
if (lf == null || rf == null) { Done(sb.AppendLine("foot bones null")); yield break; }
|
|
var cfg = WL.Combat.WLCombatMotionSettings.Instance;
|
|
sb.AppendLine("mode=" + (cfg != null ? cfg.attackMoveMode.ToString() : "?") + " scale=" + (cfg != null ? cfg.frameTableScale.ToString("F2") : "?"));
|
|
var plants = new List<Plant>(); Plant curL = null, curR = null;
|
|
var clipStart = new Dictionary<string, Vector3>(); var clipMove = new Dictionary<string, float>(); string lastClip = ""; Vector3 lastClipStart = me.transform.position;
|
|
float t0 = Time.time;
|
|
while (Time.time - t0 < seconds)
|
|
{
|
|
string clip = "(none)"; var ci = anim.GetCurrentAnimatorClipInfo(0); if (ci.Length > 0) clip = ci[0].clip.name;
|
|
if (clip != lastClip)
|
|
{
|
|
if (lastClip != "") { float mv = Vector3.Distance(new Vector3(me.transform.position.x, 0, me.transform.position.z), new Vector3(lastClipStart.x, 0, lastClipStart.z)); clipMove[lastClip + "#" + clipMove.Count] = mv; }
|
|
lastClip = clip; lastClipStart = me.transform.position;
|
|
}
|
|
float groundY = me.transform.position.y;
|
|
Track(ref curL, "L", lf.position, groundY, clip, plants);
|
|
Track(ref curR, "R", rf.position, groundY, clip, plants);
|
|
yield return null;
|
|
}
|
|
if (curL != null) plants.Add(curL); if (curR != null) plants.Add(curR);
|
|
sb.AppendLine("== 접지 플랜트별 슬라이딩 (cm · 프레임≥3 만) ==");
|
|
foreach (var g in plants.Where(p => p.frames >= 3).GroupBy(p => p.clip.Replace("_10501", "").Replace("_10101", "")))
|
|
sb.AppendLine(string.Format(" {0,-14} plants={1,2} maxSlide={2,5:F1} avgSlide={3,5:F1}", g.Key, g.Count(), g.Max(p => p.slide) * 100f, g.Average(p => p.slide) * 100f));
|
|
sb.AppendLine("== 클립별 액터 XZ 이동 (m) ==");
|
|
foreach (var kv in clipMove) sb.AppendLine(" " + kv.Key + " " + kv.Value.ToString("F2"));
|
|
sb.AppendLine("AttackRootMotion apply=" + WL.Combat.AttackRootMotion.ApplyCount + " accum=" + WL.Combat.AttackRootMotion.SwingAccum.ToString("F2") + " m");
|
|
Done(sb);
|
|
}
|
|
static void Track(ref Plant cur, string foot, Vector3 pos, float groundY, string clip, List<Plant> plants)
|
|
{
|
|
bool grounded = pos.y - groundY <= 0.18f; // 발 본 높이는 루트 기준 최저 0.12 m(실측) → +6 cm
|
|
if (grounded)
|
|
{
|
|
if (cur == null) cur = new Plant { clip = clip, foot = foot, start = pos, slide = 0f, frames = 0 };
|
|
cur.frames++;
|
|
var d = pos - cur.start; d.y = 0f; cur.slide = Mathf.Max(cur.slide, d.magnitude);
|
|
}
|
|
else if (cur != null) { plants.Add(cur); cur = null; }
|
|
}
|
|
void Done(StringBuilder sb) { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Out)); System.IO.File.WriteAllText(Out, sb.ToString()); Destroy(gameObject); }
|
|
}
|
|
|
|
public static object Watch(float seconds)
|
|
{
|
|
if (!Application.isPlaying) return "not playing";
|
|
if (GameObject.Find("__wl791") != null) return "already running";
|
|
var h = new GameObject("__wl791").AddComponent<Host>(); h.StartCoroutine(h.Co(seconds));
|
|
return "started " + seconds + "s";
|
|
}
|
|
public static object Report() { return System.IO.File.Exists(Out) ? System.IO.File.ReadAllText(Out) : "(none)"; }
|
|
}
|