123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- using UnityEngine;
- using System;
- using System.Collections;
- public class TweenAudio : Tween
- {
- #region 变量
- public override bool InOrigin
- {
- get
- {
- if (Math.Abs(Target.volume - Origin) < 0.0005f)
- {
- _InOrigin = true;
- }
- else
- {
- _InOrigin = false;
- }
- return _InOrigin;
- }
- set
- {
- _InOrigin = value;
- if (_InOrigin)
- {
- Target.volume = Origin;
- FinishBackward();
- }
- }
- }
- public override bool InDestination
- {
- get
- {
- if (Math.Abs(Target.volume - Destination) < 0.0005f)
- {
- _InDestination = true;
- }
- else
- {
- _InDestination = false;
- }
- return _InDestination;
- }
- set
- {
- _InDestination = value;
- if (_InDestination)
- {
- Target.volume = Destination;
- FinishForward();
- }
- }
- }
- protected float Delta;
- protected float Origin;
- protected float Destination;
- protected AudioSource Target;
- protected CurveFunctionF Func;
- #endregion
- public TweenAudio(AudioSource target, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false) : base(cg, target)
- {
- Func = ManaAnim.CurveFuncDicF[curve];
- Target = target;
- InForward = false;
- InBackward = false;
- Delta = destination - origin;
- Origin = origin;
- Duration = duration;
- Destination = destination;
- DestActive = destActive;
- OriginActive = originActive;
- }
- public override void StartForward()
- {
- base.StartForward();
- if (InBackward)
- {
- Timer = Duration - Timer;
- }
- else
- {
- Target.volume = Origin;
- }
- }
- public override void StartBackward()
- {
- base.StartBackward();
- if (InForward)
- {
- Timer = Duration - Timer;
- }
- else
- {
- Target.volume = Destination;
- }
- }
- public override bool DoForward()
- {
- Timer += Time.fixedDeltaTime;
- if (Timer > Duration)
- {
- FinishForward();
- Timer = 0;
- InForward = false;
- InDestination = true;
- if (OnForwardFinish != null)
- {
- OnForwardFinish.Invoke();
- }
- ManaAnim.TweenForList.Remove(this);
- return true;
- }
- else
- {
- Target.volume = Func(Timer, Duration, Origin, Delta);
- return false;
- }
- }
- public override bool DoBackward()
- {
- Timer += Time.fixedDeltaTime;
- if (Timer > Duration)
- {
- FinishBackward();
- Timer = 0;
- InBackward = false;
- InOrigin = true;
- if (OnBackwardFinish != null)
- {
- OnBackwardFinish.Invoke();
- }
- ManaAnim.TweenBacList.Remove(this);
- return true;
- }
- else
- {
- Target.volume = Func(Timer, Duration, Destination, -Delta);
- return false;
- }
- }
- }
|