From 2683c04adcaff44f9504248d2c983cd86bd4b3ad Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 31 May 2021 09:43:09 +0800 Subject: *tween --- .../Scripts/Animation/Tween/TweenController.cs | 51 ++++++++++++++++------ 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'Assets/UI_Extension/Scripts/Animation/Tween/TweenController.cs') diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/TweenController.cs b/Assets/UI_Extension/Scripts/Animation/Tween/TweenController.cs index 561eff6..e2c4495 100644 --- a/Assets/UI_Extension/Scripts/Animation/Tween/TweenController.cs +++ b/Assets/UI_Extension/Scripts/Animation/Tween/TweenController.cs @@ -7,29 +7,54 @@ using UnityEngine.Events; namespace TweenAnimation { - [Serializable] - public class TweenState - { - public string name; - public TweenAnimation animation; - } - public class TweenController : MonoBehaviour { - public List animations; + public bool autoPlayOnEnable; + public string defaultAnimation; + public List animations; - void Start () { - - } + private string m_Current; + private TweenAnimation m_CurrentAnimation; - public void PlayAnimation(string name) + private float m_StartTime; + + public void OnEnable() { + if(autoPlayOnEnable) + { + PlayAnimation(defaultAnimation); + } + } + public void PlayAnimation(string name) + { + m_Current = name; + m_CurrentAnimation = null; + for (int i = 0; i < animations.Count; ++i) + { + if(animations[i].name == name) + { + m_CurrentAnimation = animations[i]; + break; + } + } + if(m_CurrentAnimation == null) + { + Debug.LogError("No such animation'" + name + "'"); + } + else + { + m_CurrentAnimation.BeforePlay(); + } + m_StartTime = Time.time; } private void Update() { - + if (m_CurrentAnimation == null) + return; + float t = Time.time; + m_CurrentAnimation.Process(t - m_StartTime); } } -- cgit v1.1-26-g67d0