From a0577c8f3415b3173f8d57af631785b43c18d086 Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 8 Jul 2021 22:52:08 +0800 Subject: *Action Editor --- Assets/ActionTool/Editor/ActionData.cs | 52 +++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 17 deletions(-) (limited to 'Assets/ActionTool/Editor/ActionData.cs') diff --git a/Assets/ActionTool/Editor/ActionData.cs b/Assets/ActionTool/Editor/ActionData.cs index 4465d314..958e2c53 100644 --- a/Assets/ActionTool/Editor/ActionData.cs +++ b/Assets/ActionTool/Editor/ActionData.cs @@ -20,11 +20,29 @@ namespace ActionTool private AnimationEventBase m_CurEventInfo; // 当前正在编辑的event - private float m_TotalFrame; - private int m_PrevFrame; + #region metadata + private float m_TotalFrame; //timeline采样的总帧数 + public float totalFrame { get { return m_TotalFrame; } } + private float m_SampleRate; // 每次采样的时间间隔 + public float sampleRate { get { return m_SampleRate; } } + #endregion + + public float curAnimFrame { get { return m_CurAnimFrame; } } - private float m_AnimRate; // 每帧时间 + public float curAnimTimeNormal + { + get + { + return m_CurAnimFrame / m_TotalFrame; + } + set + { + float v = value % m_TotalFrame; + m_CurAnimFrame = v * m_TotalFrame; + } + } + private int m_PrevFrame; private float m_CurAnimFrame; private double m_PrevLocalTime; @@ -39,7 +57,7 @@ namespace ActionTool if(m_Clip != null) { m_TotalFrame = m_Clip.length * ActionManager.FPS; - m_AnimRate = m_Clip.length / m_TotalFrame; + m_SampleRate = m_Clip.length / m_TotalFrame; } m_PrevFrame = -1; m_CurAnimFrame = 0; @@ -114,19 +132,19 @@ namespace ActionTool public void UpdateFrame() { - if (!ActionManager.IsPlay) - return; - - m_CurAnimFrame += (float)(EditorApplication.timeSinceStartup - m_PrevLocalTime) * (ActionManager.FPS * ActionManager.Speed); + if (ActionManager.IsPlay) + { + 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; + if (m_CurAnimFrame > m_TotalFrame) + { + m_Animator.transform.position = ActionManager.s_InitPosition; + m_Animator.transform.rotation = ActionManager.s_InitRotation; + } + m_CurAnimFrame %= m_TotalFrame; } - m_CurAnimFrame %= m_TotalFrame; - SampleFrame(EditorApplication.timeSinceStartup - m_PrevLocalTime); + SampleFrame(); RunEvent(); @@ -134,7 +152,7 @@ namespace ActionTool } // 播放当前帧 - public void SampleFrame(double dt) + public void SampleFrame() { if (m_Animator == null) return; @@ -154,7 +172,7 @@ namespace ActionTool public int GetCurrentFrame() { - float animTime = m_AnimRate * m_CurAnimFrame; + float animTime = sampleRate * m_CurAnimFrame; int curFrame = Mathf.RoundToInt(animTime * ActionManager.FPS); return curFrame; } @@ -220,7 +238,7 @@ namespace ActionTool m_CurAnimFrame = 0; m_PrevFrame = 0; m_PrevLocalTime = 0; - m_AnimRate = 0; + m_SampleRate = 0; } } -- cgit v1.1-26-g67d0