#region Copyright RenGuiYou. All rights reserved. //===================================================== // NeatlyFrameWork // Author: RenGuiyou // Feedback: mailto:750539605@qq.com //===================================================== #endregion using UnityEngine; namespace Neatly.Tween { public enum LoopMode { None, Loop, PingPong, } public class NTweenImp { private uint m_id; public uint id { get { return m_id; } } public GameObject gameObject; private TweenObjectBase m_Tween; private bool m_Pause; private LoopMode m_LoopMode = LoopMode.None; private OnCompleteDel m_CompleteAction; public delegate void OnCompleteDel(); public bool IsDestroy { get; private set; } public NTweenImp Init(uint uid, TweenObjectBase tween) { m_id = uid; m_Tween = tween; gameObject = tween.gameObject; m_CompleteAction = null; m_Pause = false; IsDestroy = false; m_LoopMode = LoopMode.None; return this; } public void Excute(float dt) { if (m_Tween.IsDestroy) { IsDestroy = true; return; } if (m_Pause) return; if (m_Tween.Excute(dt)) { switch (m_LoopMode) { case LoopMode.Loop: m_Tween.LoopInit(); return; case LoopMode.PingPong: m_Tween.PingPongInit(); return; } IsDestroy = true; } } public NTweenImp SetLoopMode(LoopMode mode) { m_LoopMode = mode; return this; } public NTweenImp SetLoop(bool isLoop = true) { if (isLoop) { m_LoopMode = LoopMode.Loop; } return this; } public NTweenImp SetPingPong(bool isPingPong = true) { if (isPingPong) { m_LoopMode = LoopMode.PingPong; } return this; } public NTweenImp SetOnComplete(OnCompleteDel completeDel) { m_CompleteAction = completeDel; return this; } public void Pause() { m_Pause = true; } public void Resume() { m_Pause = false; } public void Cancel() { m_CompleteAction = null; IsDestroy = true; m_id = 0; } public void Destroy() { if (!m_Tween.IsDestroy) { m_CompleteAction?.Invoke(); } m_Tween.Destroy(); NeatlyTween.Instance.ImplementPool.Recycle(this); } } }