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