From 2fa67922f08ef39b4d70bad001592aedf22c9018 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 8 Sep 2021 19:18:57 +0800 Subject: *misc --- Assets/ActionTool/ActionToolGizmos.cs | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'Assets/ActionTool/ActionToolGizmos.cs') diff --git a/Assets/ActionTool/ActionToolGizmos.cs b/Assets/ActionTool/ActionToolGizmos.cs index f1d90911..58069527 100644 --- a/Assets/ActionTool/ActionToolGizmos.cs +++ b/Assets/ActionTool/ActionToolGizmos.cs @@ -1,6 +1,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEditor; namespace ActionTool { @@ -9,13 +10,35 @@ namespace ActionTool { AnimationData m_AnimationData; + AnimationClip m_Clip; + + AnimationClip clip + { + get + { + if (m_AnimationData == null) + return null; + if (m_Clip != null && m_Clip.name == m_AnimationData.animationName) + return m_Clip; + m_Clip = AssetDatabase.LoadAssetAtPath< AnimationClip>(m_AnimationData.animationPath); + return m_Clip; + } + } + float m_CurAnimFrame; + bool m_IsShowRootMotion; + public void SetAnimationData(AnimationData data) { m_AnimationData = data; } + public void ShowRootMotionGizmos(bool show) + { + m_IsShowRootMotion = show; + } + public void SetCurAnimFrame(float frame) { m_CurAnimFrame = frame; @@ -26,6 +49,8 @@ namespace ActionTool DrawRoot(); DrawAxis(); DrawColliders(); + + DrawRootMotion(); } void DrawRoot() @@ -77,7 +102,30 @@ namespace ActionTool } } } + } + void DrawRootMotion() + { + if (m_AnimationData == null) + return; + if (!m_AnimationData.overrideRootMotion) + return; + if (!m_IsShowRootMotion) + return; + if (clip == null) + return; + var rm = m_AnimationData.rootMotionOverrideData; + float frames = clip.length * AnimationData.FPS; + float step = 0.05f; + Vector3 prev = rm.GetPosition(0); + Vector3 cur = prev; + Gizmos.color = Color.white; + for (float f = step; f <= frames + step; f+= step) + { + cur = rm.GetPosition(f); + Gizmos.DrawLine(prev, cur); + prev = cur; + } } } -- cgit v1.1-26-g67d0