From cb893e1e5e4820cb800836cf6b8a79a1cd986cdc Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 22 Jul 2021 18:34:47 +0800 Subject: *misc --- Assets/ActionTool/Editor/ActionManager.cs | 80 +++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 4 deletions(-) (limited to 'Assets/ActionTool/Editor/ActionManager.cs') diff --git a/Assets/ActionTool/Editor/ActionManager.cs b/Assets/ActionTool/Editor/ActionManager.cs index 396e0342..cc8a7dfd 100644 --- a/Assets/ActionTool/Editor/ActionManager.cs +++ b/Assets/ActionTool/Editor/ActionManager.cs @@ -1,4 +1,5 @@ -using System.Collections; +using System; +using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; @@ -53,6 +54,8 @@ namespace ActionTool private static RootMotionData s_RootMotion; + private static AnimationData m_SharedAnimationData; // 资源 + public static AnimationData sharedAnimationData { get { return m_SharedAnimationData; } } private static AnimationData m_AnimationData; public static AnimationData animationData { @@ -70,6 +73,9 @@ namespace ActionTool } } + private static AnimationEventBase m_CurAnimationEvent; + public static AnimationEventBase animationEvent { get { return m_CurAnimationEvent; } } + private static ColliderData s_CurColliderData; public static ColliderData colliderData { get { return s_CurColliderData; } } @@ -134,7 +140,18 @@ namespace ActionTool s_CurActionData.Initialize(s_Animator, clip, s_RootMotion); string animationDataPath = s_AnimationDataFolder + unitName + "/" + animation + ".asset"; - animationData = AssetDatabase.LoadAssetAtPath(animationDataPath); + AnimationData asset = AssetDatabase.LoadAssetAtPath(animationDataPath); + m_SharedAnimationData = asset; + if(asset != null) + animationData = UnityEngine.Object.Instantiate(asset); + else + animationData = null; + + OnSelectAnimationEvent(null); + OnSelectColliderFrame(null); + OnSelectBox(null); + if (EventEditWindow) EventEditWindow.Close(); + if (ColliderWindow) ColliderWindow.Close(); } public static bool HasSelectObj() @@ -163,6 +180,7 @@ namespace ActionTool s_CurActionData = null; s_CurEditColliderFrame = null; s_CurColliderData = null; + s_CurrentAnimationName = null; } private static void InitializeUnitInstance(GameObject unit) @@ -270,7 +288,8 @@ namespace ActionTool animData.animationPath = animpath; AssetDatabase.CreateAsset(animData, animationDataPath); AssetDatabase.Refresh(); - animationData = animData; + m_SharedAnimationData = animData; + animationData = UnityEngine.Object.Instantiate(animData); } public static void SaveAnimationData() @@ -280,7 +299,12 @@ namespace ActionTool Debug.LogError("[ActionTool] 没有animation data数据"); return; } - EditorUtility.SetDirty(animationData); + string unitName = s_CurrentUnit.name; + string animation = s_CurrentAnimationName; + string animationDataPath = s_AnimationDataFolder + unitName + "/" + animation + ".asset"; + EditorUtility.CopySerialized(animationData, m_SharedAnimationData); + m_SharedAnimationData.OnSaveToDisk(); + EditorUtility.SetDirty(m_SharedAnimationData); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } @@ -368,5 +392,53 @@ namespace ActionTool } } + public static void AddNewEvent(object param) + { + EventParam eventParam = (EventParam )param; + string eventName = eventParam.eventName; // TimelineEvent.EEventType + int frame = eventParam.frame; + Debug.Log("[ActionTool] Add new event " + eventName); + if (animationData == null) + { + Debug.LogError("[ActionTool] 没有animation data数据"); + return; + } + Type type = TimelineEvent.GetTypeByName(eventName); + if(type == null) + { + Debug.LogError("[ActionTool] 没有创建对应的类, " + eventName); + return; + } + AnimationEventBase animEvent = Activator.CreateInstance(type) as AnimationEventBase; + if(animEvent) + { + animEvent.name = animEvent.type.ToString(); + animEvent.startFrame = frame; + animationData.AddEvent(animEvent); + OnSelectAnimationEvent(animEvent); + } + else + { + Debug.LogError("[ActionTool] 实例化失败, " + eventName); + return; + } + } + + public static void OnSelectAnimationEvent(AnimationEventBase animEvent) + { + m_CurAnimationEvent = animEvent; + if(animEvent != null) + { + EventEditWindow = EditorWindow.GetWindow(true); + } + } + + public static void DeleteEvent(AnimationEventBase animEvent) + { + if (animationData == null) + return; + animationData.DeleteEvent(animEvent); + } + } } \ No newline at end of file -- cgit v1.1-26-g67d0