using UnityEngine; using UnityEngine.Events; using System; using System.Collections; public abstract class Tween { public virtual bool InOrigin { get { return _InOrigin; } set { _InOrigin = value; } } public virtual bool InDestination { get { return _InDestination; } set { _InDestination = value; } } public bool _InOrigin; public bool _InDestination; public bool CG; public bool InForward; public bool InBackward; public Curve Curve; public Component Component; public UnityAction OnForwardStart; public UnityAction OnForwardFinish; public UnityAction OnBackwardStart; public UnityAction OnBackwardFinish; public CanvasGroup CanvasGroup; public float Duration; public float Timer; public bool DestActive; public bool OriginActive; public abstract bool DoForward(); public abstract bool DoBackward(); public Tween(bool cg, Curve curve, Component comp) { CG = cg; Curve = curve; Component = comp; if (cg) { CanvasGroup = comp.GetComponent(); } } public void ReForward() { Timer = 0; if (InBackward) { InBackward = false; ManaAnim.TweenBacList.Remove(this); } if (!InForward) { StartForward(); } } public void ReBackward() { Timer = 0; if (InForward) { InForward = false; ManaAnim.TweenForList.Remove(this); } if (!InBackward) { StartBackward(); } } public void ConfineForward() { if (!InDestination) { StartForward(); } } public void ConfineBackward() { if (!InOrigin) { StartBackward(); } } public virtual void StartForward() { InForward = true; Component.SetActive(true); if (InOrigin) { OnForwardStart.SafeInvoke(); } if (CG) { CanvasGroup.interactable = false; } if (InBackward) { ManaAnim.TweenBacList.Remove(this); } ManaAnim.TweenForList.UniqueAdd(this); } public virtual void StartBackward() { InBackward = true; Component.SetActive(true); if (InDestination) { OnBackwardStart.SafeInvoke(); } if (CG) { CanvasGroup.interactable = false; } if (InForward) { ManaAnim.TweenForList.Remove(this); } ManaAnim.TweenBacList.UniqueAdd(this); } protected void FinishForward() { Component.SetActive(DestActive); if (CG) { CanvasGroup.interactable = DestActive; } } protected void FinishBackward() { Component.SetActive(OriginActive); if (CG) { CanvasGroup.interactable = OriginActive; } } public 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 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 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; } } }