From f5021a96881c3efad450466d9f53d3578592ad3c Mon Sep 17 00:00:00 2001
From: ALEXTANG <574809918@qq.com>
Date: Tue, 31 Oct 2023 12:45:40 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Utility=E7=94=9F=E5=91=BD?=
=?UTF-8?q?=E5=91=A8=E6=9C=9F=E6=B3=A8=E5=85=A5OnDestroy=E5=92=8COnDrawGiz?=
=?UTF-8?q?mos=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
修正Utility生命周期注入OnDestroy和OnDrawGizmos无效的问题
---
.../Runtime/Core/Utility/Utility.Unity.cs | 30 ++++++++++++-------
.../Modules/ModuleCore/ModuleSystem.cs | 2 +-
2 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Unity.cs b/UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Unity.cs
index 9f786eb0..8e6fff75 100644
--- a/UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Unity.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Unity.cs
@@ -225,15 +225,6 @@ namespace TEngine
}
#endregion
- ///
- /// 释放Behaviour生命周期。
- ///
- public static void Release()
- {
- _MakeEntity();
- _behaviour.Release();
- }
-
private static void _MakeEntity()
{
if (_entity != null)
@@ -241,11 +232,12 @@ namespace TEngine
return;
}
- _entity = new GameObject("__MonoUtility__")
+ _entity = new GameObject("[Unity.Utility]")
{
- hideFlags = HideFlags.HideAndDontSave
+ // hideFlags = HideFlags.HideAndDontSave
};
_entity.SetActive(true);
+ _entity.transform.SetParent(GameModule.Base.transform);
#if UNITY_EDITOR
if (Application.isPlaying)
@@ -258,6 +250,22 @@ namespace TEngine
_behaviour = _entity.AddComponent();
}
+ ///
+ /// 释放Behaviour生命周期。
+ ///
+ public static void Shutdown()
+ {
+ if (_behaviour != null)
+ {
+ _behaviour.Release();
+ }
+ if (_entity != null)
+ {
+ Object.Destroy(_entity);
+ }
+ _entity = null;
+ }
+
private class MainBehaviour : MonoBehaviour
{
private event UnityAction UpdateEvent;
diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ModuleCore/ModuleSystem.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ModuleCore/ModuleSystem.cs
index f75596fe..a71dc974 100644
--- a/UnityProject/Assets/TEngine/Runtime/Modules/ModuleCore/ModuleSystem.cs
+++ b/UnityProject/Assets/TEngine/Runtime/Modules/ModuleCore/ModuleSystem.cs
@@ -77,7 +77,7 @@ namespace TEngine
public static void Shutdown(ShutdownType shutdownType)
{
Log.Info("Shutdown Game Framework ({0})...", shutdownType);
- Utility.Unity.Release();
+ Utility.Unity.Shutdown();
RootModule rootModule = GetModule();
if (rootModule != null)
{