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; } } protected bool _InOrigin; protected bool _InDestination; public bool CG; public bool InForward; public bool InBackward; public Component Component; public UnityAction OnForwardStart; public UnityAction OnForwardFinish; public UnityAction OnBackwardStart; public UnityAction OnBackwardFinish; public CanvasGroup CanvasGroup; public float Duration; protected float Timer; protected bool DestActive; protected bool OriginActive; public abstract bool DoForward(); public abstract bool DoBackward(); protected Tween(bool cg, Component comp) { CG = cg; Component = comp; if (cg) { CanvasGroup = comp.GetComponent(); } } public void ConfineForward() { if (InOrigin) { StartForward(); } } public void ConfineBackward() { if (InDestination) { StartBackward(); } } public virtual void StartForward() { InForward = true; Component.SetActive(true); if (OnForwardStart != null) { OnForwardStart.Invoke(); } if (CG) { CanvasGroup.interactable = false; } ManaAnim.TweenForList.Add(this); ManaAnim.TweenBacList.Remove(this); } public virtual void StartBackward() { InBackward = true; Component.SetActive(true); if (OnBackwardStart != null) { OnBackwardStart.Invoke(); } if (CG) { CanvasGroup.interactable = false; } ManaAnim.TweenForList.Remove(this); ManaAnim.TweenBacList.Add(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; } } }