using UnityEngine; using System.Collections; public class TweenScrr : Tween { #region protected Vector2 Delta; protected Vector2 Origin; protected Vector2 Destination; protected CanvasGroup CG; protected RectTransform Target; protected CurveFunctionV Func; #endregion public TweenScrr(RectTransform target, Vector3 origin, Vector3 destination, float duration, bool originActive, bool destActive, Curve curve) { Target = target; IsForward = false; IsBackward = false; Duration = duration; DestActive = destActive; OriginActive = originActive; Delta = destination - origin; Origin = origin; Destination = destination; CG = Target.GetComponent(); OnForwardStart += () => { Target.SetActive(true); if (CG != null) { CG.interactable = false; } }; OnForwardFinish += () => { Target.SetActive(DestActive); if (CG != null) { CG.interactable = DestActive; } }; OnBackwardStart += () => { Target.SetActive(true); if (CG != null) { CG.interactable = false; } }; OnBackwardFinish += () => { Target.SetActive(OriginActive); if (CG != null) { CG.interactable = OriginActive; } }; Func = ManaAnim.FunctionDicV[curve]; } public override void StartForward() { base.StartForward(); if (IsBackward) { Timer = Duration - Timer; } } public override void StartBackward() { base.StartBackward(); if (IsForward) { Timer = Duration - Timer; } } public override bool DoForward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { Target.position = Destination; Timer = 0; IsForward = false; OnForwardFinish.Invoke(); ManaAnim.TweenForList.Remove(this); return true; } else { Target.position = Func(Timer, Duration, Origin, Delta); return false; } } public override bool DoBackward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { Target.position = Origin; Timer = 0; IsBackward = false; OnBackwardFinish.Invoke(); ManaAnim.TweenBacList.Remove(this); return true; } else { Target.position = Func(Timer, Duration, Destination, -Delta); return false; } } }