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 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; ManaAnim.MoveForList.Remove(this); } else if (InBackward) { InPause = true; ManaAnim.MoveBacList.Remove(this); } } } public override void Resume() { if (InPause) { InPause = false; if (InForward) { ManaAnim.MoveForList.Add(this); } else if (InBackward) { ManaAnim.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; ManaAnim.MoveForList.Remove(this); } if (InBackward) { InBackward = false; ManaAnim.MoveBacList.Remove(this); } Timer = 0; InOrigin = true; StartForward(); } public virtual void ReBackward() { if (InForward) { InForward = false; ManaAnim.MoveForList.Remove(this); } if (InBackward) { InBackward = false; ManaAnim.MoveBacList.Remove(this); } Timer = 0; InDestination = true; StartBackward(); } public virtual bool StartForward() { InPause = false; if (InForward || InDestination) { return true; } Timer = 0; InForward = true; Component.SetActive(true); OnForwardStart.SafeInvoke(); if (CG) { CanvasGroup.interactable = false; } if (InBackward) { ManaAnim.MoveBacList.Remove(this); } ManaAnim.MoveForList.Add(this); return false; } public virtual bool StartBackward() { InPause = false; if (InBackward || InOrigin) { return true; } Timer = 0; InBackward = true; Component.SetActive(true); OnBackwardStart.SafeInvoke(); if (CG) { CanvasGroup.interactable = false; } if (InForward) { ManaAnim.MoveForList.Remove(this); } ManaAnim.MoveBacList.Add(this); return false; } public virtual void ForwardFinish() { Component.SetActive(DestActive); if (CG) { CanvasGroup.interactable = DestActive; } } public virtual void BackwardFinish() { 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; } } }