123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using System;
- using UnityEngine;
- using UnityEngine.UI;
- 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)
- {
- Target = target;
- IsForward = false;
- IsBackward = false;
- Duration = duration;
- DestActive = destActive;
- OriginActive = originActive;
- Delta = destination - origin;
- Origin = origin;
- Destination = destination;
-
- OnForwardStart += () =>
- {
- Target.SetActive(true);
- };
- OnForwardFinish += () =>
- {
- Target.SetActive(DestActive);
- };
- OnBackwardStart += () =>
- {
- Target.SetActive(true);
- };
- OnBackwardFinish += () =>
- {
- Target.SetActive(OriginActive);
- };
- Func = ManaAnim.FunctionDicC[curve];
- }
- public override void StartForward()
- {
- base.StartForward();
- if (IsBackward)
- {
- Timer = Duration - Timer;
- }
- }
- public override void StartBackward()
- {
- base.StartBackward();
- if (IsForward)
- {
- Timer = Duration - Timer;
- }
- }
- public override bool DoForward()
- {
- Timer += Time.fixedDeltaTime;
- if (Timer > Duration)
- {
- Target.color = Destination;
- Timer = 0;
- IsForward = false;
- 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)
- {
- Target.color = Origin;
- Timer = 0;
- IsBackward = false;
- 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;
- }
- }
- }
|