Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: MotionScheduler.DefaultScheduler #108

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,14 @@ static string GetTimeKindName(MotionTimeKind motionTimeKind)
}
if (scheduler == null)
{
#if UNITY_EDITOR
if (isCreatedOnEditor)
{
scheduler = MotionScheduler.Update;
scheduler = MotionScheduler.DefaultScheduler;
}
else
{
scheduler = EditorMotionScheduler.Update;
}
#else
scheduler = MotionScheduler.Update;
#endif
}

return scheduler switch
Expand All @@ -153,7 +149,7 @@ protected override TreeViewItem BuildRoot()
foreach (var tracking in MotionTracker.Items)
{
children.Add(new MotionTrackerViewItem(id)
{
{
MotionType = $"[{tracking.ValueType.Name}, {tracking.OptionsType.Name}, {tracking.AdapterType.Name}]",
SchedulerType = GetSchedulerName(tracking.Scheduler, tracking.CreatedOnEditor),
Elapsed = (DateTime.UtcNow - tracking.CreationTime).TotalSeconds.ToString("00.00"),
Expand Down
10 changes: 2 additions & 8 deletions src/LitMotion/Assets/LitMotion/Runtime/MotionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,19 +312,14 @@ internal readonly MotionHandle Schedule(IMotionScheduler scheduler, ref MotionDa
#if UNITY_EDITOR
if (!UnityEditor.EditorApplication.isPlaying)
{
// Inlined EditorUpdateMotionScheduler
handle = EditorMotionDispatcher.Schedule<TValue, TOptions, TAdapter>(data, callbackData);
}
else
{
// Inlined PlayerLoopMotionScheduler
data.TimeKind = MotionTimeKind.Time;
handle = MotionDispatcher.Schedule<TValue, TOptions, TAdapter>(data, callbackData, PlayerLoopTiming.Update);
handle = MotionScheduler.DefaultScheduler.Schedule<TValue, TOptions, TAdapter>(ref data, ref callbackData);
}
#else
// Inlined PlayerLoopMotionScheduler
data.TimeKind = MotionTimeKind.Time;
handle = MotionDispatcher.Schedule<TValue, TOptions, TAdapter>(data, callbackData, PlayerLoopTiming.Update);
handle = MotionScheduler.DefaultScheduler.Schedule<TValue, TOptions, TAdapter>(ref data, ref callbackData);
#endif
}
else
Expand Down Expand Up @@ -383,7 +378,6 @@ internal MotionCallbackData BuildCallbackData()
return callbacks;
}


[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal MotionCallbackData BuildCallbackData(Action<TValue> action)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ namespace LitMotion
/// </summary>
public static class MotionScheduler
{
static MotionScheduler()
{
DefaultScheduler = Update;
}

/// <summary>
/// Default scheduler used if not specified
/// </summary>
public static IMotionScheduler DefaultScheduler { get; set; }

/// <summary>
/// Scheduler that updates motion at Initialization.
/// </summary>
Expand Down