using UnityEngine; using System; using System.Collections; public class TweenCG : Tween { #region 变量 protected float Delta; protected float Origin; protected float Destination; protected CanvasGroup Target; protected CurveFunctionF Func; #endregion public TweenCG(CanvasGroup target, float origin, float 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; OnForwardStart += () => { Target.SetActive(true); Target.interactable = false; }; OnForwardFinish += () => { Target.SetActive(DestActive); Target.interactable = DestActive; }; OnBackwardStart += () => { Target.SetActive(true); Target.interactable = false; }; OnBackwardFinish += () => { Target.SetActive(OriginActive); Target.interactable = OriginActive; }; Func = ManaAnim.FunctionDicF[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.alpha = Destination; Timer = 0; IsForward = false; OnForwardFinish.Invoke(); ManaAnim.TweenForList.Remove(this); return true; } else { Target.alpha = Func(Timer, Duration, Origin, Delta); return false; } } public override bool DoBackward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { Target.alpha = Origin; Timer = 0; IsBackward = false; OnBackwardFinish.Invoke(); ManaAnim.TweenBacList.Remove(this); return true; } else { Target.alpha = Func(Timer, Duration, Destination, -Delta); return false; } } }