123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- using UnityEngine;
- using System.Linq;
- using System.Collections;
- using System.Collections.Generic;
- public class TweenSr : TweenRoot
- {
- #region 变量
- public override bool InOrigin
- {
- get
- {
- if (Target.color.Equal(Origin))
- {
- InOrigin_ = true;
- }
- else
- {
- InOrigin_ = false;
- }
- return InOrigin_;
- }
- set
- {
- InOrigin_ = value;
- InPause = false;
- InForward = false;
- InBackward = false;
- if (InOrigin_)
- {
- Target.color = Origin;
- UpdateChildSpriteRenderer();
- if (Group)
- {
- for (int i = 0; i < ChildList.Count; i++)
- {
- if (!ChildList[i].transform.IsChildOf(Target.transform))
- {
- ChildList.RemoveAt(i--);
- continue;
- }
- Color selfColor = ColorDic[ChildList[i]];
- if (AlphaOnly)
- {
- ChildList[i].color = new Color(selfColor.r, selfColor.g, selfColor.b, selfColor.a * Target.color.a);
- }
- else
- {
- ChildList[i].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;
- InPause = false;
- InForward = false;
- InBackward = false;
- if (InDestination_)
- {
- Target.color = Destination;
- UpdateChildSpriteRenderer();
- if (Group)
- {
- for (int i = 0; i < ChildList.Count; i++)
- {
- if (!ChildList[i].transform.IsChildOf(Target.transform))
- {
- ChildList.RemoveAt(i--);
- continue;
- }
- Color selfColor = ColorDic[ChildList[i]];
- if (AlphaOnly)
- {
- ChildList[i].color = new Color(selfColor.r, selfColor.g, selfColor.b, selfColor.a * Target.color.a);
- }
- else
- {
- ChildList[i].color = selfColor*Target.color;
- }
- }
- }
- ForwardFinish();
- }
- }
- }
- public bool Group;
- public bool AlphaOnly;
- public Color Delta;
- public Color Origin;
- public Color Destination;
- public SpriteRenderer Target;
- public CurveFunctionC Func;
- public List<SpriteRenderer> ChildList = new List<SpriteRenderer>();
- public Dictionary<SpriteRenderer, Color> ColorDic = new Dictionary<SpriteRenderer, Color>();
- #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 bool StartForward()
- {
- if (base.StartForward())
- {
- return true;
- }
- UpdateChildSpriteRenderer();
- if (InBackward)
- {
- InBackward = false;
- Timer = ManaAnim.GetTimerColor(Target.color, Duration, Origin, Delta, Curve);
- }
- return false;
- }
- public override bool StartBackward()
- {
- if (base.StartBackward())
- {
- return true;
- }
- UpdateChildSpriteRenderer();
- if (InForward)
- {
- InForward = false;
- Timer = ManaAnim.GetTimerColor(Target.color, Duration, Destination, new Color(-Delta.r, -Delta.g, -Delta.b, -Delta.a), Curve);
- }
- return false;
- }
- public override bool DoForward()
- {
- Timer += Time.deltaTime;
- if (Timer > Duration)
- {
- InDestination = true;
- if (OnForwardFinish != null)
- {
- OnForwardFinish.Invoke();
- }
- SetLoop(EventType.ForwardFinish);
- return true;
- }
- else
- {
- Target.color = Func(Timer, Duration, Origin, Delta);
- if (Group)
- {
- for (int i = 0; i < ChildList.Count; i++)
- {
- if (!ChildList[i].transform.IsChildOf(Target.transform))
- {
- ChildList.RemoveAt(i--);
-
- continue;
- }
-
- Color selfColor = ColorDic[ChildList[i]];
- if (AlphaOnly)
- {
- ChildList[i].color = new Color(selfColor.r, selfColor.g, selfColor.b, selfColor.a * Target.color.a);
- }
- else
- {
- ChildList[i].color = selfColor * Target.color;
- }
- }
- }
- return false;
- }
- }
- public override bool DoBackward()
- {
- Timer += Time.deltaTime;
- if (Timer > Duration)
- {
- InOrigin = true;
- if (OnBackwardFinish != null)
- {
- OnBackwardFinish.Invoke();
- }
- SetLoop(EventType.BackwardFinish);
- 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.IsChildOf(Target.transform))
- {
- ChildList.RemoveAt(i--);
-
- continue;
- }
- Color selfColor = ColorDic[ChildList[i]];
-
- if (AlphaOnly)
- {
- ChildList[i].color = new Color(selfColor.r, selfColor.g, selfColor.b, selfColor.a*Target.color.a);
- }
- else
- {
- ChildList[i].color = selfColor * Target.color;
- }
- }
- }
- return false;
- }
- }
- public void UpdateChildSpriteRenderer()
- {
- if (Group)
- {
- SpriteRenderer[] renderers = Target.GetComponentsInChildren<SpriteRenderer>();
- ChildList = new List<SpriteRenderer>();
- for (int i = 1; i < renderers.Length; i++)
- {
- SpriteRenderer renderer = renderers[i];
- ChildList.Add(renderer);
- if (!ColorDic.ContainsKey(renderer))
- {
- ColorDic.Add(renderer, renderer.color);
- }
- }
- List<SpriteRenderer> keyList = ColorDic.Keys.ToList();
- for (int i = 0; i < keyList.Count; i++)
- {
- if (!ChildList.Contains(keyList[i]))
- {
- ColorDic.Remove(keyList[i]);
- }
- }
- }
- }
- }
|