From 3bd21c73384906267a2a4c48acdb96df77bd1f67 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 30 May 2021 11:05:38 +0800 Subject: *tween --- .../Animation/Tween/Editor/PlaybackTimer.cs | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs (limited to 'Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs') diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs new file mode 100644 index 0000000..4890f2b --- /dev/null +++ b/Assets/UI_Extension/Scripts/Animation/Tween/Editor/PlaybackTimer.cs @@ -0,0 +1,70 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; +namespace TweenAnimation +{ + public class PlaybackTimer + { + // 考虑了Pause的playback时间 + public float time + { + get + { + if (m_PauseRealTime != -1) + return m_PauseRealTime - m_StartRealTime; + return realTime; + } + } + + // 从调用Resume开始后的时间 + private float realTime + { + get + { + return (float)EditorApplication.timeSinceStartup - m_StartRealTime; + } + } + + private float m_StartRealTime; + + private float m_PauseRealTime; + + public PlaybackTimer() + { + Reset(); + } + + //Start & Resume + public void Resume() + { + if (m_PauseRealTime != -1) + m_StartRealTime = (float)EditorApplication.timeSinceStartup - time; + else + m_StartRealTime = (float)EditorApplication.timeSinceStartup; + m_PauseRealTime = -1; + } + + public void Pause() + { + m_PauseRealTime = (float)EditorApplication.timeSinceStartup; + } + + public void Stop() + { + Reset(); + } + + public void Reset() + { + m_StartRealTime = -1; + m_PauseRealTime = -1; + } + + public void SetPauseTimeOffset(float dt) + { + m_PauseRealTime += dt; + } + + } +} \ No newline at end of file -- cgit v1.1-26-g67d0