mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
Update MonoUtility
Update MonoUtility
This commit is contained in:
@@ -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
|
||||
|
21
Assets/TEngine/Runtime/ClientSaveMgr/ClientSaveMgr.cs
Normal file
21
Assets/TEngine/Runtime/ClientSaveMgr/ClientSaveMgr.cs
Normal file
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb1576bb52ae9124f8b4d9f50914200b
|
||||
guid: 5f849a863ac1f7546b02342f75753f55
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -1,82 +0,0 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public class CoroutineUtility
|
||||
{
|
||||
private static GameObject _entity;
|
||||
private static MonoBehaviour _behaviour;
|
||||
|
||||
/// <summary>
|
||||
/// 开始协程
|
||||
/// </summary>
|
||||
/// <param name="routine">对应的迭代器</param>
|
||||
/// <returns></returns>
|
||||
public static Coroutine StartCoroutine(IEnumerator routine)
|
||||
{
|
||||
if (routine == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_MakeEntity();
|
||||
return _behaviour.StartCoroutine(routine);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停止协程
|
||||
/// </summary>
|
||||
/// <param name="routine"></param>
|
||||
public static void StopCoroutine(Coroutine routine)
|
||||
{
|
||||
if (routine == null)
|
||||
return;
|
||||
|
||||
if (_entity != null)
|
||||
{
|
||||
_behaviour.StopCoroutine(routine);
|
||||
routine = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 停掉所有的协程
|
||||
/// </summary>
|
||||
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<MainBehaviour>();
|
||||
}
|
||||
|
||||
private class MainBehaviour : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
203
Assets/TEngine/Runtime/Core/MonoUtility.cs
Normal file
203
Assets/TEngine/Runtime/Core/MonoUtility.cs
Normal file
@@ -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
|
||||
/// <summary>
|
||||
/// 为给外部提供的 添加帧更新事件
|
||||
/// </summary>
|
||||
/// <param name="fun"></param>
|
||||
public static void AddUpdateListener(UnityAction fun)
|
||||
{
|
||||
_MakeEntity();
|
||||
_behaviour.AddUpdateListener(fun);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为给外部提供的 添加物理帧更新事件
|
||||
/// </summary>
|
||||
/// <param name="fun"></param>
|
||||
public static void AddFixedUpdateListener(UnityAction fun)
|
||||
{
|
||||
_MakeEntity();
|
||||
_behaviour.AddFixedUpdateListener(fun);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除帧更新事件
|
||||
/// </summary>
|
||||
/// <param name="fun"></param>
|
||||
public static void RemoveUpdateListener(UnityAction fun)
|
||||
{
|
||||
_MakeEntity();
|
||||
_behaviour.RemoveUpdateListener(fun);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除物理帧更新事件
|
||||
/// </summary>
|
||||
/// <param name="fun"></param>
|
||||
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<MainBehaviour>();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6da5c0d609664a44cb9634c48ad4b269
|
||||
guid: a5dd63b85251c414eb28af69e8cfae86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -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<bool, GameStatus> callback, Action<long, long> progress)
|
||||
|
@@ -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
|
||||
/// <param name="time"></param>
|
||||
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)
|
||||
|
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 875b1816840638f47ac24cfdf7a47424
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -1,64 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
/// <summary>
|
||||
/// Mono管理者
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为给外部提供的 添加帧更新事件
|
||||
/// </summary>
|
||||
/// <param name="fun"></param>
|
||||
public void AddUpdateListener(UnityAction fun)
|
||||
{
|
||||
updateEvent += fun;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除帧更新事件
|
||||
/// </summary>
|
||||
/// <param name="fun"></param>
|
||||
public void RemoveUpdateListener(UnityAction fun)
|
||||
{
|
||||
updateEvent -= fun;
|
||||
}
|
||||
|
||||
public void Release()
|
||||
{
|
||||
updateEvent = null;
|
||||
fixedUpdateEvent = null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,144 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.ComponentModel;
|
||||
using TEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public class MonoManager : TSingleton<MonoManager>
|
||||
{
|
||||
private MonoController controller;
|
||||
|
||||
public override void Release()
|
||||
{
|
||||
StopAllCoroutine();
|
||||
controller.Release();
|
||||
controller = null;
|
||||
base.Release();
|
||||
}
|
||||
|
||||
public MonoManager()
|
||||
{
|
||||
GameObject obj = new GameObject("MonoManager");
|
||||
|
||||
controller = obj.AddComponent<MonoController>();
|
||||
|
||||
#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
|
||||
/// <summary>
|
||||
/// 为给外部提供的 添加帧更新事件
|
||||
/// </summary>
|
||||
/// <param name="fun"></param>
|
||||
public void AddUpdateListener(UnityAction fun)
|
||||
{
|
||||
controller.AddUpdateListener(fun);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为给外部提供的 添加物理帧更新事件
|
||||
/// </summary>
|
||||
/// <param name="fun"></param>
|
||||
public void AddFixedUpdateListener(UnityAction fun)
|
||||
{
|
||||
controller.AddFixedUpdateListener(fun);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除帧更新事件
|
||||
/// </summary>
|
||||
/// <param name="fun"></param>
|
||||
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
|
||||
}
|
||||
|
||||
}
|
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 380637ebe1b13894b8bdc779c0a841f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -40,7 +40,7 @@ public class ObjMgr : TSingleton<ObjMgr>
|
||||
public override void Active()
|
||||
{
|
||||
//外部注入Update
|
||||
MonoManager.Instance.AddUpdateListener(Update);
|
||||
MonoUtility.AddUpdateListener(Update);
|
||||
|
||||
GameEventMgr.Instance.Send<string>(TipsEvent.Log, "WelCome To Use TEngine");
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user