using UnityEngine; using System; using System.Collections; public class TweenVec : Tween { #region public override bool InOrigin { get { if (Local) { if (Target.localPosition == Origin) { _InOrigin = true; } else { _InOrigin = false; } } else { if (Target.position == Origin) { _InOrigin = true; } else { _InOrigin = false; } } return _InOrigin; } set { _InOrigin = value; if (_InOrigin) { if (Local) { Target.localPosition = Origin; } else { Target.position = Origin; } Target.SetActive(OriginActive); if (CG != null) { CG.interactable = OriginActive; } } } } public override bool InDestination { get { if (Local) { if (Target.localPosition == Destination) { _InDestination = true; } else { _InDestination = false; } } else { if (Target.position == Destination) { _InDestination = true; } else { _InDestination = false; } } return _InDestination; } set { _InDestination = value; if (_InDestination) { if (Local) { Target.localPosition = Destination; } else { Target.position = Destination; } Target.SetActive(DestActive); if (CG != null) { CG.interactable = DestActive; } } } } protected bool Local; protected Vector3 Delta; protected Vector3 Origin; protected Vector3 Destination; protected Transform Target; protected CanvasGroup CG; protected CurveFunctionV Func; #endregion public TweenVec(Transform target, Vector3 origin, Vector3 destination, float duration, bool local, bool originActive, bool destActive, Curve curve) { CG = target.GetComponent(); Func = ManaAnim.CurveFuncDicV[curve]; Target = target; InForward = false; InBackward = false; Local = local; Delta = destination - origin; Origin = origin; Duration = duration; DestActive = destActive; Destination = destination; OriginActive = originActive; } public override void StartForward() { base.StartForward(); Target.SetActive(true); if (CG != null) { CG.interactable = false; } if (InBackward) { Timer = Duration - Timer; } else { if (Local) { Target.localPosition = Origin; } else { Target.position = Origin; } } } public override void StartBackward() { base.StartBackward(); Target.SetActive(true); if (CG != null) { CG.interactable = false; } if (InForward) { Timer = Duration - Timer; } else { if (Local) { Target.localPosition = Destination; } else { Target.position = Destination; } } } public override bool DoForward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { Timer = 0; InForward = false; InDestination = true; if (OnForwardFinish != null) { OnForwardFinish.Invoke(); } ManaAnim.TweenForList.Remove(this); return true; } else { if (Local) { Target.localPosition = Func(Timer, Duration, Origin, Delta); } else { Target.position = Func(Timer, Duration, Origin, Delta); } return false; } } public override bool DoBackward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { Timer = 0; InBackward = false; InOrigin = true; if (OnBackwardFinish != null) { OnBackwardFinish.Invoke(); } ManaAnim.TweenBacList.Remove(this); return true; } else { if (Local) { Target.localPosition = Func(Timer, Duration, Destination, -Delta); } else { Target.position = Func(Timer, Duration, Destination, -Delta); } return false; } } }