using UnityEngine; using UnityEngine.Events; using System; using System.Collections; public abstract class TweenRoot : MoveRoot { public virtual bool InOrigin { get { return InOrigin_; } set { InOrigin_ = value; } } public bool InOrigin_; public bool CG; public bool Repeat; public bool PingPong; public bool InForward; public bool InBackward; public Curve Curve; public Component Component; public UnityAction OnBackwardStart; public UnityAction OnBackwardFinish; public CanvasGroup CanvasGroup; public float Duration; public float Timer; public bool DestActive; public bool OriginActive; public bool IgnoreActiveControll; public TweenRoot(bool cg, Curve curve, Component comp) { CG = cg; Curve = curve; Component = comp; if (cg) { CanvasGroup = comp.GetComponent(); } } public override void Pause() { if (!InPause) { if (InForward) { InPause = true; AnimManager.MoveForList.Remove(this); } else if (InBackward) { InPause = true; AnimManager.MoveBacList.Remove(this); } } } public override void Resume() { if (InPause) { InPause = false; if (InForward) { AnimManager.MoveForList.Add(this); } else if (InBackward) { AnimManager.MoveBacList.Add(this); } } } public void SetLoop(EventType eventType) { if (eventType == EventType.ForwardFinish) { if (Repeat) { ReForward(); } else if (PingPong) { StartBackward(); } } else if (eventType == EventType.BackwardFinish) { if (Repeat) { ReBackward(); } else if (PingPong) { StartForward(); } } } public virtual void ReForward() { if (InForward) { InForward = false; AnimManager.MoveForList.Remove(this); } if (InBackward) { InBackward = false; AnimManager.MoveBacList.Remove(this); } Timer = 0; InOrigin = true; StartForward(); } public virtual void ReBackward() { if (InForward) { InForward = false; AnimManager.MoveForList.Remove(this); } if (InBackward) { InBackward = false; AnimManager.MoveBacList.Remove(this); } Timer = 0; InDestination = true; StartBackward(); } public virtual bool StartForward() { InPause = false; if (InForward || InDestination) { return true; } Timer = 0; InForward = true; if (!IgnoreActiveControll) { Component.SetActive(true); } OnForwardStart.SafeInvoke(); if (CG) { CanvasGroup.interactable = false; } if (InBackward) { AnimManager.MoveBacList.Remove(this); } AnimManager.MoveForList.Add(this); return false; } public virtual bool StartBackward() { InPause = false; if (InBackward || InOrigin) { return true; } Timer = 0; InBackward = true; if (!IgnoreActiveControll) { Component.SetActive(true); } OnBackwardStart.SafeInvoke(); if (CG) { CanvasGroup.interactable = false; } if (InForward) { AnimManager.MoveForList.Remove(this); } AnimManager.MoveBacList.Add(this); return false; } public virtual void ForwardFinish() { if (!IgnoreActiveControll) { Component.SetActive(DestActive); if (CG) { CanvasGroup.interactable = DestActive; } } } public virtual void BackwardFinish() { if (!IgnoreActiveControll) { Component.SetActive(OriginActive); if (CG) { CanvasGroup.interactable = OriginActive; } } } public override void PushEvent(EventType type, UnityAction action) { if (type == EventType.ForwardStart) { OnForwardStart = action + OnForwardStart; } else if (type == EventType.ForwardFinish) { OnForwardFinish = action + OnForwardFinish; } else if (type == EventType.BackwardStart) { OnBackwardStart = action + OnBackwardStart; } else if (type == EventType.BackwardFinish) { OnBackwardFinish = action + OnBackwardFinish; } } public override void AddEventOnetime(EventType type, UnityAction action) { if (type == EventType.ForwardStart) { action += () => { OnForwardStart -= action; }; OnForwardStart += action; } else if (type == EventType.ForwardFinish) { action += () => { OnForwardFinish -= action; }; OnForwardFinish += action; } else if (type == EventType.BackwardStart) { action += () => { OnBackwardStart -= action; }; OnBackwardStart += action; } else if (type == EventType.BackwardFinish) { action += () => { OnBackwardFinish -= action; }; OnBackwardFinish += action; } } public override void PushEventOnetime(EventType type, UnityAction action) { if (type == EventType.ForwardStart) { action += () => { OnForwardStart -= action; }; OnForwardStart = action + OnForwardStart; } else if (type == EventType.ForwardFinish) { action += () => { OnForwardFinish -= action; }; OnForwardFinish = action + OnForwardFinish; } else if (type == EventType.BackwardStart) { action += () => { OnBackwardStart -= action; }; OnBackwardStart = action + OnBackwardStart; } else if (type == EventType.BackwardFinish) { action += () => { OnBackwardFinish -= action; }; OnBackwardFinish = action + OnBackwardFinish; } } }