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/TweenAnimation.cs | 64 +++++++++++++++++----- 1 file changed, 50 insertions(+), 14 deletions(-) (limited to 'Assets/UI_Extension/Scripts/Animation/Tween/TweenAnimation.cs') diff --git a/Assets/UI_Extension/Scripts/Animation/Tween/TweenAnimation.cs b/Assets/UI_Extension/Scripts/Animation/Tween/TweenAnimation.cs index e722a08..6441552 100644 --- a/Assets/UI_Extension/Scripts/Animation/Tween/TweenAnimation.cs +++ b/Assets/UI_Extension/Scripts/Animation/Tween/TweenAnimation.cs @@ -1,4 +1,5 @@ -using System; +// by chai +using System; using System.Collections; using System.Collections.Generic; using UnityEngine; @@ -15,11 +16,10 @@ namespace TweenAnimation public UnityEvent eventHandler; // 回调函数 #if UNITY_EDITOR [NonSerialized] - public bool unfold; + public bool unfold = false; #endif public TweenEvent() { - unfold = false; name = "New Event"; time = 0; eventHandler = null; @@ -56,6 +56,9 @@ namespace TweenAnimation // 回放次数,0是不限制,默认是0 public int playbackLimit; + // 是否触发事件 + public bool triggerEvents; + // 只触发一次事件 public bool triggerOnce; @@ -111,14 +114,8 @@ namespace TweenAnimation if (modules == null) return; - float logicTime = time; - - if (this.playbackStyle == PlaybackStyle.Once) - logicTime = HandleOnce(time); - else if (this.playbackStyle == PlaybackStyle.Loop) - logicTime = HandleLoop(time); - else if (this.playbackStyle == PlaybackStyle.PingPong) - logicTime = HandlePingpong(time); + time = ApplyLimit(time); + float logicTime = HandleTime(time); for (int i = 0; i < modules.Count; i ++) { @@ -129,19 +126,19 @@ namespace TweenAnimation } } - private float HandleOnce(float time) + float HandleOnce(float time) { time = Mathf.Clamp(time, 0, duration); return time; } - private float HandleLoop(float time) + float HandleLoop(float time) { time = time % duration; return time; } - private float HandlePingpong(float time) + float HandlePingpong(float time) { if (time <= duration) return time; @@ -156,11 +153,50 @@ namespace TweenAnimation return time; } + // 返回[0,duration]范围内的逻辑时间 + public float HandleTime(float time) + { + float logicTime = time; + if (this.playbackStyle == PlaybackStyle.Once) + logicTime = HandleOnce(time); + else if (this.playbackStyle == PlaybackStyle.Loop) + logicTime = HandleLoop(time); + else if (this.playbackStyle == PlaybackStyle.PingPong) + logicTime = HandlePingpong(time); + return logicTime; + } + + public float ApplyLimit(float time) + { + if (playbackLimit <= 0) + return time; + if (playbackStyle == PlaybackStyle.Loop) + time = Mathf.Clamp(time, 0, playbackLimit * duration); + else if(playbackStyle == PlaybackStyle.PingPong) + time = Mathf.Clamp(time, 0, playbackLimit * duration); + return time; + } + #if UNITY_EDITOR public void UpdateEditor(float time) { Process(time); } + + // 返回0-duration内的时间,用负数代表从右往左 + public float GetIdentifiedTime(float t) + { + int round = (int)(t / duration); + float time = HandleTime(t); + if(playbackStyle == PlaybackStyle.PingPong) + { + bool bOdd = (round & 1) == 1; + if(bOdd) + time = -time; + } + return time; + } + #endif } -- cgit v1.1-26-g67d0