summaryrefslogtreecommitdiff
path: root/Assets/ActionTool/Editor/ActionManager.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/ActionTool/Editor/ActionManager.cs')
-rw-r--r--Assets/ActionTool/Editor/ActionManager.cs69
1 files changed, 66 insertions, 3 deletions
diff --git a/Assets/ActionTool/Editor/ActionManager.cs b/Assets/ActionTool/Editor/ActionManager.cs
index 32c71434..08d48781 100644
--- a/Assets/ActionTool/Editor/ActionManager.cs
+++ b/Assets/ActionTool/Editor/ActionManager.cs
@@ -17,6 +17,7 @@ namespace ActionTool
public static ActionEventEditor EventEditWindow;
public static ActionColliderEditor ColliderWindow;
+ //规定timeline上事件的采样频率是30帧
public const int FPS = 30;
public static float Speed = 1;
@@ -44,6 +45,7 @@ namespace ActionTool
private static AnimatorOverrideController s_OverrideContorller;
private static ActionData s_CurActionData;
+ public static ActionData actionData { get { return s_CurActionData; } }
public static Vector3 s_InitPosition = Vector3.zero;
@@ -51,9 +53,18 @@ namespace ActionTool
private static RootMotionData s_RootMotion;
+ private static ActionToolGizmos s_Gizmos;
+ public static ActionToolGizmos gizmos { get { return s_Gizmos; } }
+
+ // 是否在自动播放
private static bool s_IsPlay;
public static bool IsPlay { get { return s_IsPlay; } }
+ private static GameObject s_RootActionTool;
+ private const string kRootActionTool = "RootActionTool";
+
+ public const int kMaxEventsPerFrame = 10;
+
public static void OnSelectObj(GameObject obj)
{
Release();
@@ -79,7 +90,7 @@ namespace ActionTool
s_OverrideContorller["EmptyAction"] = clip;
}
- string rootmotionData = s_RootMotionDataFolder + s_CurrentUnit.name + "/" + animation.Replace(' ', '_') + ".asset";
+ string rootmotionData = s_RootMotionDataFolder + s_CurrentUnit.name + "/" + animation + ".asset";
s_RootMotion = AssetDatabase.LoadAssetAtPath<RootMotionData>(rootmotionData);
if (s_RootMotion == null)
{
@@ -89,7 +100,6 @@ namespace ActionTool
if (s_CurActionData == null)
s_CurActionData = new ActionData();
s_CurActionData.Initialize(s_Animator, clip, s_RootMotion);
-
}
public static bool HasSelectObj()
@@ -112,6 +122,10 @@ namespace ActionTool
s_CurrentUnit = null;
s_CurrentAnimationName = null;
s_Animator = null;
+ s_RootActionTool = GameObject.Find(kRootActionTool);
+ if (s_RootActionTool)
+ GameObject.DestroyImmediate(s_RootActionTool);
+ s_CurActionData = null;
}
private static void InitializeUnitInstance(GameObject unit)
@@ -122,6 +136,12 @@ namespace ActionTool
unit.transform.position = s_InitPosition;
unit.transform.rotation = s_InitRotation;
+ s_RootActionTool = GameObject.Find(kRootActionTool);
+ if(s_RootActionTool == null)
+ s_RootActionTool = new GameObject(kRootActionTool);
+
+ unit.transform.SetParent(s_RootActionTool.transform);
+
s_Animator = unit.GetComponentInChildren<Animator>();
if(s_Animator == null)
{
@@ -141,6 +161,8 @@ namespace ActionTool
s_Animator.runtimeAnimatorController = s_OverrideContorller;
s_Animator.applyRootMotion = false;
+
+ s_Gizmos = unit.AddComponent<ActionToolGizmos>();
}
public static void UpdateFrame()
@@ -154,10 +176,51 @@ namespace ActionTool
s_IsPlay = !s_IsPlay;
if(s_IsPlay && s_CurActionData != null)
{
- s_CurActionData.SetCurrentAnimTime(0);
s_CurActionData.StartFrame();
}
}
+ public static void Start()
+ {
+ if (s_CurActionData != null)
+ s_CurActionData.curAnimTimeNormal = 0;
+ }
+
+ public static void Stop()
+ {
+ if (s_CurActionData != null)
+ {
+ if (s_IsPlay)
+ Pause();
+ s_CurActionData.curAnimTimeNormal = 0;
+ }
+ }
+
+ public static void Previous()
+ {
+ if (s_IsPlay)
+ Pause();
+ float cur = s_CurActionData.curAnimFrame;
+ float pre = Mathf.Ceil(cur - 1);
+ pre = (int)Mathf.Clamp(pre, 0, s_CurActionData.totalFrame);
+ s_CurActionData.SetCurrentAnimTime(pre);
+ }
+
+ public static void Next()
+ {
+ if (s_IsPlay)
+ Pause();
+ float cur = s_CurActionData.curAnimFrame;
+ float next = Mathf.Floor(cur + 1);
+ next = (int)Mathf.Clamp(next, 0, s_CurActionData.totalFrame);
+ s_CurActionData.SetCurrentAnimTime(next);
+ }
+
+ public static void End()
+ {
+ if (s_CurActionData != null)
+ s_CurActionData.curAnimTimeNormal = 1;
+ }
+
}
} \ No newline at end of file