From d69611d66431e28ea35477c6781a00d57ae04fa3 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 7 Apr 2021 21:13:03 +0800 Subject: =?UTF-8?q?*=E5=9B=A0=E4=B8=BA=E6=B2=A1=E6=9C=89meta=EF=BC=8C?= =?UTF-8?q?=E5=AF=BC=E8=87=B4missing=EF=BC=8C=E5=88=A0=E9=99=A4UIEffect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Test/UIEffect/Program/Common/EffectPlayer.cs | 154 --------------------- 1 file changed, 154 deletions(-) delete mode 100644 Assets/Test/UIEffect/Program/Common/EffectPlayer.cs (limited to 'Assets/Test/UIEffect/Program/Common/EffectPlayer.cs') diff --git a/Assets/Test/UIEffect/Program/Common/EffectPlayer.cs b/Assets/Test/UIEffect/Program/Common/EffectPlayer.cs deleted file mode 100644 index f60165a..0000000 --- a/Assets/Test/UIEffect/Program/Common/EffectPlayer.cs +++ /dev/null @@ -1,154 +0,0 @@ -using UnityEngine; -using System; -using System.Collections.Generic; - -namespace Coffee.UIEffects -{ - /// - /// Effect player. - /// - [Serializable] - public class EffectPlayer - { - //################################ - // Public Members. - //################################ - /// - /// Gets or sets a value indicating whether is playing. - /// - [Header("Effect Player")] [Tooltip("Playing.")] - public bool play = false; - - /// - /// Gets or sets the delay before looping. - /// - [Tooltip("Initial play delay.")] [Range(0f, 10f)] - public float initialPlayDelay = 0; - - /// - /// Gets or sets the duration. - /// - [Tooltip("Duration.")] [Range(0.01f, 10f)] - public float duration = 1; - - /// - /// Gets or sets a value indicating whether can loop. - /// - [Tooltip("Loop.")] public bool loop = false; - - /// - /// Gets or sets the delay before looping. - /// - [Tooltip("Delay before looping.")] [Range(0f, 10f)] - public float loopDelay = 0; - - /// - /// Gets or sets the update mode. - /// - [Tooltip("Update mode")] public AnimatorUpdateMode updateMode = AnimatorUpdateMode.Normal; - - static List s_UpdateActions; - - /// - /// Register player. - /// - public void OnEnable(Action callback = null) - { - if (s_UpdateActions == null) - { - s_UpdateActions = new List(); - Canvas.willRenderCanvases += () => - { - var count = s_UpdateActions.Count; - for (int i = 0; i < count; i++) - { - s_UpdateActions[i].Invoke(); - } - }; - } - - s_UpdateActions.Add(OnWillRenderCanvases); - - if (play) - { - _time = -initialPlayDelay; - } - else - { - _time = 0; - } - - _callback = callback; - } - - /// - /// Unregister player. - /// - public void OnDisable() - { - _callback = null; - s_UpdateActions.Remove(OnWillRenderCanvases); - } - - /// - /// Start playing. - /// - public void Play(bool reset, Action callback = null) - { - if (reset) - { - _time = 0; - } - - play = true; - if (callback != null) - { - _callback = callback; - } - } - - /// - /// Stop playing. - /// - public void Stop(bool reset) - { - if (reset) - { - _time = 0; - if (_callback != null) - { - _callback(_time); - } - } - - play = false; - } - - //################################ - // Private Members. - //################################ - float _time = 0; - Action _callback; - - void OnWillRenderCanvases() - { - if (!play || !Application.isPlaying || _callback == null) - { - return; - } - - _time += updateMode == AnimatorUpdateMode.UnscaledTime - ? Time.unscaledDeltaTime - : Time.deltaTime; - var current = _time / duration; - - if (duration <= _time) - { - play = loop; - _time = loop ? -loopDelay : 0; - } - - _callback(current); - } - } -} -- cgit v1.1-26-g67d0