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:
Soraphis 2023-08-03 23:14:26 +02:00 committed by GitHub
parent 7992efc98d
commit db3ed28471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 11 deletions

View File

@ -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)
{

View File

@ -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>

View File

@ -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)
{