using UnityEngine; using System.Linq; using System.Collections; using System.Collections.Generic; public class TweenSr : Tween { #region 变量 public override bool InOrigin { get { if (Target.color.Equal(Origin)) { _InOrigin = true; } else { _InOrigin = false; } return _InOrigin; } set { _InOrigin = value; if (_InOrigin) { Target.color = Origin; if (Group) { for (int i = 0; i < ChildList.Count; i++) { if (ChildList[i].transform.parent != Target.transform) { ChildList.RemoveAt(i--); continue; } Color selfColor = ColorDic[ChildList[i]]; ChildList[i].material.SetColor("_Color", selfColor * Target.color); } } BackwardFinish(); } } } public override bool InDestination { get { if (Target.color.Equal(Destination)) { _InDestination = true; } else { _InDestination = false; } return _InDestination; } set { _InDestination = value; if (_InDestination) { Target.color = Destination; if (Group) { for (int i = 0; i < ChildList.Count; i++) { if (ChildList[i].transform.parent != Target.transform) { ChildList.RemoveAt(i--); continue; } Color selfColor = ColorDic[ChildList[i]]; ChildList[i].material.SetColor("_Color", selfColor * Target.color); } } ForwardFinish(); } } } public bool Group; public Color Delta; public Color Origin; public Color Destination; public SpriteRenderer Target; public CurveFunctionC Func; public List ChildList; public Dictionary ColorDic = new Dictionary(); #endregion public TweenSr(SpriteRenderer target, Color origin, Color destination, float duration, bool originActive, bool destActive, Curve curve,bool cg = false,bool group=false) : base(cg, curve, target) { 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(); if (Group) { Renderer[] renderers = Target.GetComponentsInChildren(); ChildList = new List(); for (int i = 1; i < renderers.Length; i++) { Renderer renderer = renderers[i]; ChildList.Add(renderer); if (!ColorDic.ContainsKey(renderer)) { ColorDic.Add(renderer, renderer.material.GetColor("_Color")); } } List keyList = ColorDic.Keys.ToList(); for (int i = 0; i < keyList.Count; i++) { if (!ChildList.Contains(keyList[i])) { ColorDic.Remove(keyList[i]); } } } if (InBackward) { Timer = ManaAnim.GetTimerColor(Target.color, Duration, Origin, Delta, Curve); } } public override void StartBackward() { base.StartBackward(); if (Group) { Renderer[] renderers = Target.GetComponentsInChildren(); ChildList = new List(); for (int i = 1; i < renderers.Length; i++) { Renderer renderer = renderers[i]; ChildList.Add(renderer); if (!ColorDic.ContainsKey(renderer)) { ColorDic.Add(renderer, renderer.material.GetColor("_Color")); } } List keyList = ColorDic.Keys.ToList(); for (int i = 0; i < keyList.Count; i++) { if (!ChildList.Contains(keyList[i])) { ColorDic.Remove(keyList[i]); } } } if (InForward) { Timer = ManaAnim.GetTimerColor(Target.color, Duration, Destination, new Color(-Delta.r, -Delta.g, -Delta.b, -Delta.a), Curve); } } public override bool DoForward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { InForward = false; InDestination = true; if (OnForwardFinish != null) { OnForwardFinish.Invoke(); } return true; } else { Target.color = Func(Timer, Duration, Origin, Delta); if (Group) { for (int i = 0; i < ChildList.Count; i++) { if (ChildList[i].transform.parent != Target.transform) { ChildList.RemoveAt(i--); continue; } Color selfColor = ColorDic[ChildList[i]]; ChildList[i].material.SetColor("_Color", selfColor * Target.color); } } return false; } } public override bool DoBackward() { Timer += Time.fixedDeltaTime; if (Timer > Duration) { InBackward = false; InOrigin = true; if (OnBackwardFinish != null) { OnBackwardFinish.Invoke(); } 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 < ChildList.Count; i++) { if (ChildList[i].transform.parent != Target.transform) { ChildList.RemoveAt(i--); continue; } Color selfColor = ColorDic[ChildList[i]]; ChildList[i].material.SetColor("_Color", selfColor * Target.color); } } return false; } } }