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) { if (Math.Abs(target.alpha - origin) < 0.0005f) { InForward = true; } else if (Math.Abs(target.alpha - destination) < 0.0005f) { InBackward = true; } Func = ManaAnim.FunctionDicF[curve]; Target = target; IsForward = false; IsBackward = false; Delta = destination - origin; Origin = origin; Duration = duration; DestActive = destActive; Destination = destination; OriginActive = originActive; 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; }; } public override void StartForward() { base.StartForward(); if (IsBackward) { Timer = Duration - Timer; } else { Target.alpha = Origin; } } public override void StartBackward() { base.StartBackward(); if (IsForward) { Timer = Duration - Timer; } else { Target.alpha = Destination; } } public override bool DoForward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { Timer = 0; Target.alpha = Destination; IsForward = false; InBackward = true; 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) { Timer = 0; Target.alpha = Origin; IsBackward = false; InForward = true; OnBackwardFinish.Invoke(); ManaAnim.TweenBacList.Remove(this); return true; } else { Target.alpha = Func(Timer, Duration, Destination, -Delta); return false; } } }