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