This commit is contained in:
2025-12-14 01:45:02 +01:00
parent 60d509344c
commit f03e13236f
30 changed files with 260 additions and 2480 deletions

View File

@@ -128,31 +128,6 @@ namespace KCM.StateManagement.Observers
if (this.state == null)
return;
// Unity uses "fake null" for destroyed objects. Since our state is stored as object,
// we must explicitly detect that case to avoid exceptions + log spam.
try
{
UnityEngine.Object unityObj = this.state as UnityEngine.Object;
if (this.state is UnityEngine.Object && unityObj == null)
{
try { StateObserver.observers.Remove(this.state.GetHashCode()); } catch { }
try
{
if (observerObject != null)
UnityEngine.Object.Destroy(observerObject);
else
UnityEngine.Object.Destroy(this.gameObject);
}
catch
{
}
return;
}
}
catch
{
}
if (!(currentMs - lastUpdate > updateInterval)) // Don't run if the update interval hasn't passed (default 100 milliseconds);
return;

View File

@@ -12,24 +12,6 @@ namespace KCM.StateManagement.Observers
{
public static Dictionary<int, IObserver> observers = new Dictionary<int, IObserver>();
public static void ClearAll()
{
foreach (var observer in observers.Values)
{
try
{
var component = observer as Component;
if (component != null)
UnityEngine.Object.Destroy(component.gameObject);
}
catch
{
}
}
observers.Clear();
}
public static void RegisterObserver<T>(T instance, string[] monitoredFields, EventHandler<StateUpdateEventArgs> eventHandler = null, EventHandler<StateUpdateEventArgs> sendUpdateHandler = null)
{
if (observers.ContainsKey(instance.GetHashCode()))