fix: clearing event registrations when changing playmode stage.

This commit is contained in:
Soraphis 2023-07-19 17:38:39 +00:00
parent e852be280a
commit 96eba51be9

View File

@ -67,6 +67,7 @@ namespace UnityAtoms
foreach (var instance in _instances) foreach (var instance in _instances)
{ {
instance._replayBuffer.Clear(); instance._replayBuffer.Clear();
instance.UnregisterAll();
} }
} }
else if (state == PlayModeStateChange.EnteredPlayMode) else if (state == PlayModeStateChange.EnteredPlayMode)
@ -74,6 +75,7 @@ namespace UnityAtoms
foreach (var instance in _instances) foreach (var instance in _instances)
{ {
instance._replayBuffer.Clear(); instance._replayBuffer.Clear();
instance.UnregisterAll();
} }
} }
} }
@ -82,14 +84,7 @@ namespace UnityAtoms
private void OnDisable() private void OnDisable()
{ {
// Clear all delegates when exiting play mode // Clear all delegates when exiting play mode
if (_onEvent != null) UnregisterAll();
{
var invocationList = _onEvent.GetInvocationList();
foreach (var d in invocationList)
{
_onEvent -= (Action<T>)d;
}
}
} }
/// <summary> /// <summary>