mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-21 23:58:49 -05:00
AtomValueList disabled domain reload compatibility (#420)
* fix: wrong state checked in AtomEvent reset (#403) * fix: make AtomValueList compatible with disabled domain reload (#419) fix: AtomValueList now resets runtime modifications (#418) * fix: handling dead references when resetting objects for AtomValueList. (#417) * removed the dead-reference handling (#417) - this will be addressed in (#421) compacted the Playmode state change
This commit is contained in:
parent
7992efc98d
commit
db3ed28471
@ -62,15 +62,8 @@ namespace UnityAtoms
|
||||
#if UNITY_EDITOR
|
||||
private static void HandlePlayModeStateChange(PlayModeStateChange state)
|
||||
{
|
||||
if (state == PlayModeStateChange.ExitingEditMode)
|
||||
{
|
||||
foreach (var instance in _instances)
|
||||
{
|
||||
instance._replayBuffer.Clear();
|
||||
instance.UnregisterAll();
|
||||
}
|
||||
}
|
||||
else if (state == PlayModeStateChange.EnteredPlayMode)
|
||||
if (state == PlayModeStateChange.ExitingEditMode // BEFORE any GO is initialized:
|
||||
|| state == PlayModeStateChange.EnteredEditMode) // AFTER Playmode stopped
|
||||
{
|
||||
foreach (var instance in _instances)
|
||||
{
|
||||
|
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityAtoms
|
||||
@ -42,6 +44,49 @@ namespace UnityAtoms
|
||||
[SerializeField]
|
||||
protected List<T> list = new List<T>();
|
||||
|
||||
private List<T> _initial;
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
/// <summary>
|
||||
/// Set of all AtomVariable instances in editor.
|
||||
/// </summary>
|
||||
private static HashSet<AtomValueList<T, E>> _instances = new HashSet<AtomValueList<T, E>>();
|
||||
#endif
|
||||
|
||||
protected virtual 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) // BEFORE any GO is initialized:
|
||||
{
|
||||
foreach (var instance in _instances)
|
||||
{
|
||||
if(instance._startCleared) instance.list.Clear();
|
||||
instance._initial = instance.list.ToList();
|
||||
}
|
||||
}
|
||||
else if (state == PlayModeStateChange.EnteredEditMode) // AFTER Playmode stopped
|
||||
{
|
||||
foreach (var instance in _instances)
|
||||
{
|
||||
instance.list = instance._initial;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Add an item to the list.
|
||||
/// </summary>
|
||||
|
@ -192,14 +192,14 @@ namespace UnityAtoms
|
||||
#if UNITY_EDITOR
|
||||
private static void HandlePlayModeStateChange(PlayModeStateChange state)
|
||||
{
|
||||
if (state == PlayModeStateChange.ExitingEditMode)
|
||||
if (state == PlayModeStateChange.ExitingEditMode) // BEFORE any GO is initialized:
|
||||
{
|
||||
foreach (var instance in _instances)
|
||||
{
|
||||
instance.SetInitialValues();
|
||||
}
|
||||
}
|
||||
else if (state == PlayModeStateChange.EnteredPlayMode)
|
||||
else if (state == PlayModeStateChange.EnteredPlayMode) // within/end of the first frame
|
||||
{
|
||||
foreach (var instance in _instances)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user