using UnityEngine; using UnityEngine.UI; using System; using System.Collections; public class TweenGra : Tween { #region 变量 protected Color Delta; protected Color Origin; protected Color Destination; protected Graphic Target; protected CurveFunctionC Func; #endregion public TweenGra(Graphic target, Color origin, Color destination, float duration, bool originActive, bool destActive, Curve curve) { if (target.color == origin) { InForward = true; } else if (target.color == destination) { InBackward = true; } Func = ManaAnim.FunctionDicC[curve]; Target = target; IsForward = false; IsBackward = false; Delta = destination - origin; Origin = origin; Duration = duration; DestActive = destActive; Destination = destination; OriginActive = originActive; OnForwardStart += () => { Target.SetActive(true); }; OnForwardFinish += () => { Target.SetActive(DestActive); }; OnBackwardStart += () => { Target.SetActive(true); }; OnBackwardFinish += () => { Target.SetActive(OriginActive); }; } public override void StartForward() { base.StartForward(); if (IsBackward) { Timer = Duration - Timer; } else { Target.color = Origin; } } public override void StartBackward() { base.StartBackward(); if (IsForward) { Timer = Duration - Timer; } else { Target.color = Destination; } } public override bool DoForward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { Timer = 0; Target.color = Destination; IsForward = false; InBackward = true; OnForwardFinish.Invoke(); ManaAnim.TweenForList.Remove(this); return true; } else { Target.color = Func(Timer, Duration, Origin, Delta); return false; } } public override bool DoBackward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { Timer = 0; Target.color = Origin; IsBackward = false; InForward = true; OnBackwardFinish.Invoke(); ManaAnim.TweenBacList.Remove(this); return true; } else { Target.color = Func(Timer, Duration, Destination, new Color(-Delta.r, -Delta.g, -Delta.b, -Delta.a)); return false; } } }