summaryrefslogtreecommitdiff
path: root/Assets/Tools/ActionTool/ActionToolGizmos.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-09-15 12:50:26 +0800
committerchai <chaifix@163.com>2021-09-15 12:50:26 +0800
commit98f31f197a126850a5878cd6e583ae6dbf64ab3d (patch)
tree207f726fb027c227d2fd58bd1bc340cb3a7eaf67 /Assets/Tools/ActionTool/ActionToolGizmos.cs
parentad950c25abdf7f5a2f0428863d4035e9eb168fd5 (diff)
*rename
Diffstat (limited to 'Assets/Tools/ActionTool/ActionToolGizmos.cs')
-rw-r--r--Assets/Tools/ActionTool/ActionToolGizmos.cs139
1 files changed, 139 insertions, 0 deletions
diff --git a/Assets/Tools/ActionTool/ActionToolGizmos.cs b/Assets/Tools/ActionTool/ActionToolGizmos.cs
new file mode 100644
index 00000000..938d2c51
--- /dev/null
+++ b/Assets/Tools/ActionTool/ActionToolGizmos.cs
@@ -0,0 +1,139 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEditor;
+
+namespace ActionTool
+{
+
+ public class ActionToolGizmos : MonoBehaviour
+ {
+ 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;
+
+ GameObject m_UnitRoot;
+
+ public void Initialize(GameObject unitRoot)
+ {
+ m_UnitRoot = unitRoot;
+ }
+
+ public void SetAnimationData(AnimationData data)
+ {
+ m_AnimationData = data;
+ }
+
+ public void ShowRootMotionGizmos(bool show)
+ {
+ m_IsShowRootMotion = show;
+ }
+
+ public void SetCurAnimFrame(float frame)
+ {
+ m_CurAnimFrame = frame;
+ }
+
+ void OnDrawGizmos()
+ {
+ DrawRoot();
+ DrawAxis();
+ DrawColliders();
+
+ DrawRootMotion();
+ }
+
+ void DrawRoot()
+ {
+ Gizmos.color = Color.yellow;
+ Gizmos.DrawCube(m_UnitRoot.transform.position, new Vector3(0.1f, 0.1f, 0.1f));
+ }
+
+ void DrawAxis()
+ {
+ Gizmos.color = Color.red;
+ Gizmos.DrawLine(-Vector3.right * 1000, Vector3.right * 1000);
+ Gizmos.color = Color.green;
+ Gizmos.DrawLine(Vector3.zero, Vector3.up * 1000);
+ Gizmos.color = Color.blue;
+ Gizmos.DrawLine(Vector3.zero, Vector3.forward * 1000);
+ }
+
+ void DrawColliders()
+ {
+ if (m_AnimationData == null)
+ return;
+ DrawBoxes(m_AnimationData.hurtBoxes, Color.green);
+ DrawBoxes(m_AnimationData.hitBoxes, Color.red);
+ }
+
+ void DrawBoxes(List<ColliderData> boxes, Color color)
+ {
+ if (boxes != null && boxes.Count > 0)
+ {
+ for (int i = 0; i < boxes.Count; ++i)
+ {
+ var box = boxes[i];
+ if (box != null)
+ {
+ var info = box.GetColliderInfo(m_CurAnimFrame);
+ if (!info.active)
+ continue;
+ Vector3 pos = info.position;
+ switch (box.pivot)
+ {
+ case ColliderBox.Pivot.MiddleBottom:
+ pos.y += info.size.y / 2;
+ break;
+ }
+ pos += m_UnitRoot.transform.position;
+ Gizmos.color = color * 0.5f;
+ Gizmos.DrawCube(pos, info.size);
+ }
+ }
+ }
+ }
+
+ 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;
+ }
+ }
+
+ }
+}