AlicizaX/Client/Packages/com.alicizax.unity.eventkit/Editor/EventContainerEditorReset.cs

33 lines
884 B
C#
Raw Normal View History

2025-04-28 19:45:45 +08:00
#if UNITY_EDITOR
using UnityEditor;
using System;
using System.Reflection;
namespace AlicizaX.EventKit
{
[InitializeOnLoad]
public static class EventContainerEditorReset
{
static EventContainerEditorReset()
{
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
}
private static void OnPlayModeStateChanged(PlayModeStateChange state)
{
if (state == PlayModeStateChange.ExitingPlayMode)
ResetAllEventContainers();
}
private static void ResetAllEventContainers()
{
foreach (var type in EventContainerRegistry.GetRegisteredTypes())
{
MethodInfo resetMethod = type.GetMethod("Reset", BindingFlags.Public | BindingFlags.Static);
resetMethod?.Invoke(null, null);
}
}
}
}
#endif