summaryrefslogtreecommitdiff
path: root/Assets/ActionTool/Editor
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-07-07 18:47:37 +0800
committerchai <chaifix@163.com>2021-07-07 18:47:37 +0800
commita13f10139d33264fc9ebc5a15c75faf16fc7757e (patch)
tree9d6c40a21fc873c6e25ff4bbdeba663a73927427 /Assets/ActionTool/Editor
parent1bb4971cffac3851a119f16e815bfe42abfc2df6 (diff)
+Action Tool
Diffstat (limited to 'Assets/ActionTool/Editor')
-rw-r--r--Assets/ActionTool/Editor/ActionColliderEditor.cs12
-rw-r--r--Assets/ActionTool/Editor/ActionColliderEditor.cs.meta11
-rw-r--r--Assets/ActionTool/Editor/ActionData.cs225
-rw-r--r--Assets/ActionTool/Editor/ActionData.cs.meta11
-rw-r--r--Assets/ActionTool/Editor/ActionEditor.cs120
-rw-r--r--Assets/ActionTool/Editor/ActionEditor.cs.meta11
-rw-r--r--Assets/ActionTool/Editor/ActionEditorStyles.cs44
-rw-r--r--Assets/ActionTool/Editor/ActionEditorStyles.cs.meta11
-rw-r--r--Assets/ActionTool/Editor/ActionEditorUI.cs65
-rw-r--r--Assets/ActionTool/Editor/ActionEditorUI.cs.meta11
-rw-r--r--Assets/ActionTool/Editor/ActionEventEditor.cs23
-rw-r--r--Assets/ActionTool/Editor/ActionEventEditor.cs.meta11
-rw-r--r--Assets/ActionTool/Editor/ActionManager.cs154
-rw-r--r--Assets/ActionTool/Editor/ActionManager.cs.meta11
-rw-r--r--Assets/ActionTool/Editor/ActionPreviewEditor.cs166
-rw-r--r--Assets/ActionTool/Editor/ActionPreviewEditor.cs.meta11
16 files changed, 897 insertions, 0 deletions
diff --git a/Assets/ActionTool/Editor/ActionColliderEditor.cs b/Assets/ActionTool/Editor/ActionColliderEditor.cs
new file mode 100644
index 00000000..e28798f1
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionColliderEditor.cs
@@ -0,0 +1,12 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEditor;
+
+namespace ActionTool
+{
+
+ public class ActionColliderEditor : EditorWindow
+ {
+ }
+} \ No newline at end of file
diff --git a/Assets/ActionTool/Editor/ActionColliderEditor.cs.meta b/Assets/ActionTool/Editor/ActionColliderEditor.cs.meta
new file mode 100644
index 00000000..393c3deb
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionColliderEditor.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 3fcd174d4fc741a4986f1a08413e6ada
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/ActionTool/Editor/ActionData.cs b/Assets/ActionTool/Editor/ActionData.cs
new file mode 100644
index 00000000..33bb5c71
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionData.cs
@@ -0,0 +1,225 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Linq;
+using UnityEngine;
+using UnityEditor;
+
+namespace ActionTool
+{
+ // 正在编辑的动画
+ public class ActionData
+ {
+ private Animator m_Animator;
+ private AnimationClip m_Clip;
+
+ private AnimationData m_AnimData; // asset
+
+ private List<AnimationEventBase> m_EventList { get { return m_AnimData != null ? m_AnimData.animationEvents : null; } }
+
+ private AnimationEventBase m_CurEventInfo; // 当前正在编辑的event
+
+ private float m_TotalFrame;
+ private int m_PrevFrame;
+
+ private float m_AnimRate; // 每帧时间
+
+ private float m_CurAnimFrame;
+ private double m_PrevLocalTime;
+
+ private const string kStateName = "Action";
+
+ public void Initialize(Animator animator, AnimationClip clip)
+ {
+ m_Animator = animator;
+ m_Clip = clip;
+ if(m_Clip != null)
+ {
+ m_TotalFrame = m_Clip.length * ActionManager.FPS;
+ m_AnimRate = m_Clip.length / m_TotalFrame;
+ }
+ m_PrevFrame = -1;
+ m_CurAnimFrame = 0;
+ m_PrevLocalTime = 0;
+ m_Animator.Play(kStateName, 0, 0);
+ }
+
+ public void SetCurrentAnimTime(float time)
+ {
+ m_CurAnimFrame = time;
+ }
+
+ public void SetCurrentEvent(int index)
+ {
+ if(index < 0)
+ {
+ m_CurEventInfo = null;
+ }
+ else if(m_EventList != null)
+ {
+ m_CurEventInfo = m_EventList[index];
+ }
+ else
+ {
+ m_CurEventInfo = null;
+ }
+ }
+
+ public AnimationEventBase GetEvent(int index)
+ {
+ if(m_EventList != null && index >= 0 && index < m_EventList.Count)
+ {
+ return m_EventList[index];
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public int GetEventCount()
+ {
+ if (m_EventList != null)
+ return m_EventList.Count;
+ return 0;
+ }
+
+ public void RemoveCurrentEvent()
+ {
+ if(m_EventList != null)
+ {
+ m_EventList.Remove(m_CurEventInfo);
+ m_CurEventInfo = null;
+ }
+ }
+
+ public void RemoveAllEvent()
+ {
+ if(m_EventList != null)
+ {
+ m_EventList.Clear();
+ m_CurEventInfo = null;
+ }
+ }
+
+ public void StartFrame()
+ {
+ m_PrevFrame = -1;
+ m_PrevLocalTime = EditorApplication.timeSinceStartup;
+ }
+
+ public void UpdateFrame()
+ {
+ if (!ActionManager.IsPlay)
+ return;
+
+ m_CurAnimFrame += (float)(EditorApplication.timeSinceStartup - m_PrevLocalTime) * (ActionManager.FPS * ActionManager.Speed);
+
+ if (m_CurAnimFrame > m_TotalFrame)
+ {
+ m_Animator.transform.position = ActionManager.s_InitPosition;
+ m_Animator.transform.rotation = ActionManager.s_InitRotation;
+ }
+ m_CurAnimFrame %= m_TotalFrame;
+
+ SampleFrame(EditorApplication.timeSinceStartup - m_PrevLocalTime);
+
+ RunEvent();
+
+ m_PrevLocalTime = EditorApplication.timeSinceStartup;
+ }
+
+ // 播放当前帧
+ public void SampleFrame(double dt)
+ {
+ if (m_Animator == null)
+ return;
+
+ m_Animator.speed = 1;
+
+ float normalizeTime = m_CurAnimFrame / m_TotalFrame;
+
+ m_Animator.Play(kStateName, 0, normalizeTime);
+ m_Animator.Update((float)dt);
+
+ m_Animator.transform.position += m_Animator.deltaPosition;
+ m_Animator.transform.rotation *= m_Animator.deltaRotation;
+
+ m_Animator.speed = 0;
+ }
+
+ public int GetCurrentFrame()
+ {
+ float animTime = m_AnimRate * m_CurAnimFrame;
+ int curFrame = Mathf.RoundToInt(animTime * ActionManager.FPS);
+ return curFrame;
+ }
+
+ public void RunEvent()
+ {
+ }
+
+ public void CreateEvent(TimelineEvent.EEventType eventtype, int startFrame)
+ {
+ var classes = Assembly
+ .GetAssembly(typeof(AnimationEventBase))
+ .GetTypes()
+ .Where(t => t.IsSubclassOf(typeof(AnimationEventBase)));
+ Type type = null;
+ foreach (var itor in classes)
+ {
+ string name = itor.Name;
+ if(itor.Name == eventtype.ToString())
+ {
+ type = itor;
+ break;
+ }
+ }
+ if(type != null)
+ {
+ var e = Activator.CreateInstance(type) as AnimationEventBase;
+ e.type = eventtype;
+ e.startFrame = startFrame;
+ AddEvent(e);
+ }
+ else
+ {
+ Debug.LogError("[ActionTool] 没有对应类型的event" + eventtype.ToString());
+ }
+ }
+
+ public void AddEvent(AnimationEventBase evnt)
+ {
+ if (m_AnimData == null || m_EventList == null)
+ {
+ Debug.LogError("[ActionTool] 没有对应的action数据,是否在" + ActionManager.s_AnimationDataFolder + "创建");
+ return;
+ }
+ m_EventList.Add(evnt);
+ }
+
+ public void SaveActionData()
+ {
+ if (m_AnimData == null)
+ return;
+ EditorUtility.SetDirty(m_AnimData);
+ AssetDatabase.SaveAssets();
+ }
+
+ public void Clear()
+ {
+ m_Animator = null;
+ m_Clip = null;
+ m_AnimData = null;
+ m_CurEventInfo = null;
+ m_TotalFrame = 0;
+ m_CurAnimFrame = 0;
+ m_PrevFrame = 0;
+ m_PrevLocalTime = 0;
+ m_AnimRate = 0;
+ }
+
+ }
+
+}
diff --git a/Assets/ActionTool/Editor/ActionData.cs.meta b/Assets/ActionTool/Editor/ActionData.cs.meta
new file mode 100644
index 00000000..4e6fe1ca
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionData.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: eccac258cc2e3a94cb5b1c569b96c366
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/ActionTool/Editor/ActionEditor.cs b/Assets/ActionTool/Editor/ActionEditor.cs
new file mode 100644
index 00000000..90c8bfc9
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionEditor.cs
@@ -0,0 +1,120 @@
+using System.IO;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEditor;
+using UnityEngine;
+
+namespace ActionTool
+{
+
+ public class ActionEditor : EditorWindow
+ {
+ [MenuItem("Custom/ActionTool/Open")]
+ static void OpenTools()
+ {
+ ActionManager.AnimationWindow = GetWindow<ActionEditor>();
+ }
+
+ private string m_SearchText;
+
+ public void OnEnable()
+ {
+
+ }
+
+ public void OnDisable()
+ {
+ }
+
+ public void OnGUI()
+ {
+ GUILayout.Space(5);
+ GUI_SelectUnit();
+ GUILayout.Space(5);
+ GUI_AnimationList();
+ GUILayout.Space(5);
+ }
+
+ private void GUI_SelectUnit()
+ {
+ if(ActionManager.CurrentUnit == null)
+ {
+ EditorGUILayout.HelpBox("选择角色prefab", MessageType.Warning);
+ }
+
+ GUILayout.BeginHorizontal();
+
+ GameObject selectObj = EditorGUILayout.ObjectField(ActionManager.CurrentUnit, typeof(GameObject), false, GUILayout.Width(position.width - 160)) as GameObject;
+
+ if(selectObj != ActionManager.CurrentUnit)
+ {
+ ActionManager.OnSelectObj(selectObj);
+ }
+
+ if (GUILayout.Button("Select", GUILayout.Width(70)))
+ {
+
+ }
+
+ if (GUILayout.Button("Reimport", GUILayout.Width(70)))
+ {
+
+ }
+
+ GUILayout.EndHorizontal();
+ }
+
+ private Vector2 m_AnimtionListScroll;
+ private void GUI_AnimationList()
+ {
+ if (!ActionManager.HasSelectObj())
+ return;
+
+ string unitName = ActionManager.GetUnitName();
+
+ EditorGUILayout.LabelField("Animation List");
+
+ m_SearchText = GUILayout.TextField(m_SearchText, "SearchTextField", GUILayout.Width(position.width - 20)).ToLower();
+
+ string animFolder = ActionManager.s_AnimFolder + unitName + "/";
+
+ string[] animfiles = Directory.GetFiles(animFolder);
+
+ if (animfiles != null && animfiles.Length > 0)
+ {
+ GUIStyle style = GUI.skin.GetStyle("Button");
+ TextAnchor prevAnchor = style.alignment;
+ TextClipping prevClipping = style.clipping;
+ bool prevRichText = style.richText;
+ style.alignment = TextAnchor.MiddleCenter;
+ style.clipping = TextClipping.Overflow;
+ style.richText = true;
+
+ m_AnimtionListScroll = EditorGUILayout.BeginScrollView(m_AnimtionListScroll);
+
+ for (int i = 0; i < animfiles.Length; ++i)
+ {
+ string file = animfiles[i];
+ if (file.Contains(".meta"))
+ continue;
+ string animName = Path.GetFileNameWithoutExtension(file);
+ bool show = m_SearchText == string.Empty || m_SearchText == "" || animName.ToLower().Contains(m_SearchText);
+ if (!show)
+ continue;
+ bool bChecked = ActionManager.CurrentAnimationName == animName;
+ bool check = GUILayout.Toggle(bChecked, animName, style, GUILayout.Height(15));
+ if (check && ActionManager.CurrentAnimationName != animName)
+ ActionManager.OnSelectAnimation(animName);
+ }
+
+ EditorGUILayout.EndScrollView();
+
+ style.alignment = prevAnchor;
+ style.clipping = prevClipping;
+ style.richText = prevRichText;
+ }
+
+ }
+
+ }
+} \ No newline at end of file
diff --git a/Assets/ActionTool/Editor/ActionEditor.cs.meta b/Assets/ActionTool/Editor/ActionEditor.cs.meta
new file mode 100644
index 00000000..4c2ff1fe
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionEditor.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: ce7158026a0c5f74eb9acc71dea8288c
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/ActionTool/Editor/ActionEditorStyles.cs b/Assets/ActionTool/Editor/ActionEditorStyles.cs
new file mode 100644
index 00000000..c7c15aaf
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionEditorStyles.cs
@@ -0,0 +1,44 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEditor;
+
+namespace ActionTool
+{
+ internal class ActionEditorStyles
+ {
+ public GUIStyle textBold;
+
+ private static ActionEditorStyles s_instance;
+
+ public static ActionEditorStyles Get()
+ {
+ bool flag = s_instance == null;
+ if (flag)
+ {
+ s_instance = new ActionEditorStyles();
+ }
+ return s_instance;
+ }
+
+ private ActionEditorStyles()
+ {
+ InitStyle(out textBold, GUI.skin.label, s => {
+ s.fontStyle = FontStyle.Bold;
+ });
+ }
+
+ private delegate void Initter(GUIStyle style);
+ private static void InitStyle(out GUIStyle normal, GUIStyle other, Initter initter)
+ {
+ normal = new GUIStyle(other);
+ initter(normal);
+ }
+ private static void InitStyle(out GUIStyle normal, Initter initter)
+ {
+ normal = new GUIStyle();
+ initter(normal);
+ }
+
+ }
+} \ No newline at end of file
diff --git a/Assets/ActionTool/Editor/ActionEditorStyles.cs.meta b/Assets/ActionTool/Editor/ActionEditorStyles.cs.meta
new file mode 100644
index 00000000..8adef727
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionEditorStyles.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 13b6cd36eabea4b42aadd96b3a816fe3
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/ActionTool/Editor/ActionEditorUI.cs b/Assets/ActionTool/Editor/ActionEditorUI.cs
new file mode 100644
index 00000000..effa6be7
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionEditorUI.cs
@@ -0,0 +1,65 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEditor;
+
+namespace ActionTool
+{
+ internal class ActionEditorUI
+ {
+ private static ActionEditorUI s_instance;
+
+ public static ActionEditorUI Get()
+ {
+ bool flag = s_instance == null;
+ if (flag)
+ {
+ s_instance = new ActionEditorUI();
+ }
+ return s_instance;
+ }
+
+ private ActionEditorUI()
+ {
+ }
+
+ public void DrawVerticalLineFast(float x, float minY, float maxY, Color color)
+ {
+ bool bWin = Application.platform == RuntimePlatform.WindowsEditor;
+ if (bWin)
+ {
+ GL.Color(color);
+ GL.Vertex(new Vector3(x - 0.5f, minY, 0f));
+ GL.Vertex(new Vector3(x + 0.5f, minY, 0f));
+ GL.Vertex(new Vector3(x + 0.5f, maxY, 0f));
+ GL.Vertex(new Vector3(x - 0.5f, maxY, 0f));
+ }
+ else
+ {
+ GL.Color(color);
+ GL.Vertex(new Vector3(x, minY, 0f));
+ GL.Vertex(new Vector3(x, maxY, 0f));
+ }
+ }
+
+ public void DrawHorizontalLineFast(float y, float minX, float maxX, Color color)
+ {
+ bool bWin = Application.platform == RuntimePlatform.WindowsEditor;
+ if (bWin)
+ {
+ GL.Color(color);
+ GL.Vertex(new Vector3(minX, y - 0.5f, 0f));
+ GL.Vertex(new Vector3(minX, y + 0.5f, 0f));
+ GL.Vertex(new Vector3(maxX, y + 0.5f, 0f));
+ GL.Vertex(new Vector3(maxX, y - 0.5f, 0f));
+ }
+ else
+ {
+ GL.Color(color);
+ GL.Vertex(new Vector3(minX, y, 0f));
+ GL.Vertex(new Vector3(maxX, y, 0f));
+ }
+ }
+
+ }
+} \ No newline at end of file
diff --git a/Assets/ActionTool/Editor/ActionEditorUI.cs.meta b/Assets/ActionTool/Editor/ActionEditorUI.cs.meta
new file mode 100644
index 00000000..6d66f438
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionEditorUI.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: c0e7eed5cfcabd24f980de3b9fc699ac
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/ActionTool/Editor/ActionEventEditor.cs b/Assets/ActionTool/Editor/ActionEventEditor.cs
new file mode 100644
index 00000000..70a75011
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionEventEditor.cs
@@ -0,0 +1,23 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace ActionTool
+{
+
+ public class ActionEventEditor : MonoBehaviour
+ {
+
+ // Start is called before the first frame update
+ void Start()
+ {
+
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+
+ }
+ }
+} \ No newline at end of file
diff --git a/Assets/ActionTool/Editor/ActionEventEditor.cs.meta b/Assets/ActionTool/Editor/ActionEventEditor.cs.meta
new file mode 100644
index 00000000..6a130af1
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionEventEditor.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 7e3fa648b1f19c141ad717db41c10772
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/ActionTool/Editor/ActionManager.cs b/Assets/ActionTool/Editor/ActionManager.cs
new file mode 100644
index 00000000..e894d32c
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionManager.cs
@@ -0,0 +1,154 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEditor;
+using UnityEngine;
+
+namespace ActionTool
+{
+ public static class ActionManager
+ {
+ public static string s_AnimFolder = "Assets/Art/Animations/";
+ public static string s_Controller = "Assets/ActionTool/controller_temp.controller";
+ public static string s_AnimationDataFolder = "Assets/Data/AnimationData/";
+ public static string s_UnitDataFolder = "Assets/Data/UnitData/";
+
+ public static ActionEditor AnimationWindow;
+ public static ActionPreviewEditor PreviewWindow;
+ public static ActionEventEditor EventEditWindow;
+ public static ActionColliderEditor ColliderWindow;
+
+ public const int FPS = 30;
+
+ public static float Speed = 1;
+
+ public static GameObject CurrentUnit
+ {
+ get
+ {
+ return s_CurrentUnit;
+ }
+ }
+
+ public static string CurrentAnimationName
+ {
+ get
+ {
+ return s_CurrentAnimationName;
+ }
+ }
+
+ private static GameObject s_CurrentUnit;
+ private static string s_CurrentAnimationName;
+ private static GameObject s_UnitInstance;
+ private static Animator s_Animator;
+ private static AnimatorOverrideController s_OverrideContorller;
+
+ private static ActionData s_CurActionData;
+
+ public static Vector3 s_InitPosition = Vector3.zero;
+
+ public static Quaternion s_InitRotation = Quaternion.identity;
+
+ private static bool s_IsPlay;
+ public static bool IsPlay { get { return s_IsPlay; } }
+
+ public static void OnSelectObj(GameObject obj)
+ {
+ Release();
+ s_CurrentUnit = obj;
+ if(s_CurrentUnit != null)
+ {
+ s_UnitInstance = GameObject.Instantiate(obj);
+ InitializeUnitInstance(s_UnitInstance);
+ }
+ }
+
+ public static void OnSelectAnimation(string animation)
+ {
+ s_CurrentAnimationName = animation;
+ if(PreviewWindow == null)
+ PreviewWindow = EditorWindow.GetWindow<ActionPreviewEditor>();
+ PreviewWindow.Repaint();
+
+ string animpath = s_AnimFolder + s_CurrentUnit.name + "/" + animation + ".anim";
+ AnimationClip clip = AssetDatabase.LoadAssetAtPath(animpath, typeof(AnimationClip)) as AnimationClip;
+ if(clip)
+ {
+ s_OverrideContorller["EmptyAction"] = clip;
+ }
+
+ if(s_CurActionData == null)
+ s_CurActionData = new ActionData();
+ s_CurActionData.Initialize(s_Animator, clip);
+ }
+
+ public static bool HasSelectObj()
+ {
+ return s_CurrentUnit != null;
+ }
+
+ public static string GetUnitName()
+ {
+ if (s_CurrentUnit == null)
+ return null;
+ return s_CurrentUnit.name;
+ }
+
+ public static void Release()
+ {
+ if(s_UnitInstance != null)
+ GameObject.DestroyImmediate(s_UnitInstance);
+ s_UnitInstance = null;
+ s_CurrentUnit = null;
+ s_CurrentAnimationName = null;
+ s_Animator = null;
+ }
+
+ private static void InitializeUnitInstance(GameObject unit)
+ {
+ if (unit == null)
+ return;
+
+ unit.transform.position = s_InitPosition;
+ unit.transform.rotation = s_InitRotation;
+
+ s_Animator = unit.GetComponentInChildren<Animator>();
+ if(s_Animator == null)
+ {
+ Debug.LogError("[ActionTool] 角色prefab下没有animator");
+ return;
+ }
+
+ RuntimeAnimatorController controller = AssetDatabase.LoadAssetAtPath(s_Controller, typeof(RuntimeAnimatorController)) as RuntimeAnimatorController;
+ if(controller == null)
+ {
+ Debug.LogError("[ActionTool] 文件丢失" + s_Controller);
+ return;
+ }
+
+ s_OverrideContorller = new AnimatorOverrideController(controller);
+ s_OverrideContorller.name = "override controller";
+ s_Animator.runtimeAnimatorController = s_OverrideContorller;
+
+ UnitRootMotion rootMotion = s_UnitInstance.GetComponent<UnitRootMotion>();
+ Object.DestroyImmediate(rootMotion);
+ }
+
+ public static void UpdateFrame()
+ {
+ if (s_CurActionData != null)
+ s_CurActionData.UpdateFrame();
+ }
+
+ public static void Pause()
+ {
+ s_IsPlay = !s_IsPlay;
+ if(s_IsPlay && s_CurActionData != null)
+ {
+ s_CurActionData.SetCurrentAnimTime(0);
+ s_CurActionData.StartFrame();
+ }
+ }
+
+ }
+} \ No newline at end of file
diff --git a/Assets/ActionTool/Editor/ActionManager.cs.meta b/Assets/ActionTool/Editor/ActionManager.cs.meta
new file mode 100644
index 00000000..86dd9397
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionManager.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 5edc3f3e858191742a0db785219adbe3
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/ActionTool/Editor/ActionPreviewEditor.cs b/Assets/ActionTool/Editor/ActionPreviewEditor.cs
new file mode 100644
index 00000000..9b557128
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionPreviewEditor.cs
@@ -0,0 +1,166 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEditor;
+
+namespace ActionTool
+{
+
+ public class ActionPreviewEditor : EditorWindow
+ {
+ private Texture m_UITextureStop;
+ private Texture m_UITexturePause;
+ private Texture m_UITexturePlay;
+ private Texture m_UITextureNext;
+ private Texture m_UITextureEnd;
+ private Texture m_UITexturePrevious;
+ private Texture m_UITextureStart;
+
+ private GUIStyle m_StyleBold;
+
+ private const float kToolbarControlMargin = 5;
+ private const float kToolbarHeight = 50;
+ private const float kToolbarControlSize = kToolbarHeight - kToolbarControlMargin * 2;
+
+ private ActionEditorStyles styles;
+ private ActionEditorUI ui;
+
+ private void OnEnable()
+ {
+ titleContent = new GUIContent("Action Preview");
+
+ m_UITextureStop = (Texture)Resources.Load("button_control_stop");
+ m_UITexturePause = (Texture)Resources.Load("button_control_pause");
+ m_UITexturePlay = (Texture)Resources.Load("button_control_play");
+ m_UITextureNext = (Texture)Resources.Load("button_control_next");
+ m_UITextureEnd = (Texture)Resources.Load("button_control_end");
+ m_UITexturePrevious = (Texture)Resources.Load("button_control_previous");
+ m_UITextureStart = (Texture)Resources.Load("button_control_start");
+
+ styles = ActionEditorStyles.Get();
+ }
+
+ private void OnDisable()
+ {
+ ActionManager.PreviewWindow = null;
+ }
+
+ private void OnGUI()
+ {
+ if (ActionManager.CurrentAnimationName == null || ActionManager.CurrentAnimationName == "")
+ {
+ EditorGUILayout.HelpBox("选择动画", MessageType.Warning);
+ return;
+ }
+
+ if (styles == null) styles = ActionEditorStyles.Get();
+ if (ui == null) ui = ActionEditorUI.Get();
+
+ GUI_Toolbar();
+ GUI_Detail();
+ }
+
+ void GUI_Toolbar()
+ {
+ float x = 0, y = kToolbarControlMargin;
+ GUI_Toolbar_BG();
+ GUI_Toolbar_Start(ref x, ref y);
+ GUI_Toolbar_Previous(ref x, ref y);
+ GUI_Toolbar_Stop(ref x, ref y);
+ GUI_Toolbar_Pause(ref x, ref y);
+ GUI_Toolbar_Next(ref x, ref y);
+ GUI_Toolbar_End(ref x, ref y);
+ }
+
+ void GUI_Toolbar_BG()
+ {
+ GUI.DrawTexture(new Rect(0, 0, position.width, 50), EditorStyles.toolbar.normal.background);
+ }
+
+ void GUI_Toolbar_Start(ref float x, ref float y)
+ {
+ x += kToolbarControlMargin;
+ Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
+ if(GUI.Button(rect, m_UITextureStart))
+ {
+
+ }
+ x += kToolbarControlSize;
+ }
+
+ void GUI_Toolbar_Previous(ref float x, ref float y)
+ {
+ x += kToolbarControlMargin;
+ Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
+ if (GUI.Button(rect, m_UITexturePrevious))
+ {
+
+ }
+ x += kToolbarControlSize;
+ }
+
+ void GUI_Toolbar_Stop(ref float x, ref float y)
+ {
+ x += kToolbarControlMargin;
+ Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
+ if (GUI.Button(rect, m_UITextureStop))
+ {
+
+ }
+ x += kToolbarControlSize;
+ }
+
+ void GUI_Toolbar_Pause(ref float x, ref float y)
+ {
+ x += kToolbarControlMargin;
+ Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
+ Texture tex = ActionManager.IsPlay ? m_UITexturePlay : m_UITexturePause;
+ if (GUI.Button(rect, tex))
+ {
+ ActionManager.Pause();
+ }
+ x += kToolbarControlSize;
+ }
+
+ void GUI_Toolbar_Next(ref float x, ref float y)
+ {
+ x += kToolbarControlMargin;
+ Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
+ if (GUI.Button(rect, m_UITextureNext))
+ {
+
+ }
+ x += kToolbarControlSize;
+ }
+
+ void GUI_Toolbar_End(ref float x, ref float y)
+ {
+ x += kToolbarControlMargin;
+ Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
+ if (GUI.Button(rect, m_UITextureEnd))
+ {
+
+ }
+ x += kToolbarControlSize;
+ }
+
+ void GUI_Detail()
+ {
+ float y = kToolbarHeight + 5;
+ float x = 5;
+
+ GUI.Label(new Rect(x, y, 105, 20), "Animation Name:");
+ x += 105;
+ GUI.Label(new Rect(x, y, 210, 20), ActionManager.CurrentAnimationName, styles.textBold);
+ x += 200;
+
+ }
+
+ void Update()
+ {
+ ActionManager.UpdateFrame();
+ }
+
+ }
+
+} \ No newline at end of file
diff --git a/Assets/ActionTool/Editor/ActionPreviewEditor.cs.meta b/Assets/ActionTool/Editor/ActionPreviewEditor.cs.meta
new file mode 100644
index 00000000..5b4ca315
--- /dev/null
+++ b/Assets/ActionTool/Editor/ActionPreviewEditor.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 309177f6ffca86847b5a989422c96fdc
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: