using UnityEngine; using System; using System.Collections; public class TweenCG : Tween { #region 变量 public override bool InOrigin { get { if (Math.Abs(Target.alpha - Origin) < 0.0005f) { _InOrigin = true; } else { _InOrigin = false; } return _InOrigin; } set { _InOrigin = value; if (_InOrigin) { Target.alpha = Origin; } } } public override bool InDestination { get { if (Math.Abs(Target.alpha - Destination) < 0.0005f) { _InDestination = true; } else { _InDestination = false; } return _InDestination; } set { _InDestination = value; if (_InDestination) { Target.alpha = Destination; } } } 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) { Func = ManaAnim.CurveFuncDicF[curve]; Target = target; InForward = false; InBackward = false; Delta = destination - origin; Origin = origin; Duration = duration; DestActive = destActive; Destination = destination; OriginActive = originActive; OnForwardStart += () => { }; OnForwardFinish += () => { }; OnBackwardStart += () => { }; OnBackwardFinish += () => { }; } public override void StartForward() { base.StartForward(); Target.SetActive(true); Target.interactable = false; if (InBackward) { Timer = Duration - Timer; } else { Target.alpha = Origin; } } public override void StartBackward() { base.StartBackward(); Target.SetActive(true); Target.interactable = false; if (InForward) { Timer = Duration - Timer; } else { Target.alpha = Destination; } } public override bool DoForward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { Timer = 0; InForward = false; InDestination = true; Target.SetActive(DestActive); Target.interactable = DestActive; 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; InBackward = false; InOrigin = true; Target.SetActive(OriginActive); Target.interactable = OriginActive; OnBackwardFinish.Invoke(); ManaAnim.TweenBacList.Remove(this); return true; } else { Target.alpha = Func(Timer, Duration, Destination, -Delta); return false; } } }