123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using UnityEngine;
- namespace Animancer
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public class MixerParameterTweenFloat : MixerParameterTween<float>
- {
- public MixerParameterTweenFloat() { }
- public MixerParameterTweenFloat(MixerState<float> mixer) : base(mixer) { }
- protected override float CalculateCurrentValue() => Mathf.LerpUnclamped(StartValue, EndValue, Progress);
- }
-
-
-
-
-
- public class MixerParameterTweenVector2 : MixerParameterTween<Vector2>
- {
- public MixerParameterTweenVector2() { }
- public MixerParameterTweenVector2(MixerState<Vector2> mixer) : base(mixer) { }
- protected override Vector2 CalculateCurrentValue() => Vector2.LerpUnclamped(StartValue, EndValue, Progress);
- }
-
-
-
-
-
- public abstract class MixerParameterTween<TParameter> : Key, IUpdatable
- {
-
-
- public MixerState<TParameter> Mixer { get; set; }
-
-
- public TParameter StartValue { get; set; }
-
- public TParameter EndValue { get; set; }
-
-
- public float Duration { get; set; }
-
- public float Time { get; set; }
-
- public float Progress
- {
- get => Time / Duration;
- set => Time = value * Duration;
- }
-
-
- public MixerParameterTween() { }
-
- public MixerParameterTween(MixerState<TParameter> mixer) => Mixer = mixer;
-
-
-
-
- public void Start(TParameter endValue, float duration)
- {
- #if UNITY_ASSERTIONS
- AnimancerUtilities.Assert(Mixer != null, nameof(Mixer) + " is null.");
- AnimancerUtilities.Assert(Mixer.Root != null, $"{nameof(Mixer)}.{nameof(Mixer.Root)} is null.");
- #endif
- StartValue = Mixer.Parameter;
- EndValue = endValue;
- Duration = duration;
- Time = 0;
- Mixer.Root.RequirePreUpdate(this);
- }
-
-
- public void Stop() => Mixer?.Root?.CancelPreUpdate(this);
-
-
- public bool IsActive => IsInList(this);
-
-
-
-
-
-
- protected abstract TParameter CalculateCurrentValue();
-
- void IUpdatable.Update()
- {
- Time += AnimancerPlayable.DeltaTime;
- if (Time < Duration)
- {
- Mixer.Parameter = CalculateCurrentValue();
- }
- else
- {
- Time = Duration;
- Mixer.Parameter = EndValue;
- Stop();
- }
- }
-
- }
- }
|