From 5d9b3525d03d640d19164cb54f5ef9e1d6387be5 Mon Sep 17 00:00:00 2001
From: ALEXTANG <574809918@qq.com>
Date: Thu, 4 Aug 2022 10:37:23 +0800
Subject: [PATCH] Update MonoUtility
Update MonoUtility
---
Assets/Scene/TEngine-NetDemo.unity | 2 +-
.../Runtime/ClientSaveMgr/ClientSaveMgr.cs | 21 ++
.../ClientSaveMgr.cs.meta} | 2 +-
.../TEngine/Runtime/Core/CoroutineUtility.cs | 82 -------
Assets/TEngine/Runtime/Core/MonoUtility.cs | 203 ++++++++++++++++++
...ineUtility.cs.meta => MonoUtility.cs.meta} | 2 +-
.../Runtime/HotUpdate/Runtime/LoadMgr.cs | 14 +-
.../HotUpdate/Runtime/LoaderUtilities.cs | 8 +-
Assets/TEngine/Runtime/Mono.meta | 8 -
Assets/TEngine/Runtime/Mono/MonoController.cs | 64 ------
Assets/TEngine/Runtime/Mono/MonoManager.cs | 144 -------------
.../TEngine/Runtime/Mono/MonoManager.cs.meta | 11 -
Assets/TEngine/Runtime/UI/Demo/TEngineTest.cs | 2 +-
Assets/TEngine/Runtime/UI/UIWindowBase.cs | 4 +-
14 files changed, 241 insertions(+), 326 deletions(-)
create mode 100644 Assets/TEngine/Runtime/ClientSaveMgr/ClientSaveMgr.cs
rename Assets/TEngine/Runtime/{Mono/MonoController.cs.meta => ClientSaveMgr/ClientSaveMgr.cs.meta} (83%)
delete mode 100644 Assets/TEngine/Runtime/Core/CoroutineUtility.cs
create mode 100644 Assets/TEngine/Runtime/Core/MonoUtility.cs
rename Assets/TEngine/Runtime/Core/{CoroutineUtility.cs.meta => MonoUtility.cs.meta} (83%)
delete mode 100644 Assets/TEngine/Runtime/Mono.meta
delete mode 100644 Assets/TEngine/Runtime/Mono/MonoController.cs
delete mode 100644 Assets/TEngine/Runtime/Mono/MonoManager.cs
delete mode 100644 Assets/TEngine/Runtime/Mono/MonoManager.cs.meta
diff --git a/Assets/Scene/TEngine-NetDemo.unity b/Assets/Scene/TEngine-NetDemo.unity
index fa9c18fe..69b8e919 100644
--- a/Assets/Scene/TEngine-NetDemo.unity
+++ b/Assets/Scene/TEngine-NetDemo.unity
@@ -161,7 +161,7 @@ MonoBehaviour:
m_GameObject: {fileID: 1143387670}
m_Enabled: 1
m_EditorHideFlags: 0
- m_Script: {fileID: 11500000, guid: 091015446be02ff4eb886963dbe15d74, type: 3}
+ m_Script: {fileID: 11500000, guid: 869b1b77e2356f14a86cbb2646bc4032, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1861967532
diff --git a/Assets/TEngine/Runtime/ClientSaveMgr/ClientSaveMgr.cs b/Assets/TEngine/Runtime/ClientSaveMgr/ClientSaveMgr.cs
new file mode 100644
index 00000000..61efc3c4
--- /dev/null
+++ b/Assets/TEngine/Runtime/ClientSaveMgr/ClientSaveMgr.cs
@@ -0,0 +1,21 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace TEngine
+{
+ public class ClientSaveMgr
+ {
+ // Start is called before the first frame update
+ void Start()
+ {
+
+ }
+
+ // Update is called once per frame
+ void Update()
+ {
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/TEngine/Runtime/Mono/MonoController.cs.meta b/Assets/TEngine/Runtime/ClientSaveMgr/ClientSaveMgr.cs.meta
similarity index 83%
rename from Assets/TEngine/Runtime/Mono/MonoController.cs.meta
rename to Assets/TEngine/Runtime/ClientSaveMgr/ClientSaveMgr.cs.meta
index 1e9e023d..6b3e6307 100644
--- a/Assets/TEngine/Runtime/Mono/MonoController.cs.meta
+++ b/Assets/TEngine/Runtime/ClientSaveMgr/ClientSaveMgr.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: bb1576bb52ae9124f8b4d9f50914200b
+guid: 5f849a863ac1f7546b02342f75753f55
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/TEngine/Runtime/Core/CoroutineUtility.cs b/Assets/TEngine/Runtime/Core/CoroutineUtility.cs
deleted file mode 100644
index 9602869e..00000000
--- a/Assets/TEngine/Runtime/Core/CoroutineUtility.cs
+++ /dev/null
@@ -1,82 +0,0 @@
-using System.Collections;
-using UnityEngine;
-
-namespace TEngine
-{
- public class CoroutineUtility
- {
- private static GameObject _entity;
- private static MonoBehaviour _behaviour;
-
- ///
- /// 开始协程
- ///
- /// 对应的迭代器
- ///
- public static Coroutine StartCoroutine(IEnumerator routine)
- {
- if (routine == null)
- {
- return null;
- }
-
- _MakeEntity();
- return _behaviour.StartCoroutine(routine);
- }
-
- ///
- /// 停止协程
- ///
- ///
- public static void StopCoroutine(Coroutine routine)
- {
- if (routine == null)
- return;
-
- if (_entity != null)
- {
- _behaviour.StopCoroutine(routine);
- routine = null;
- }
- }
-
- ///
- /// 停掉所有的协程
- ///
- public static void StopAllCoroutines()
- {
- if (_entity != null)
- {
- _behaviour.StopAllCoroutines();
- }
- }
-
- private static void _MakeEntity()
- {
- if (_entity != null)
- {
- return;
- }
-
- _entity = new GameObject("__coroutine__")
- {
- hideFlags = HideFlags.HideAndDontSave
- };
- _entity.SetActive(true);
-
-#if UNITY_EDITOR
- if (Application.isPlaying)
-#endif
- {
- Object.DontDestroyOnLoad(_entity);
- }
- UnityEngine.Assertions.Assert.IsFalse(_behaviour);
- _behaviour = _entity.AddComponent();
- }
-
- private class MainBehaviour : MonoBehaviour
- {
-
- }
- }
-}
diff --git a/Assets/TEngine/Runtime/Core/MonoUtility.cs b/Assets/TEngine/Runtime/Core/MonoUtility.cs
new file mode 100644
index 00000000..97939725
--- /dev/null
+++ b/Assets/TEngine/Runtime/Core/MonoUtility.cs
@@ -0,0 +1,203 @@
+using System.Collections;
+using UnityEngine;
+using UnityEngine.Events;
+using UnityEngine.Internal;
+
+namespace TEngine
+{
+ public class MonoUtility
+ {
+ private static GameObject _entity;
+ private static MainBehaviour _behaviour;
+
+ #region 控制协程Coroutine
+ public static Coroutine StartCoroutine(string methodName)
+ {
+ if (string.IsNullOrEmpty(methodName))
+ {
+ return null;
+ }
+ _MakeEntity();
+ return _behaviour.StartCoroutine(methodName);
+ }
+
+ public static Coroutine StartCoroutine(IEnumerator routine)
+ {
+ if (routine == null)
+ {
+ return null;
+ }
+
+ _MakeEntity();
+ return _behaviour.StartCoroutine(routine);
+ }
+
+ public static Coroutine StartCoroutine(string methodName, [DefaultValue("null")] object value)
+ {
+ if (string.IsNullOrEmpty(methodName))
+ {
+ return null;
+ }
+ _MakeEntity();
+ return _behaviour.StartCoroutine(methodName, value);
+ }
+
+ public static void StopCoroutine(string methodName)
+ {
+ if (string.IsNullOrEmpty(methodName))
+ {
+ return;
+ }
+ if (_entity != null)
+ {
+ _behaviour.StopCoroutine(methodName);
+ }
+ }
+
+ public static void StopCoroutine(IEnumerator routine)
+ {
+ if (routine == null)
+ {
+ return;
+ }
+ if (_entity != null)
+ {
+ _behaviour.StopCoroutine(routine);
+ }
+ }
+
+ public static void StopCoroutine(Coroutine routine)
+ {
+ if (routine == null)
+ return;
+
+ if (_entity != null)
+ {
+ _behaviour.StopCoroutine(routine);
+ routine = null;
+ }
+ }
+
+ public static void StopAllCoroutines()
+ {
+ if (_entity != null)
+ {
+ _behaviour.StopAllCoroutines();
+ }
+ }
+ #endregion
+
+ #region 注入UnityUpdate/FixedUpdate
+ ///
+ /// 为给外部提供的 添加帧更新事件
+ ///
+ ///
+ public static void AddUpdateListener(UnityAction fun)
+ {
+ _MakeEntity();
+ _behaviour.AddUpdateListener(fun);
+ }
+
+ ///
+ /// 为给外部提供的 添加物理帧更新事件
+ ///
+ ///
+ public static void AddFixedUpdateListener(UnityAction fun)
+ {
+ _MakeEntity();
+ _behaviour.AddFixedUpdateListener(fun);
+ }
+
+ ///
+ /// 移除帧更新事件
+ ///
+ ///
+ public static void RemoveUpdateListener(UnityAction fun)
+ {
+ _MakeEntity();
+ _behaviour.RemoveUpdateListener(fun);
+ }
+
+ ///
+ /// 移除物理帧更新事件
+ ///
+ ///
+ public static void RemoveFixedUpdateListener(UnityAction fun)
+ {
+ _MakeEntity();
+ _behaviour.RemoveFixedUpdateListener(fun);
+ }
+ #endregion
+
+ private static void _MakeEntity()
+ {
+ if (_entity != null)
+ {
+ return;
+ }
+
+ _entity = new GameObject("__MonoUtility__")
+ {
+ hideFlags = HideFlags.HideAndDontSave
+ };
+ _entity.SetActive(true);
+
+#if UNITY_EDITOR
+ if (Application.isPlaying)
+#endif
+ {
+ Object.DontDestroyOnLoad(_entity);
+ }
+ UnityEngine.Assertions.Assert.IsFalse(_behaviour);
+ _behaviour = _entity.AddComponent();
+ }
+
+ private class MainBehaviour : MonoBehaviour
+ {
+ private event UnityAction updateEvent;
+ private event UnityAction fixedUpdateEvent;
+
+ void Update()
+ {
+ if (updateEvent != null)
+ {
+ updateEvent();
+ }
+ }
+
+ void FixedUpdate()
+ {
+ if (fixedUpdateEvent != null)
+ {
+ fixedUpdateEvent();
+ }
+ }
+
+ public void AddFixedUpdateListener(UnityAction fun)
+ {
+ fixedUpdateEvent += fun;
+ }
+
+ public void RemoveFixedUpdateListener(UnityAction fun)
+ {
+ fixedUpdateEvent -= fun;
+ }
+
+ public void AddUpdateListener(UnityAction fun)
+ {
+ updateEvent += fun;
+ }
+
+ public void RemoveUpdateListener(UnityAction fun)
+ {
+ updateEvent -= fun;
+ }
+
+ public void Release()
+ {
+ updateEvent = null;
+ fixedUpdateEvent = null;
+ }
+ }
+ }
+}
diff --git a/Assets/TEngine/Runtime/Core/CoroutineUtility.cs.meta b/Assets/TEngine/Runtime/Core/MonoUtility.cs.meta
similarity index 83%
rename from Assets/TEngine/Runtime/Core/CoroutineUtility.cs.meta
rename to Assets/TEngine/Runtime/Core/MonoUtility.cs.meta
index 0f4321ff..9248bbd2 100644
--- a/Assets/TEngine/Runtime/Core/CoroutineUtility.cs.meta
+++ b/Assets/TEngine/Runtime/Core/MonoUtility.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 6da5c0d609664a44cb9634c48ad4b269
+guid: a5dd63b85251c414eb28af69e8cfae86
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/TEngine/Runtime/HotUpdate/Runtime/LoadMgr.cs b/Assets/TEngine/Runtime/HotUpdate/Runtime/LoadMgr.cs
index c6c246ad..4b5371e8 100644
--- a/Assets/TEngine/Runtime/HotUpdate/Runtime/LoadMgr.cs
+++ b/Assets/TEngine/Runtime/HotUpdate/Runtime/LoadMgr.cs
@@ -581,20 +581,20 @@ namespace TEngine
if (_coroutine != null)
{
- CoroutineUtility.StopCoroutine(_coroutine);
+ MonoUtility.StopCoroutine(_coroutine);
_coroutine = null;
}
//开始下载
- _coroutine = CoroutineUtility.StartCoroutine(Downloader.DownLoad());
+ _coroutine = MonoUtility.StartCoroutine(Downloader.DownLoad());
LoaderUtilities.DelayFun(() =>
{
if (_load_data_check != null)
{
- CoroutineUtility.StopCoroutine(_load_data_check);
+ MonoUtility.StopCoroutine(_load_data_check);
}
- _load_data_check = CoroutineUtility.StartCoroutine(_StartLoadingCheck());
+ _load_data_check = MonoUtility.StartCoroutine(_StartLoadingCheck());
}, new WaitForSeconds(1));
}
@@ -605,7 +605,7 @@ namespace TEngine
Downloader.StopDownLoad();
if (_coroutine == null) return;
- CoroutineUtility.StopCoroutine(_coroutine);
+ MonoUtility.StopCoroutine(_coroutine);
_coroutine = null;
}
@@ -649,7 +649,7 @@ namespace TEngine
{
if (_load_data_check != null)
{
- CoroutineUtility.StopCoroutine(_load_data_check);
+ MonoUtility.StopCoroutine(_load_data_check);
}
}
//尝试重连
@@ -863,7 +863,7 @@ namespace TEngine
FileunzipManager.Instance.StartFastUnZip(file.All, dir, dir);
- CoroutineUtility.StartCoroutine(UpdateProgress(totalFilesize, status, callback, progress));
+ MonoUtility.StartCoroutine(UpdateProgress(totalFilesize, status, callback, progress));
}
public IEnumerator UpdateProgress(long size, GameStatus status, Action callback, Action progress)
diff --git a/Assets/TEngine/Runtime/HotUpdate/Runtime/LoaderUtilities.cs b/Assets/TEngine/Runtime/HotUpdate/Runtime/LoaderUtilities.cs
index d3e5fbdf..07ed00a8 100644
--- a/Assets/TEngine/Runtime/HotUpdate/Runtime/LoaderUtilities.cs
+++ b/Assets/TEngine/Runtime/HotUpdate/Runtime/LoaderUtilities.cs
@@ -134,9 +134,9 @@ namespace TEngine
if (_coroutine != null)
{
- MonoManager.Instance.StopCoroutine(_coroutine);
+ MonoUtility.StopCoroutine(_coroutine);
}
- _coroutine = MonoManager.Instance.StartCoroutine(_Response(_msgContent));
+ _coroutine = MonoUtility.StartCoroutine(_Response(_msgContent));
}
private static IEnumerator _Response(NetContent content)
@@ -157,7 +157,7 @@ namespace TEngine
if (_coroutine != null)
{
- MonoManager.Instance.StopCoroutine(_coroutine);
+ MonoUtility.StopCoroutine(_coroutine);
_coroutine = null;
}
}
@@ -279,7 +279,7 @@ namespace TEngine
///
public static Coroutine DelayFun(Action callback, YieldInstruction time)
{
- return MonoManager.Instance.StartCoroutine(DelayFunIEnumerator(callback, time));
+ return MonoUtility.StartCoroutine(DelayFunIEnumerator(callback, time));
}
public static IEnumerator DelayFunIEnumerator(Action callback, YieldInstruction time)
diff --git a/Assets/TEngine/Runtime/Mono.meta b/Assets/TEngine/Runtime/Mono.meta
deleted file mode 100644
index 3d29ae5e..00000000
--- a/Assets/TEngine/Runtime/Mono.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 875b1816840638f47ac24cfdf7a47424
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/TEngine/Runtime/Mono/MonoController.cs b/Assets/TEngine/Runtime/Mono/MonoController.cs
deleted file mode 100644
index b35bd80a..00000000
--- a/Assets/TEngine/Runtime/Mono/MonoController.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-using UnityEngine;
-using UnityEngine.Events;
-
-namespace TEngine
-{
- ///
- /// Mono管理者
- ///
- public class MonoController : MonoBehaviour
- {
- private event UnityAction updateEvent;
- private event UnityAction fixedUpdateEvent;
-
- void Update()
- {
- if (updateEvent != null)
- {
- updateEvent();
- }
- }
-
- void FixedUpdate()
- {
- if (fixedUpdateEvent != null)
- {
- fixedUpdateEvent();
- }
- }
-
- public void AddFixedUpdateListener(UnityAction fun)
- {
- fixedUpdateEvent += fun;
- }
-
- public void RemoveFixedUpdateListener(UnityAction fun)
- {
- fixedUpdateEvent -= fun;
- }
-
- ///
- /// 为给外部提供的 添加帧更新事件
- ///
- ///
- public void AddUpdateListener(UnityAction fun)
- {
- updateEvent += fun;
- }
-
- ///
- /// 移除帧更新事件
- ///
- ///
- public void RemoveUpdateListener(UnityAction fun)
- {
- updateEvent -= fun;
- }
-
- public void Release()
- {
- updateEvent = null;
- fixedUpdateEvent = null;
- }
- }
-}
\ No newline at end of file
diff --git a/Assets/TEngine/Runtime/Mono/MonoManager.cs b/Assets/TEngine/Runtime/Mono/MonoManager.cs
deleted file mode 100644
index 00e3c67f..00000000
--- a/Assets/TEngine/Runtime/Mono/MonoManager.cs
+++ /dev/null
@@ -1,144 +0,0 @@
-using System.Collections;
-using System.ComponentModel;
-using TEngine;
-using UnityEngine;
-using UnityEngine.Events;
-
-namespace TEngine
-{
- public class MonoManager : TSingleton
- {
- private MonoController controller;
-
- public override void Release()
- {
- StopAllCoroutine();
- controller.Release();
- controller = null;
- base.Release();
- }
-
- public MonoManager()
- {
- GameObject obj = new GameObject("MonoManager");
-
- controller = obj.AddComponent();
-
-#if UNITY_EDITOR
- GameObject tEngine = SingletonMgr.Root;
- if (tEngine != null)
- {
- obj.transform.SetParent(tEngine.transform);
- }
-#endif
- }
-
- ~MonoManager()
- {
- StopAllCoroutine();
- controller.Release();
- controller = null;
- }
-
- #region 注入UnityUpdate/FixedUpdate
- ///
- /// 为给外部提供的 添加帧更新事件
- ///
- ///
- public void AddUpdateListener(UnityAction fun)
- {
- controller.AddUpdateListener(fun);
- }
-
- ///
- /// 为给外部提供的 添加物理帧更新事件
- ///
- ///
- public void AddFixedUpdateListener(UnityAction fun)
- {
- controller.AddFixedUpdateListener(fun);
- }
-
- ///
- /// 移除帧更新事件
- ///
- ///
- public void RemoveUpdateListener(UnityAction fun)
- {
- controller.RemoveUpdateListener(fun);
- }
- #endregion
-
- #region 控制协程Coroutine
- public Coroutine StartCoroutine(string methodName)
- {
- if (controller == null)
- {
- return null;
- }
- return controller.StartCoroutine(methodName);
- }
-
- public Coroutine StartCoroutine(IEnumerator routine)
- {
- if (controller == null)
- {
- return null;
- }
- return controller.StartCoroutine(routine);
- }
-
- public Coroutine StartCoroutine(string methodName, [DefaultValue("null")] object value)
- {
- if (controller == null)
- {
- return null;
- }
- return controller.StartCoroutine(methodName, value);
- }
-
- public void StopCoroutine(string methodName)
- {
- if (controller == null)
- {
- return;
- }
- controller.StopCoroutine(methodName);
- }
-
- public void StopCoroutine(IEnumerator routine)
- {
- if (controller == null)
- {
- return;
- }
- controller.StopCoroutine(routine);
- }
-
- public void StopCoroutine(Coroutine routine)
- {
- if (controller == null)
- {
- return;
- }
- controller.StopCoroutine(routine);
- }
-
- public void StopAllCoroutine()
- {
- if (controller != null)
- {
- controller.StopAllCoroutines();
- }
- }
- #endregion
-
- #region GC
- public void GC()
- {
- System.GC.Collect();
- }
- #endregion
- }
-
-}
\ No newline at end of file
diff --git a/Assets/TEngine/Runtime/Mono/MonoManager.cs.meta b/Assets/TEngine/Runtime/Mono/MonoManager.cs.meta
deleted file mode 100644
index 4dbc8b93..00000000
--- a/Assets/TEngine/Runtime/Mono/MonoManager.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: 380637ebe1b13894b8bdc779c0a841f7
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/TEngine/Runtime/UI/Demo/TEngineTest.cs b/Assets/TEngine/Runtime/UI/Demo/TEngineTest.cs
index 9841274c..c4e5b9ec 100644
--- a/Assets/TEngine/Runtime/UI/Demo/TEngineTest.cs
+++ b/Assets/TEngine/Runtime/UI/Demo/TEngineTest.cs
@@ -40,7 +40,7 @@ public class ObjMgr : TSingleton
public override void Active()
{
//外部注入Update
- MonoManager.Instance.AddUpdateListener(Update);
+ MonoUtility.AddUpdateListener(Update);
GameEventMgr.Instance.Send(TipsEvent.Log, "WelCome To Use TEngine");
}
diff --git a/Assets/TEngine/Runtime/UI/UIWindowBase.cs b/Assets/TEngine/Runtime/UI/UIWindowBase.cs
index c767cb2f..a315cd55 100644
--- a/Assets/TEngine/Runtime/UI/UIWindowBase.cs
+++ b/Assets/TEngine/Runtime/UI/UIWindowBase.cs
@@ -247,12 +247,12 @@ namespace UI
protected Coroutine StartCoroutine(IEnumerator routine)
{
- return MonoManager.Instance.StartCoroutine(routine);
+ return MonoUtility.StartCoroutine(routine);
}
protected void StopCoroutine(Coroutine cort)
{
- MonoManager.Instance.StopCoroutine(cort);
+ MonoUtility.StopCoroutine(cort);
}
#endregion