123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- 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<CanvasGroup>();
- }
- }
- 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;
- }
- }
- }
|