Skip to content
Open
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
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace LitMotion.LitMotion.Runtime.Internal
{
internal class EnterThePlayModeHelper
{
#if UNITY_EDITOR
private static readonly List<Action> _scheduledActions = new();

[InitializeOnEnterPlayMode]
private static void Reset()
{
foreach (var action in _scheduledActions)
action();
MotionDispatcher.Clear();
}
#endif

[Conditional("UNITY_EDITOR")]
public static void Register<TValue, TOptions, TAdapter>(MotionStorage<TValue, TOptions, TAdapter> storage)
where TValue : unmanaged
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter<TValue, TOptions>
{
#if UNITY_EDITOR
if (EditorSettings.enterPlayModeOptionsEnabled)
_scheduledActions.Add(storage.Reset);
#endif
}

[Conditional("UNITY_EDITOR")]
public static void Register<TValue, TOptions, TAdapter>(UpdateRunner<TValue, TOptions, TAdapter> runner)
where TValue : unmanaged
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter<TValue, TOptions>
{
#if UNITY_EDITOR
if (EditorSettings.enterPlayModeOptionsEnabled)
_scheduledActions.Add(runner.Reset);
#endif
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,14 @@ static void CheckTypeId(in MotionHandle handle)
throw new ArgumentException("Invalid type id.");
}
}

#if UNITY_EDITOR
[UnityEditor.InitializeOnEnterPlayMode]
private static void Clear()
{
MotionTypeCount = 0;
list.Clear();
}
#endif
}
}
4 changes: 4 additions & 0 deletions src/LitMotion/Assets/LitMotion/Runtime/MotionDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.CompilerServices;
using UnityEngine;
using LitMotion.Collections;
using LitMotion.LitMotion.Runtime.Internal;

#if UNITY_EDITOR
using UnityEditor;
Expand Down Expand Up @@ -51,6 +52,7 @@ static MotionStorage<TValue, TOptions, TAdapter> CreateIfNull(ref MotionStorage<
{
storage = new MotionStorage<TValue, TOptions, TAdapter>(MotionManager.MotionTypeCount);
MotionManager.Register(storage);
EnterThePlayModeHelper.Register(storage);
}
return storage;
}
Expand Down Expand Up @@ -100,6 +102,7 @@ public static (UpdateRunner<TValue, TOptions, TAdapter> runner, bool isCreated)
runner = new UpdateRunner<TValue, TOptions, TAdapter>(storage, Time.timeAsDouble, Time.unscaledTimeAsDouble, Time.realtimeSinceStartupAsDouble);
}
GetRunnerList(playerLoopTiming).Add(runner);
EnterThePlayModeHelper.Register(runner);
return (runner, true);
}
return (runner, false);
Expand Down Expand Up @@ -251,6 +254,7 @@ public static MotionStorage<TValue, TOptions, TAdapter> GetOrCreateStorage()
{
storage = new MotionStorage<TValue, TOptions, TAdapter>(MotionManager.MotionTypeCount);
MotionManager.Register(storage);
EnterThePlayModeHelper.Register(storage);
}
return storage;
}
Expand Down