支持编辑器下EnterPlayMode Options

This commit is contained in:
ALEXTANG
2024-05-07 18:05:41 +08:00
parent ae0d00424f
commit 4c0f5a77f9
5 changed files with 51 additions and 2 deletions

View File

@@ -34,6 +34,7 @@ namespace GameLogic
object obj = Activator.CreateInstance(type, mgr.Dispatcher); object obj = Activator.CreateInstance(type, mgr.Dispatcher);
mgr.Init();
mgr.RegWrapInterface(obj.GetType().GetInterfaces()[0]?.FullName, obj); mgr.RegWrapInterface(obj.GetType().GetInterfaces()[0]?.FullName, obj);
} }
} }

View File

@@ -62,13 +62,22 @@ namespace TEngine
entry.InterfaceWrap = callerWrap; entry.InterfaceWrap = callerWrap;
if (typeName != null) if (typeName != null)
{ {
_eventEntryMap.Add(typeName, entry); _eventEntryMap[typeName] = entry;
} }
} }
/// <summary> /// <summary>
/// 分发注册器。 /// 分发注册器。
/// </summary> /// </summary>
public EventDispatcher Dispatcher { get; } = new EventDispatcher(); public EventDispatcher Dispatcher { get; private set; } = new EventDispatcher();
/// <summary>
/// 清除事件。
/// </summary>
public void Init()
{
_eventEntryMap.Clear();
Dispatcher = new EventDispatcher();
}
} }
} }

View File

@@ -585,5 +585,13 @@ namespace TEngine
} }
#endregion #endregion
/// <summary>
/// 清除事件。
/// </summary>
public static void Shutdown()
{
_eventMgr.Init();
}
} }
} }

View File

@@ -1,6 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace TEngine namespace TEngine
{ {
@@ -170,5 +173,32 @@ namespace TEngine
_timer = null; _timer = null;
_resourceExt = null; _resourceExt = null;
} }
#region HandlePlayModeStateChanged
private void OnEnable()
{
#if UNITY_EDITOR
EditorApplication.playModeStateChanged += HandlePlayModeStateChanged;
#endif
}
private void OnDisable()
{
#if UNITY_EDITOR
EditorApplication.playModeStateChanged -= HandlePlayModeStateChanged;
#endif
}
#if UNITY_EDITOR
void HandlePlayModeStateChanged(PlayModeStateChange state)
{
if (state == PlayModeStateChange.ExitingPlayMode)
{
ModuleSystem.Shutdown(ShutdownType.Quit);
}
}
#endif
#endregion
} }
} }

View File

@@ -87,6 +87,7 @@ namespace TEngine
_modules.Clear(); _modules.Clear();
GameModule.Shutdown(shutdownType); GameModule.Shutdown(shutdownType);
GameEvent.Shutdown();
if (shutdownType == ShutdownType.None) if (shutdownType == ShutdownType.None)
{ {