mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-07-02 14:41:15 +00:00
Added GTWeen
This commit is contained in:
parent
457998788e
commit
2036e4e748
152 changed files with 5889 additions and 7 deletions
25
GTweensGodot/GTweens/Source/Tweeners/FloatTweener.cs
Normal file
25
GTweensGodot/GTweens/Source/Tweeners/FloatTweener.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using GTweens.Delegates;
|
||||
using GTweens.Interpolators;
|
||||
|
||||
namespace GTweens.Tweeners;
|
||||
|
||||
public sealed class FloatTweener : Tweener<float>
|
||||
{
|
||||
public FloatTweener(
|
||||
Getter currentValueGetter,
|
||||
Setter setter,
|
||||
Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
: base(
|
||||
currentValueGetter,
|
||||
setter,
|
||||
to,
|
||||
duration,
|
||||
FloatInterpolator.Instance,
|
||||
validation
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
1
GTweensGodot/GTweens/Source/Tweeners/FloatTweener.cs.uid
Normal file
1
GTweensGodot/GTweens/Source/Tweeners/FloatTweener.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bywdapy07yjny
|
||||
25
GTweensGodot/GTweens/Source/Tweeners/ITweener.cs
Normal file
25
GTweensGodot/GTweens/Source/Tweeners/ITweener.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using GTweens.Easings;
|
||||
using GTweens.Enums;
|
||||
|
||||
namespace GTweens.Tweeners
|
||||
{
|
||||
public interface ITweener
|
||||
{
|
||||
float Duration { get; }
|
||||
float Elapsed { get; }
|
||||
float Remaining { get; }
|
||||
|
||||
bool IsPlaying { get; }
|
||||
bool IsCompleted { get; }
|
||||
bool IsKilled { get; }
|
||||
bool IsCompletedOrKilled { get; }
|
||||
|
||||
void SetEasing(EasingDelegate easingFunction);
|
||||
|
||||
void Reset(ResetMode mode);
|
||||
void Start();
|
||||
void Tick(float deltaTime);
|
||||
void Complete();
|
||||
void Kill();
|
||||
}
|
||||
}
|
||||
1
GTweensGodot/GTweens/Source/Tweeners/ITweener.cs.uid
Normal file
1
GTweensGodot/GTweens/Source/Tweeners/ITweener.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://k17rtk6wh5xf
|
||||
26
GTweensGodot/GTweens/Source/Tweeners/IntTweener.cs
Normal file
26
GTweensGodot/GTweens/Source/Tweeners/IntTweener.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using GTweens.Delegates;
|
||||
using GTweens.Interpolators;
|
||||
|
||||
namespace GTweens.Tweeners
|
||||
{
|
||||
public sealed class IntTweener : Tweener<int>
|
||||
{
|
||||
internal IntTweener(
|
||||
Getter currValueGetter,
|
||||
Setter setter,
|
||||
Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
: base(
|
||||
currValueGetter,
|
||||
setter,
|
||||
to,
|
||||
duration,
|
||||
IntInterpolator.Instance,
|
||||
validation
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
1
GTweensGodot/GTweens/Source/Tweeners/IntTweener.cs.uid
Normal file
1
GTweensGodot/GTweens/Source/Tweeners/IntTweener.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ntjjh7jiu8vt
|
||||
26
GTweensGodot/GTweens/Source/Tweeners/SystemColorTweener.cs
Normal file
26
GTweensGodot/GTweens/Source/Tweeners/SystemColorTweener.cs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
using System.Drawing;
|
||||
using GTweens.Delegates;
|
||||
using GTweens.Interpolators;
|
||||
|
||||
namespace GTweens.Tweeners
|
||||
{
|
||||
public sealed class SystemColorTweener : Tweener<Color>
|
||||
{
|
||||
public SystemColorTweener(
|
||||
Getter currValueGetter,
|
||||
Setter setter,
|
||||
Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
: base(currValueGetter,
|
||||
setter,
|
||||
to,
|
||||
duration,
|
||||
SystemColorInterpolator.Instance,
|
||||
validation
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bugpyjerorwcw
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
using System.Numerics;
|
||||
using GTweens.Delegates;
|
||||
using GTweens.Interpolators;
|
||||
|
||||
namespace GTweens.Tweeners
|
||||
{
|
||||
public sealed class SystemQuaternionTweener : Tweener<Quaternion>
|
||||
{
|
||||
public SystemQuaternionTweener(
|
||||
Getter currValueGetter,
|
||||
Setter setter,
|
||||
Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
: base(
|
||||
currValueGetter,
|
||||
setter,
|
||||
to,
|
||||
duration,
|
||||
SystemQuaternionInterpolator.Instance,
|
||||
validation
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://cvhxhs2yx2njy
|
||||
27
GTweensGodot/GTweens/Source/Tweeners/SystemVector2Tweener.cs
Normal file
27
GTweensGodot/GTweens/Source/Tweeners/SystemVector2Tweener.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System.Numerics;
|
||||
using GTweens.Delegates;
|
||||
using GTweens.Interpolators;
|
||||
|
||||
namespace GTweens.Tweeners
|
||||
{
|
||||
public sealed class SystemVector2Tweener : Tweener<Vector2>
|
||||
{
|
||||
public SystemVector2Tweener(
|
||||
Getter currValueGetter,
|
||||
Setter setter,
|
||||
Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
: base(
|
||||
currValueGetter,
|
||||
setter,
|
||||
to,
|
||||
duration,
|
||||
SystemVector2Interpolator.Instance,
|
||||
validation
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://ckm388yjwcuu6
|
||||
27
GTweensGodot/GTweens/Source/Tweeners/SystemVector3Tweener.cs
Normal file
27
GTweensGodot/GTweens/Source/Tweeners/SystemVector3Tweener.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System.Numerics;
|
||||
using GTweens.Delegates;
|
||||
using GTweens.Interpolators;
|
||||
|
||||
namespace GTweens.Tweeners
|
||||
{
|
||||
public sealed class SystemVector3Tweener : Tweener<Vector3>
|
||||
{
|
||||
public SystemVector3Tweener(
|
||||
Getter currValueGetter,
|
||||
Setter setter,
|
||||
Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
: base(
|
||||
currValueGetter,
|
||||
setter,
|
||||
to,
|
||||
duration,
|
||||
SystemVector3Interpolator.Instance,
|
||||
validation
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bpptxf58855kt
|
||||
27
GTweensGodot/GTweens/Source/Tweeners/SystemVector4Tweener.cs
Normal file
27
GTweensGodot/GTweens/Source/Tweeners/SystemVector4Tweener.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System.Numerics;
|
||||
using GTweens.Delegates;
|
||||
using GTweens.Interpolators;
|
||||
|
||||
namespace GTweens.Tweeners
|
||||
{
|
||||
public sealed class SystemVector4Tweener : Tweener<Vector4>
|
||||
{
|
||||
public SystemVector4Tweener(
|
||||
Getter currValueGetter,
|
||||
Setter setter,
|
||||
Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
: base(
|
||||
currValueGetter,
|
||||
setter,
|
||||
to,
|
||||
duration,
|
||||
SystemVector4Interpolator.Instance,
|
||||
validation
|
||||
)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://b4534l80h30dx
|
||||
234
GTweensGodot/GTweens/Source/Tweeners/Tweener.cs
Normal file
234
GTweensGodot/GTweens/Source/Tweeners/Tweener.cs
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
using System;
|
||||
using GTweens.Delegates;
|
||||
using GTweens.Easings;
|
||||
using GTweens.Enums;
|
||||
using GTweens.Extensions;
|
||||
using GTweens.Interpolators;
|
||||
|
||||
namespace GTweens.Tweeners
|
||||
{
|
||||
public abstract class Tweener<T> : ITweener
|
||||
{
|
||||
public delegate void Setter(T currentValue);
|
||||
public delegate T Getter();
|
||||
|
||||
public bool IsPlaying { get; private set; }
|
||||
public bool IsCompleted { get; private set; }
|
||||
public bool IsKilled { get; private set; }
|
||||
public bool IsCompletedOrKilled => IsCompleted || IsKilled;
|
||||
|
||||
public float Duration { get; }
|
||||
public float Elapsed { get; private set; }
|
||||
public float Remaining => Math.Max(Duration - Elapsed, 0f);
|
||||
|
||||
readonly Getter _getter;
|
||||
readonly Setter _setter;
|
||||
readonly Getter _to;
|
||||
readonly ValidationDelegates.Validation _validation;
|
||||
|
||||
readonly IInterpolator<T> _interpolator;
|
||||
|
||||
bool _hasFirstTimeValues;
|
||||
T _firstTimeInitialValue = default!;
|
||||
T _firstTimeFinalValue = default!;
|
||||
|
||||
T _initialValue = default!;
|
||||
T _finalValue = default!;
|
||||
T _currentValue = default!;
|
||||
|
||||
EasingDelegate _easingFunction = PresetEasingDelegateFactory.GetEaseDelegate(Easing.Linear);
|
||||
|
||||
public Tweener(
|
||||
Getter getter,
|
||||
Setter setter,
|
||||
Getter to,
|
||||
float duration,
|
||||
IInterpolator<T> interpolator,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
{
|
||||
_getter = getter;
|
||||
_setter = setter;
|
||||
_to = to;
|
||||
_interpolator = interpolator;
|
||||
_validation = validation;
|
||||
|
||||
Duration = Math.Max(duration, 0.0f);
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
if (IsPlaying)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsPlaying = true;
|
||||
IsCompleted = false;
|
||||
IsKilled = false;
|
||||
|
||||
Elapsed = 0.0f;
|
||||
|
||||
bool valid = Validate();
|
||||
|
||||
if(!valid)
|
||||
{
|
||||
Kill();
|
||||
return;
|
||||
}
|
||||
|
||||
_initialValue = _getter.Invoke();
|
||||
|
||||
GetFirstTimeValues();
|
||||
|
||||
CompleteIfInstant();
|
||||
}
|
||||
|
||||
public void Reset(ResetMode mode)
|
||||
{
|
||||
bool valid = Validate();
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
Kill();
|
||||
return;
|
||||
}
|
||||
|
||||
GetFirstTimeValues();
|
||||
|
||||
IsCompleted = false;
|
||||
IsKilled = false;
|
||||
Elapsed = 0.0f;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
default:
|
||||
case ResetMode.InitialValues:
|
||||
{
|
||||
_setter(_firstTimeInitialValue);
|
||||
_finalValue = _firstTimeFinalValue;
|
||||
}
|
||||
break;
|
||||
|
||||
case ResetMode.IncrementalValues:
|
||||
{
|
||||
T difference = _interpolator.Subtract(_firstTimeInitialValue, _firstTimeFinalValue);
|
||||
_finalValue = _interpolator.Add(_currentValue, difference);
|
||||
}
|
||||
break;
|
||||
|
||||
case ResetMode.PingPong:
|
||||
{
|
||||
_finalValue = _initialValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Tick(float deltaTime)
|
||||
{
|
||||
if (!IsPlaying)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool valid = Validate();
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
Kill();
|
||||
return;
|
||||
}
|
||||
|
||||
Elapsed = Math.Min(Duration, Elapsed + deltaTime);
|
||||
|
||||
if (Elapsed < Duration)
|
||||
{
|
||||
float timeNormalized = MathExtensions.SafeDivide(Elapsed, Duration);
|
||||
|
||||
_currentValue = _interpolator.Evaluate(
|
||||
_initialValue,
|
||||
_finalValue,
|
||||
timeNormalized,
|
||||
_easingFunction
|
||||
);
|
||||
|
||||
_setter(_currentValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public void Complete()
|
||||
{
|
||||
bool valid = Validate();
|
||||
|
||||
if (!valid)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GetFirstTimeValues();
|
||||
|
||||
T newValue = _interpolator.Evaluate(
|
||||
_initialValue,
|
||||
_finalValue,
|
||||
1.0f,
|
||||
_easingFunction
|
||||
);
|
||||
|
||||
_setter(newValue);
|
||||
|
||||
IsPlaying = false;
|
||||
IsCompleted = true;
|
||||
}
|
||||
|
||||
public void Kill()
|
||||
{
|
||||
IsKilled = true;
|
||||
IsPlaying = false;
|
||||
}
|
||||
|
||||
public void SetEasing(EasingDelegate easingFunction)
|
||||
{
|
||||
_easingFunction = easingFunction;
|
||||
}
|
||||
|
||||
void CompleteIfInstant()
|
||||
{
|
||||
if (!IsPlaying)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool isInstant = Duration == 0.0f;
|
||||
|
||||
if (isInstant)
|
||||
{
|
||||
Complete();
|
||||
}
|
||||
}
|
||||
|
||||
bool Validate()
|
||||
{
|
||||
return _validation.Invoke();
|
||||
}
|
||||
|
||||
void GetFirstTimeValues()
|
||||
{
|
||||
if (_hasFirstTimeValues)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_hasFirstTimeValues = true;
|
||||
|
||||
_finalValue = _to.Invoke();
|
||||
|
||||
_firstTimeInitialValue = _initialValue;
|
||||
_firstTimeFinalValue = _finalValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
1
GTweensGodot/GTweens/Source/Tweeners/Tweener.cs.uid
Normal file
1
GTweensGodot/GTweens/Source/Tweeners/Tweener.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cy5dli5pvpgrj
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// using Juce.Tweening.Interpolators;
|
||||
// using UnityEngine;
|
||||
//
|
||||
// namespace Juce.Tweening.Tweeners
|
||||
// {
|
||||
// public class Vector3RotationTweener : Tweener<Vector3>
|
||||
// {
|
||||
// public Vector3RotationTweener(
|
||||
// Getter currValueGetter,
|
||||
// Setter setter,
|
||||
// Getter finalValueGetter,
|
||||
// RotationMode rotationMode,
|
||||
// float duration,
|
||||
// Validation validation
|
||||
// )
|
||||
// : base(
|
||||
// currValueGetter,
|
||||
// setter,
|
||||
// finalValueGetter,
|
||||
// duration,
|
||||
// new SystemVector3RotationInterpolator(rotationMode),
|
||||
// validation
|
||||
// )
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://by4baldnaurb8
|
||||
Loading…
Add table
Add a link
Reference in a new issue