-
Thanks for creating such an awesome tween library. private LTDescr waitWorker;
public void UpdateState()
{
if (waitWorker != null)
return;
if (agent.velocity.magnitude < MinSpeedToStartRest)
waitWorker = agent.gameObject.LeanDelayedCall(GetRestTime(), ChangeTargetPosition);
} As a temporary solution, I created own class public static class LeanEx
{
public static MotionHandle LeanDelayedCall(this GameObject gameObject, float delay, Action action)
{
return LeanDelayedCall(delay, action)
.AddTo(gameObject);
}
public static MotionHandle LeanDelayedCall(this Component component, float delay, Action action)
{
return LeanDelayedCall(delay, action)
.AddTo(component);
}
public static MotionHandle LeanDelayedCall(float delay, Action action)
{
return LMotion.Create(0f, 1f, delay)
.WithOnComplete(action)
.RunWithoutBinding();
}
} ...and rewrote first code with: private MotionHandle waitWorker;
public void UpdateState()
{
if (waitWorker.IsActive())
return;
if (agent.velocity.magnitude < MinSpeedToStartRest)
waitWorker = agent.LeanDelayedCall(GetRestTime(), ChangeTargetPosition);
} But I'm not sure that it's correct way. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
LitMotion does not have an API equivalent to DelayedCall. This is by design. I don't think DelayedCall is a feature that a tween library should have. The tween library's responsibility is to implement animations using value interpolation and easing, and is not intended for asynchronous processing. Additionally, delayed processing using callbacks is not the preferred method as it makes exception handling and cancellation difficult. These asynchronous operations should be done with async/await (UniTask is probably the best option). However, if your purpose is simply to migrate from LeanTween, I think your method is fine. It should work correctly. |
Beta Was this translation helpful? Give feedback.
-
@annulusgames In case you have any example code snippet how you'd handle delayed calls, would love to see them - but no stress :) |
Beta Was this translation helpful? Give feedback.
LitMotion does not have an API equivalent to DelayedCall. This is by design.
I don't think DelayedCall is a feature that a tween library should have. The tween library's responsibility is to implement animations using value interpolation and easing, and is not intended for asynchronous processing. Additionally, delayed processing using callbacks is not the preferred method as it makes exception handling and cancellation difficult. These asynchronous operations should be done with async/await (UniTask is probably the best option).
However, if your purpose is simply to migrate from LeanTween, I think your method is fine. It should work correctly.