123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- using UnityEngine;
- using System.Linq;
- using System.Collections;
- using System.Collections.Generic;
- public class TweenRenderer : TweenRoot
- {
- #region 变量
- public override bool InOrigin
- {
- get
- {
- if (Target.material.GetColor("_Color").Equal(Origin))
- {
- InOrigin_ = true;
- }
- else
- {
- InOrigin_ = false;
- }
- return InOrigin_;
- }
- set
- {
- InOrigin_ = value;
- InPause = false;
- InForward = false;
- InBackward = false;
- if (InOrigin_)
- {
- Target.material.SetColor("_Color", Origin);
- 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].material.SetColor("_Color", new Color(selfColor.r, selfColor.g, selfColor.b, selfColor.a * Target.material.GetColor("_Color").a));
- }
- else
- {
- ChildList[i].material.SetColor("_Color", selfColor * Target.material.GetColor("_Color"));
- }
- }
- }
- BackwardFinish();
- }
- }
- }
- public override bool InDestination
- {
- get
- {
- if (Target.material.GetColor("_Color").Equal(Destination))
- {
- InDestination_ = true;
- }
- else
- {
- InDestination_ = false;
- }
- return InDestination_;
- }
- set
- {
- InDestination_ = value;
- InPause = false;
- InForward = false;
- InBackward = false;
- if (InDestination_)
- {
- Target.material.SetColor("_Color", Destination);
- 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].material.SetColor("_Color", new Color(selfColor.r, selfColor.g, selfColor.b, selfColor.a * Target.material.GetColor("_Color").a));
- }
- else
- {
- ChildList[i].material.SetColor("_Color", selfColor * Target.material.GetColor("_Color"));
- }
- }
- }
- ForwardFinish();
- }
- }
- }
- public bool Group;
- public bool AlphaOnly;
- public Color Delta;
- public Color Origin;
- public Color Destination;
- public Renderer Target;
- public CurveFunctionC Func;
- public List<Renderer> ChildList = new List<Renderer>();
- public Dictionary<Renderer, Color> ColorDic = new Dictionary<Renderer, Color>();
- #endregion
- public TweenRenderer(Renderer 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;
- }
- if (Group)
- {
- Renderer[] renderers = Target.GetComponentsInChildren<Renderer>();
- ChildList = new List<Renderer>();
- 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<Renderer> keyList = ColorDic.Keys.ToList();
- for (int i = 0; i < keyList.Count; i++)
- {
- if (!ChildList.Contains(keyList[i]))
- {
- ColorDic.Remove(keyList[i]);
- }
- }
- }
- if (InBackward)
- {
- InBackward = false;
- Timer = ManaAnim.GetTimerColor(Target.material.GetColor("_Color"), Duration, Origin, Delta, Curve);
- }
- return false;
- }
- public override bool StartBackward()
- {
- if (base.StartBackward())
- {
- return true;
- }
- if (Group)
- {
- Renderer[] renderers = Target.GetComponentsInChildren<Renderer>();
- ChildList = new List<Renderer>();
- 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<Renderer> keyList = ColorDic.Keys.ToList();
- for (int i = 0; i < keyList.Count; i++)
- {
- if (!ChildList.Contains(keyList[i]))
- {
- ColorDic.Remove(keyList[i]);
- }
- }
- }
- if (InForward)
- {
- InForward = false;
- Timer = ManaAnim.GetTimerColor(Target.material.GetColor("_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.material.SetColor("_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].material.SetColor("_Color", new Color(selfColor.r, selfColor.g, selfColor.b, selfColor.a * Target.material.GetColor("_Color").a));
- }
- else
- {
- ChildList[i].material.SetColor("_Color", selfColor * Target.material.GetColor("_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.material.SetColor("_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].material.SetColor("_Color", new Color(selfColor.r, selfColor.g, selfColor.b, selfColor.a * Target.material.GetColor("_Color").a));
- }
- else
- {
- ChildList[i].material.SetColor("_Color", selfColor * Target.material.GetColor("_Color"));
- }
- }
- }
- return false;
- }
- }
- }
|