From 3bd21c73384906267a2a4c48acdb96df77bd1f67 Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 30 May 2021 11:05:38 +0800 Subject: *tween --- .../Scripts/Animation/Tween/TweenModule.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'Assets/UI_Extension/Scripts/Animation/Tween/TweenModule.cs') diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule.cs b/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule.cs index e42236b..2fd3742 100644 --- a/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule.cs +++ b/Assets/UI_Extension/Scripts/Animation/Tween/TweenModule.cs @@ -1,7 +1,9 @@ -using System; +// by chai +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.UI; namespace TweenAnimation { @@ -14,8 +16,10 @@ namespace TweenAnimation public float duration; + private float m_LastTime; + #if UNITY_EDITOR - public new virtual string name { get { return ""; } } + public virtual string name { get { return ""; } } public string description; @@ -25,13 +29,19 @@ namespace TweenAnimation public bool unfold; #endif + private bool IsValidTime0(float time0) + { + return time0 >= 0 && time0 <= duration; + } + // 根据当前时间更新值, time的范围是tween animation的duration public void OnUpdate(float time) { float time0 = time - timeOffset; - if (time0 < 0 || time0 > duration) + if (!IsValidTime0(time0) && !IsValidTime0(duration)) return; - SetValue(time0); + m_LastTime = time0; + SetValue(Mathf.Clamp(time0, 0, duration)); } // time是去掉了offset后的时间 -- cgit v1.1-26-g67d0