123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- using UnityEngine;
- using System;
- using System.Collections;
- public class TweenCG : Tween
- {
- #region 变量
- protected float Delta;
- protected float Origin;
- protected float Destination;
- protected CanvasGroup Target;
- protected CurveFunctionF Func;
- #endregion
- public TweenCG(CanvasGroup target, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- Target = target;
- Duration = duration;
- DestActive = destActive;
- OriginActive = originActive;
- Delta = destination - origin;
- Origin = origin;
- Destination = destination;
- OnForwardStart += () =>
- {
- Target.SetActive(true);
- Target.interactable = false;
- };
- OnForwardFinish += () =>
- {
- Target.SetActive(DestActive);
- Target.interactable = DestActive;
- };
- OnBackwardStart += () =>
- {
- Target.SetActive(true);
- Target.interactable = false;
- };
- OnBackwardFinish += () =>
- {
- Target.SetActive(OriginActive);
- Target.interactable = OriginActive;
- };
- Func = ManaAnim.FunctionDicF[curve];
- }
- public override bool DoForward()
- {
- if (Timer > Duration)
- {
- Target.alpha = Destination;
- Timer = 0;
- IsBackwardFinish = true;
- OnForwardFinish.Invoke();
- ManaAnim.TweenForList.Remove(this);
- return true;
- }
- else
- {
- Target.alpha = Func(Timer, Duration, Origin, Delta);
- Timer += Time.fixedDeltaTime;
- return false;
- }
- }
- public override bool DoBackward()
- {
- if (Timer > Duration)
- {
- Target.alpha = Origin;
- Timer = 0;
- IsForwardFinish = true;
- OnBackwardFinish.Invoke();
- ManaAnim.TweenBacList.Remove(this);
- return true;
- }
- else
- {
- Target.alpha = Func(Timer, Duration, Destination, -Delta);
- Timer += Time.fixedDeltaTime;
- return false;
- }
- }
- }
|