using UnityEngine; using System.Collections; public class TweenSr : Tween { #region 变量 public override bool InOrigin { get { if (Target.color == Origin) { _InOrigin = true; } else { _InOrigin = false; } return _InOrigin; } set { _InOrigin = value; if (_InOrigin) { Target.color = Origin; if (Group) { for (int i = 0; i < Targets.Length; i++) { Targets[i].SetAlpha(Target.color.a * Targets[i].color.a); } } Target.SetActive(OriginActive); } } } public override bool InDestination { get { if (Target.color == Destination) { _InDestination = true; } else { _InDestination = false; } return _InDestination; } set { _InDestination = value; if (_InDestination) { Target.color = Destination; if (Group) { for (int i = 0; i < Targets.Length; i++) { Targets[i].SetAlpha(Target.color.a * Targets[i].color.a); } } Target.SetActive(DestActive); } } } protected bool Group; protected Color Delta; protected Color Origin; protected Color Destination; protected SpriteRenderer Target; protected SpriteRenderer[] Targets; protected CurveFunctionC Func; #endregion public TweenSr(SpriteRenderer target, Color origin, Color destination, float duration, bool group, bool originActive, bool destActive, Curve curve) { Func = ManaAnim.CurveFuncDicC[curve]; Target = target; InForward = false; InBackward = false; Delta = destination - origin; Origin = origin; Group = group; Duration = duration; DestActive = destActive; Destination = destination; OriginActive = originActive; } public override void StartForward() { base.StartForward(); Target.SetActive(true); if (Group) { Targets = Target.GetComponentsInChildren(); } if (InBackward) { Timer = Duration - Timer; } else { Target.color = Origin; } } public override void StartBackward() { base.StartBackward(); Target.SetActive(true); if (Group) { Targets = Target.GetComponentsInChildren(); } if (InForward) { Timer = Duration - Timer; } else { Target.color = Destination; } } public override bool DoForward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { Timer = 0; InForward = false; InDestination = true; if (OnForwardFinish != null) { OnForwardFinish.Invoke(); } ManaAnim.TweenForList.Remove(this); return true; } else { Target.color = Func(Timer, Duration, Origin, Delta); if (Group) { for (int i = 0; i < Targets.Length; i++) { Targets[i].SetAlpha(Target.color.a * Targets[i].color.a); } } return false; } } public override bool DoBackward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { Timer = 0; InBackward = false; InOrigin = true; if (OnBackwardFinish != null) { 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)); if (Group) { for (int i = 0; i < Targets.Length; i++) { Targets[i].SetAlpha(Target.color.a * Targets[i].color.a); } } return false; } } }