123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- 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;
- }
- }
- }
|