mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-21 23:58:49 -05:00
fix: event replay buffer persisting if domain reload disabled
This commit is contained in:
parent
994026fb7e
commit
e852be280a
@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityAtoms
|
||||
@ -35,6 +38,47 @@ namespace UnityAtoms
|
||||
|
||||
private Queue<T> _replayBuffer = new Queue<T>();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// Set of all AtomVariable instances in editor.
|
||||
/// </summary>
|
||||
private static HashSet<AtomEvent<T>> _instances = new HashSet<AtomEvent<T>>();
|
||||
#endif
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (EditorSettings.enterPlayModeOptionsEnabled)
|
||||
{
|
||||
_instances.Add(this);
|
||||
|
||||
EditorApplication.playModeStateChanged -= HandlePlayModeStateChange;
|
||||
EditorApplication.playModeStateChanged += HandlePlayModeStateChange;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private static void HandlePlayModeStateChange(PlayModeStateChange state)
|
||||
{
|
||||
if (state == PlayModeStateChange.ExitingEditMode)
|
||||
{
|
||||
foreach (var instance in _instances)
|
||||
{
|
||||
instance._replayBuffer.Clear();
|
||||
}
|
||||
}
|
||||
else if (state == PlayModeStateChange.EnteredPlayMode)
|
||||
{
|
||||
foreach (var instance in _instances)
|
||||
{
|
||||
instance._replayBuffer.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
// Clear all delegates when exiting play mode
|
||||
|
Loading…
Reference in New Issue
Block a user