feat: safe delegate invocation helper added

This commit is contained in:
2025-04-13 19:08:47 +03:00
parent 00f7b1aaab
commit 58eb373c79
21 changed files with 116 additions and 91 deletions

View File

@@ -26,14 +26,14 @@ internal class Tween : ITween
_state = value;
switch (value)
{
case TweenState.Completed: OnCompleted?.Invoke(this); OnEnded?.Invoke(this); break;
case TweenState.Cancelled: OnCancelled?.Invoke(this); OnEnded?.Invoke(this); break;
case TweenState.Paused: OnPaused?.Invoke(this); break;
case TweenState.Completed: OnCompleted?.InvokeSafe(this); OnEnded?.InvokeSafe(this); break;
case TweenState.Cancelled: OnCancelled?.InvokeSafe(this); OnEnded?.InvokeSafe(this); break;
case TweenState.Paused: OnPaused?.InvokeSafe(this); break;
case TweenState.Playing:
if (previousState == TweenState.Idle)
OnStarted?.Invoke(this);
OnStarted?.InvokeSafe(this);
else
OnResumed?.Invoke(this);
OnResumed?.InvokeSafe(this);
break;
}
}
@@ -58,9 +58,9 @@ internal class Tween : ITween
_counter = value.Min(Duration).Max(0f);
Progress = Counter / Duration;
OnUpdated?.Invoke(this);
OnUpdated?.InvokeSafe(this);
OnDeltaUpdated?.Invoke(this, Easing.Evaluate(Progress) - Easing.Evaluate(previousProgress));
OnDeltaUpdated?.InvokeSafe(this, Easing.Evaluate(Progress) - Easing.Evaluate(previousProgress));
if (_counter >= Duration)
State = TweenState.Completed;

View File

@@ -14,7 +14,7 @@ public class TweenManager : HierarchyObject
public ITween StartTween(float duration, TweenSetCallback? setCallback = null)
{
Tween tween = new(duration);
tween.OnUpdated += tween => setCallback?.Invoke(tween.Value);
tween.OnUpdated += tween => setCallback?.InvokeSafe(tween.Value);
runningCoroutines.Add(tween, coroutineManager.StartCoroutine(RunTween(tween)));
return tween;
}