summaryrefslogtreecommitdiff
path: root/Assets/ActionTool/Editor/ActionManager.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-07-22 18:34:47 +0800
committerchai <chaifix@163.com>2021-07-22 18:34:47 +0800
commitcb893e1e5e4820cb800836cf6b8a79a1cd986cdc (patch)
treec96f8020c760d89d418684b71de294556d6961d3 /Assets/ActionTool/Editor/ActionManager.cs
parentf7f2ebc0ce06aaf7d34325258c9bfe689043de94 (diff)
*misc
Diffstat (limited to 'Assets/ActionTool/Editor/ActionManager.cs')
-rw-r--r--Assets/ActionTool/Editor/ActionManager.cs80
1 files changed, 76 insertions, 4 deletions
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<AnimationData>(animationDataPath);
+ AnimationData asset = AssetDatabase.LoadAssetAtPath<AnimationData>(animationDataPath);
+ m_SharedAnimationData = asset;
+ if(asset != null)
+ animationData = UnityEngine.Object.Instantiate<AnimationData>(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<AnimationData>(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<ActionEventEditor>(true);
+ }
+ }
+
+ public static void DeleteEvent(AnimationEventBase animEvent)
+ {
+ if (animationData == null)
+ return;
+ animationData.DeleteEvent(animEvent);
+ }
+
}
} \ No newline at end of file