From b839afa76aab92ad7406b0febc97891932993b90 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 26 Oct 2023 00:22:02 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E9=87=8A=E6=94=BE=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E8=B5=84=E6=BA=90=E6=98=AF=E5=90=A6=E6=9C=89?= =?UTF-8?q?=E6=95=88=E3=80=81=E6=94=AF=E6=8C=81YooAssets=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E9=87=8D=E5=AE=9A=E5=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 释放资源判断资源是否有效、支持YooAssets日志重定向 --- .../Modules/ResourceModule/AssetReference.cs | 2 +- .../Modules/ResourceModule/AssetsLogger.cs | 28 ++++++++++++++++++ .../ResourceModule/AssetsLogger.cs.meta | 3 ++ .../Modules/ResourceModule/ResourceManager.cs | 29 +------------------ 4 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/AssetsLogger.cs create mode 100644 UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/AssetsLogger.cs.meta diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/AssetReference.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/AssetReference.cs index f29b0712..44a749d2 100644 --- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/AssetReference.cs +++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/AssetReference.cs @@ -62,7 +62,7 @@ namespace TEngine private void OnDestroy() { - if (_operationHandle != null) + if (_operationHandle is { IsValid: true }) { _operationHandle.Release(); _operationHandle = null; diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/AssetsLogger.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/AssetsLogger.cs new file mode 100644 index 00000000..799b8624 --- /dev/null +++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/AssetsLogger.cs @@ -0,0 +1,28 @@ +namespace TEngine +{ + /// + /// 资源管理日志实现器。 + /// + internal class AssetsLogger : YooAsset.ILogger + { + public void Log(string message) + { + TEngine.Log.Info(message); + } + + public void Warning(string message) + { + TEngine.Log.Warning(message); + } + + public void Error(string message) + { + TEngine.Log.Error(message); + } + + public void Exception(System.Exception exception) + { + TEngine.Log.Fatal(exception.Message); + } + } +} \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/AssetsLogger.cs.meta b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/AssetsLogger.cs.meta new file mode 100644 index 00000000..9126c7ff --- /dev/null +++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/AssetsLogger.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: fb010b07ce0e492dae9f04e18a1af2e2 +timeCreated: 1698250627 \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs index 548a4dc3..f768c5d3 100644 --- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs +++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs @@ -2,7 +2,6 @@ using System.Threading; using Cysharp.Threading.Tasks; using UnityEngine; -using UnityEngine.SceneManagement; using YooAsset; namespace TEngine @@ -369,7 +368,7 @@ namespace TEngine while (iter.MoveNext()) { AssetOperationHandle handle = iter.Current; - if (handle != null) + if (handle is { IsValid: true }) { handle.Dispose(); handle = null; @@ -882,30 +881,4 @@ namespace TEngine return cancelOrFailed ? null : handle.GetSubAssetObjects(); } } - - /// - /// 资源管理日志实现器。 - /// - internal class AssetsLogger : YooAsset.ILogger - { - public void Log(string message) - { - TEngine.Log.Info(message); - } - - public void Warning(string message) - { - TEngine.Log.Warning(message); - } - - public void Error(string message) - { - TEngine.Log.Error(message); - } - - public void Exception(System.Exception exception) - { - TEngine.Log.Fatal(exception.Message); - } - } } \ No newline at end of file From 6ee515e8c5981cc91ab2974a5068b434718435ed Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 26 Oct 2023 10:28:05 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=B1=80=E9=83=A8?= =?UTF-8?q?=E5=8D=95=E4=BD=8D=E4=BA=8B=E4=BB=B6=E5=88=86=E5=8F=91=E5=99=A8?= =?UTF-8?q?=E7=9A=84=E5=B0=81=E8=A3=85=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加局部单位事件分发器的封装。 --- .../Core/GameEvent/ActorEventDispatcher.cs | 614 ++++++++++++++++++ .../GameEvent/ActorEventDispatcher.cs.meta | 3 + 2 files changed, 617 insertions(+) create mode 100644 UnityProject/Assets/TEngine/Runtime/Core/GameEvent/ActorEventDispatcher.cs create mode 100644 UnityProject/Assets/TEngine/Runtime/Core/GameEvent/ActorEventDispatcher.cs.meta diff --git a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/ActorEventDispatcher.cs b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/ActorEventDispatcher.cs new file mode 100644 index 00000000..e446596f --- /dev/null +++ b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/ActorEventDispatcher.cs @@ -0,0 +1,614 @@ +using System; +using System.Collections.Generic; + +#region Class Documentation +/************************************************************************************************************ +Class Name: ActorEventDispatcher.cs 局部单位事件分发器。 +Type: Actor, Event +Example: + private ActorEventDispatcher _event; + + /// + /// 局部事件管理器。 + /// 只分发和监听这个Event内部的事件 + /// + public ActorEventDispatcher Event => _event ??= MemoryPool.Acquire(); + + // owner局部发送事件。 + owner.Event.Send(eventId,xxx); + + // owner监听自身事件并绑定持有对象为owner。 比如是组件的情况下。移除时调用RemoveAllListenerByOwner(owner)会根据持有对象(组件)移除。 + owner.Event.AddEventListener(eventId,xxx,owner); +************************************************************************************************************/ +#endregion + +namespace TEngine +{ + /// + /// 局部单位事件分发器。 + /// + public class ActorEventDispatcher : IMemory + { + /// + /// 所有事件。 + /// + private readonly Dictionary> _allEventListenerMap; + + /// + /// 用于标记一个事件是不是正在处理。 + /// + private readonly List _processEventList; + + /// + /// 用于标记一个事件是不是被移除。 + /// + private readonly List _delayDeleteEventList; + + public ActorEventDispatcher() + { + _processEventList = new List(); + _delayDeleteEventList = new List(); + _allEventListenerMap = new Dictionary>(); + } + + /// + /// 移除所有事件监听。 + /// + public void DestroyAllEventListener() + { + var itr = _allEventListenerMap.GetEnumerator(); + while (itr.MoveNext()) + { + var kv = itr.Current; + kv.Value.Clear(); + } + + _processEventList.Clear(); + _delayDeleteEventList.Clear(); + itr.Dispose(); + } + + /// + /// 延迟移除事件。 + /// + /// + private void AddDelayDelete(int eventId) + { + if (!_delayDeleteEventList.Contains(eventId)) + { + _delayDeleteEventList.Add(eventId); + Log.Info("delay delete eventId[{0}]", eventId); + } + } + + /// + /// 如果找到eventId对应的监听,删除所有标记为delete的监听。 + /// + /// 事件Id。 + private void CheckDelayDelete(int eventId) + { + if (_delayDeleteEventList.Contains(eventId)) + { + if (_allEventListenerMap.TryGetValue(eventId, out var listListener)) + { + for (int i = 0; i < listListener.Count; i++) + { + if (listListener[i].IsDeleted) + { + Log.Info("remove delay delete eventId[{0}]", eventId); + listListener[i] = listListener[^1]; + listListener.RemoveAt(listListener.Count - 1); + i--; + } + } + } + + _delayDeleteEventList.Remove(eventId); + } + } + + /// + /// 发送事件。 + /// + /// 事件Id。 + public void SendEvent(int eventId) + { + if (_allEventListenerMap.TryGetValue(eventId, out var listListener)) + { + _processEventList.Add(eventId); +#if UNITY_EDITOR + int iEventCnt = _processEventList.Count; +#endif + + var count = listListener.Count; + for (int i = 0; i < count; i++) + { + var node = listListener[i]; + if (node.IsDeleted) + { + continue; + } + + if (listListener[i].Callback is Action callBack) + { + callBack(); + } + else + { + Log.Fatal("Invalid event data type: {0}", eventId); + } + } + + +#if UNITY_EDITOR + Log.Assert(iEventCnt == _processEventList.Count); + Log.Assert(eventId == _processEventList[^1]); +#endif + _processEventList.RemoveAt(_processEventList.Count - 1); + + CheckDelayDelete(eventId); + } + } + + /// + /// 发送事件。 + /// + /// 事件Id。 + /// 事件参数。 + /// 事件参数类型1。 + public void SendEvent(int eventId, TArg1 arg1) + { + if (_allEventListenerMap.TryGetValue(eventId, out var listListener)) + { + _processEventList.Add(eventId); +#if UNITY_EDITOR + int iEventCnt = _processEventList.Count; +#endif + + var count = listListener.Count; + for (int i = 0; i < count; i++) + { + var node = listListener[i]; + if (node.IsDeleted) + { + continue; + } + + if (listListener[i].Callback is Action callBack) + { + callBack(arg1); + } + else + { + Log.Fatal("Invalid event data type: {0}", eventId); + } + } + + +#if UNITY_EDITOR + Log.Assert(iEventCnt == _processEventList.Count); + Log.Assert(eventId == _processEventList[^1]); +#endif + + _processEventList.RemoveAt(_processEventList.Count - 1); + + CheckDelayDelete(eventId); + } + } + + /// + /// 发送事件。 + /// + /// 事件Id。 + /// 事件参数1。 + /// 事件参数2。 + /// 事件参数类型1。 + /// 事件参数类型2。 + public void SendEvent(int eventId, TArg1 arg1, TArg2 arg2) + { + if (_allEventListenerMap.TryGetValue(eventId, out var listListener)) + { + _processEventList.Add(eventId); +#if UNITY_EDITOR + int iEventCnt = _processEventList.Count; +#endif + + var count = listListener.Count; + for (int i = 0; i < count; i++) + { + var node = listListener[i]; + if (node.IsDeleted) + { + continue; + } + + if (listListener[i].Callback is Action callBack) + { + callBack(arg1, arg2); + } + else + { + Log.Fatal("Invalid event data type: {0}", eventId); + } + } + + +#if UNITY_EDITOR + Log.Assert(iEventCnt == _processEventList.Count); + Log.Assert(eventId == _processEventList[^1]); +#endif + _processEventList.RemoveAt(_processEventList.Count - 1); + + CheckDelayDelete(eventId); + } + } + + /// + /// 发送事件。 + /// + /// 事件Id。 + /// 事件参数1。 + /// 事件参数2。 + /// 事件参数3。 + /// 事件参数类型1。 + /// 事件参数类型2。 + /// 事件参数类型3。 + public void SendEvent(int eventId, TArg1 arg1, TArg2 arg2, TArg3 arg3) + { + if (_allEventListenerMap.TryGetValue(eventId, out var listListener)) + { + _processEventList.Add(eventId); +#if UNITY_EDITOR + int iEventCnt = _processEventList.Count; +#endif + + var count = listListener.Count; + for (int i = 0; i < count; i++) + { + var node = listListener[i]; + if (node.IsDeleted) + { + continue; + } + + if (node.Callback is Action callBack) + { + callBack(arg1, arg2, arg3); + } + else + { + Log.Fatal("Invalid event data type: {0}", eventId); + } + } + + +#if UNITY_EDITOR + Log.Assert(iEventCnt == _processEventList.Count); + Log.Assert(eventId == _processEventList[^1]); +#endif + _processEventList.RemoveAt(_processEventList.Count - 1); + + CheckDelayDelete(eventId); + } + } + + /// + /// 发送事件。 + /// + /// 事件Id。 + /// 事件参数1。 + /// 事件参数2。 + /// 事件参数3。 + /// 事件参数4。 + /// 事件参数类型1。 + /// 事件参数类型2。 + /// 事件参数类型3。 + /// 事件参数类型4。 + public void SendEvent(int eventId, TArg1 arg1, TArg2 arg2, TArg3 arg3, TArg4 arg4) + { + if (_allEventListenerMap.TryGetValue(eventId, out var listListener)) + { + _processEventList.Add(eventId); +#if UNITY_EDITOR + int iEventCnt = _processEventList.Count; +#endif + + + var count = listListener.Count; + for (int i = 0; i < count; i++) + { + var node = listListener[i]; + if (node.IsDeleted) + { + continue; + } + + if (listListener[i].Callback is Action callBack) + { + callBack(arg1, arg2, arg3, arg4); + } + else + { + Log.Fatal("Invalid event data type: {0}", eventId); + } + } + + +#if UNITY_EDITOR + Log.Assert(iEventCnt == _processEventList.Count); + Log.Assert(eventId == _processEventList[^1]); +#endif + _processEventList.RemoveAt(_processEventList.Count - 1); + + CheckDelayDelete(eventId); + } + } + + /// + /// 增加事件监听。 + /// + /// 事件Id。 + /// 事件回调。 + /// 持有者Tag。 + public void AddEventListener(int eventId, Action eventCallback, object owner) + { + AddEventListenerImp(eventId, eventCallback, owner); + } + + /// + /// 增加事件监听。 + /// + /// 事件Id。 + /// 事件回调。 + /// 持有者Tag。 + /// 事件参数类型1。 + public void AddEventListener(int eventId, Action eventCallback, object owner) + { + AddEventListenerImp(eventId, eventCallback, owner); + } + + /// + /// 增加事件监听。 + /// + /// 事件Id。 + /// 事件回调。 + /// 持有者Tag。 + /// 事件参数类型1。 + /// 事件参数类型2。 + public void AddEventListener(int eventId, Action eventCallback, object owner) + { + AddEventListenerImp(eventId, eventCallback, owner); + } + + /// + /// 增加事件监听。 + /// + /// 事件Id。 + /// 事件回调。 + /// 持有者Tag。 + /// 事件参数类型1。 + /// 事件参数类型2。 + /// 事件参数类型3。 + public void AddEventListener(int eventId, Action eventCallback, object owner) + { + AddEventListenerImp(eventId, eventCallback, owner); + } + + /// + /// 增加事件监听。 + /// + /// 事件Id。 + /// 事件回调。 + /// 持有者Tag。 + /// 事件参数类型1。 + /// 事件参数类型2。 + /// 事件参数类型3。 + /// 事件参数类型4。 + public void AddEventListener(int eventId, Action eventCallback, object owner) + { + AddEventListenerImp(eventId, eventCallback, owner); + } + + /// + /// 增加事件监听具体实现。 + /// + /// 事件Id。 + /// 事件回调。 + /// 持有者Tag。 + private void AddEventListenerImp(int eventId, Delegate listener, object owner) + { + if (!_allEventListenerMap.TryGetValue(eventId, out var listListener)) + { + listListener = new List(); + _allEventListenerMap.Add(eventId, listListener); + } + + var existNode = listListener.Find((node) => node.Callback == listener); + if (existNode != null) + { + if (existNode.IsDeleted) + { + existNode.IsDeleted = false; + Log.Warning("AddEvent hashId deleted, repeat add: {0}", eventId); + return; + } + + Log.Fatal("AddEvent hashId repeated: {0}", eventId); + return; + } + + listListener.Add(new EventRegInfo(listener, owner)); + } + + /// + /// 通过持有者Tag移除监听。 + /// + /// 持有者Tag。 + public void RemoveAllListenerByOwner(object owner) + { + var itr = _allEventListenerMap.GetEnumerator(); + while (itr.MoveNext()) + { + var kv = itr.Current; + var list = kv.Value; + + int eventId = kv.Key; + bool isProcessing = _processEventList.Contains(eventId); + bool delayDeleted = false; + + for (int i = 0; i < list.Count; i++) + { + var regInfo = list[i]; + if (regInfo.Owner == owner) + { + if (isProcessing) + { + regInfo.IsDeleted = true; + delayDeleted = true; + } + else + { + list[i] = list[^1]; + list.RemoveAt(list.Count - 1); + i--; + } + } + } + + if (delayDeleted) + { + AddDelayDelete(eventId); + } + } + + itr.Dispose(); + } + + /// + /// 移除事件监听。 + /// + /// 事件Id。 + /// 消息回调。 + public void RemoveEventListener(int eventId, Action eventCallback) + { + RemoveEventListenerImp(eventId, eventCallback); + } + + /// + /// 移除事件监听。 + /// + /// 事件Id。 + /// 消息回调。 + /// 参数类型1。 + public void RemoveEventListener(int eventId, Action eventCallback) + { + RemoveEventListenerImp(eventId, eventCallback); + } + + /// + /// 移除事件监听。 + /// + /// 事件Id。 + /// 消息回调。 + /// 参数类型1。 + /// 参数类型2。 + public void RemoveEventListener(int eventId, Action eventCallback) + { + RemoveEventListenerImp(eventId, eventCallback); + } + + /// + /// 移除事件监听。 + /// + /// 事件Id。 + /// 消息回调。 + /// 参数类型1。 + /// 参数类型2。 + /// 参数类型3。 + public void RemoveEventListener(int eventId, Action eventCallback) + { + RemoveEventListenerImp(eventId, eventCallback); + } + + /// + /// 移除事件监听。 + /// + /// 事件Id。 + /// 消息回调。 + /// 参数类型1。 + /// 参数类型2。 + /// 参数类型3。 + /// 参数类型4。 + public void RemoveEventListener(int eventId, Action eventCallback) + { + RemoveEventListenerImp(eventId, eventCallback); + } + + /// + /// 删除监听,如果是正在处理的监听则标记为删除 + /// + /// 事件Id。 + /// 事件监听。 + protected void RemoveEventListenerImp(int eventId, Delegate listener) + { + if (_allEventListenerMap.TryGetValue(eventId, out var listListener)) + { + bool isProcessing = _processEventList.Contains(eventId); + if (!isProcessing) + { + listListener.RemoveAll(node => node.Callback == listener); + } + else + { + int listenCnt = listListener.Count; + for (int i = 0; i < listenCnt; i++) + { + var node = listListener[i]; + if (node.Callback == listener) + { + node.IsDeleted = true; + AddDelayDelete(eventId); + break; + } + } + } + } + } + + /// + /// 清除回收接口。 + /// + public void Clear() + { + DestroyAllEventListener(); + } + } + + /// + /// 事件注册信息。 + /// + public class EventRegInfo + { + /// + /// 事件回调。 + /// + public readonly Delegate Callback; + + /// + /// 事件持有者。 + /// + public readonly object Owner; + + /// + /// 事件是否删除。 + /// + public bool IsDeleted; + + public EventRegInfo(Delegate callback, object owner) + { + this.Callback = callback; + Owner = owner; + IsDeleted = false; + } + } +} \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/ActorEventDispatcher.cs.meta b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/ActorEventDispatcher.cs.meta new file mode 100644 index 00000000..13ce0f62 --- /dev/null +++ b/UnityProject/Assets/TEngine/Runtime/Core/GameEvent/ActorEventDispatcher.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 222c2a26f3b14d42950d0e9a10b61b38 +timeCreated: 1673511406 \ No newline at end of file From 6ed32082e1c4dacfef92730e1c333beb4b6f3080 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 26 Oct 2023 11:43:32 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E4=BF=AE=E6=AD=A3HttpDispose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正HttpDispose --- .../Assets/TEngine/Runtime/Core/Utility/Utility.Http.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Http.cs b/UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Http.cs index 635af55b..eee6fa49 100644 --- a/UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Http.cs +++ b/UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Http.cs @@ -91,6 +91,8 @@ namespace TEngine if (isCanceled) { Log.Warning($"HttpPost {unityWebRequest.url} be canceled!"); + unityWebRequest.Dispose(); + cts.Dispose(); } } catch (OperationCanceledException ex) @@ -98,11 +100,16 @@ namespace TEngine if (ex.CancellationToken == cts.Token) { Log.Warning("HttpPost Timeout"); + unityWebRequest.Dispose(); + cts.Dispose(); return string.Empty; } } - return unityWebRequest.downloadHandler.text; + string ret = unityWebRequest.downloadHandler.text; + unityWebRequest.Dispose(); + cts.Dispose(); + return ret; } } } From 94788685137e97b746559f3cd932f3be3a6de44d Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 26 Oct 2023 12:28:06 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E4=BF=AE=E6=AD=A3HttpDispose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正HttpDispose --- UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Http.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Http.cs b/UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Http.cs index eee6fa49..2f6c0410 100644 --- a/UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Http.cs +++ b/UnityProject/Assets/TEngine/Runtime/Core/Utility/Utility.Http.cs @@ -93,6 +93,7 @@ namespace TEngine Log.Warning($"HttpPost {unityWebRequest.url} be canceled!"); unityWebRequest.Dispose(); cts.Dispose(); + return string.Empty; } } catch (OperationCanceledException ex) From 6992d12c6cd7b4358e526ef00ff545f542be446e Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 26 Oct 2023 13:12:35 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=B8=BB=E5=8A=A8GetItemByIndex=E5=92=8CGetI?= =?UTF-8?q?temList=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复循环列表主动GetItemByIndex和GetItemList的问题 --- .../GameLogic/Common/UI/Widget/UIListBase.cs | 2 +- .../Common/UI/Widget/UILoopGridWidget.cs | 15 ++- .../Common/UI/Widget/UILoopListViewWidget.cs | 11 +- .../Common/UI/Widget/UILoopListWidget.cs | 19 ++- .../DataStruct/GameFrameworkDictionary.cs | 120 ++++++++++++++++++ .../GameFrameworkDictionary.cs.meta | 3 + 6 files changed, 159 insertions(+), 11 deletions(-) create mode 100644 UnityProject/Assets/TEngine/Runtime/Core/DataStruct/GameFrameworkDictionary.cs create mode 100644 UnityProject/Assets/TEngine/Runtime/Core/DataStruct/GameFrameworkDictionary.cs.meta diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListBase.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListBase.cs index c3ca2042..8a9773a5 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListBase.cs +++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UIListBase.cs @@ -277,7 +277,7 @@ namespace GameLogic item.SetSelected(false); } - item = GetItem(m_selectIndex) as IListSelectItem; + item = GetItem(selectIndex) as IListSelectItem; if (item != null) { item.SetSelected(true); diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopGridWidget.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopGridWidget.cs index 423b9de7..381dd406 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopGridWidget.cs +++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopGridWidget.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using TEngine; using UnityEngine; namespace GameLogic @@ -17,7 +18,7 @@ namespace GameLogic /// /// Item字典 /// - private Dictionary m_itemCache = new Dictionary(); + private GameFrameworkDictionary m_itemCache = new GameFrameworkDictionary(); /// /// 计算偏差后的ItemList @@ -163,9 +164,19 @@ namespace GameLogic m_items.Clear(); for (int i = 0; i < m_itemCache.Count; i++) { - m_items.Add(m_itemCache[i]); + m_items.Add(m_itemCache.GetValueByIndex(i)); } return m_items; } + + /// + /// 获取Item。 + /// + /// 索引。 + /// TItem。 + public TItem GetItemByIndex(int index) + { + return m_itemCache.GetValueByIndex(index); + } } } diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopListViewWidget.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopListViewWidget.cs index e2c1f3ae..c20af44d 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopListViewWidget.cs +++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopListViewWidget.cs @@ -8,7 +8,7 @@ namespace GameLogic { public LoopListView LoopRectView { private set; get; } - private Dictionary m_itemCache = new Dictionary(); + private GameFrameworkDictionary m_itemCache = new GameFrameworkDictionary(); public override void BindMemberProperty() { @@ -71,9 +71,8 @@ namespace GameLogic List list = new List(); for (int i = 0; i < m_itemCache.Count; i++) { - list.Add(m_itemCache[i]); + list.Add(m_itemCache.GetValueByIndex(i)); } - return list; } @@ -85,11 +84,11 @@ namespace GameLogic /// /// 获取Item。 /// - /// - /// + /// 索引。 + /// TItem。 public T GetItemByIndex(int index) { - return m_itemCache[index]; + return m_itemCache.GetValueByIndex(index); } } } \ No newline at end of file diff --git a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopListWidget.cs b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopListWidget.cs index a3e29c34..db7bea3e 100644 --- a/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopListWidget.cs +++ b/UnityProject/Assets/GameScripts/HotFix/GameLogic/Common/UI/Widget/UILoopListWidget.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using TEngine; using UnityEngine; namespace GameLogic @@ -16,8 +17,9 @@ namespace GameLogic /// /// Item字典 + /// Key => GameObjectHashCode | Value => TItem. /// - private Dictionary m_itemCache = new Dictionary(); + private GameFrameworkDictionary m_itemCache = new GameFrameworkDictionary(); /// /// 计算偏差后的ItemList @@ -159,7 +161,10 @@ namespace GameLogic public List GetItemList() { m_items.Clear(); - m_items.AddRange(m_itemCache.Values); + for (int i = 0; i < m_itemCache.Count; i++) + { + m_items.Add(m_itemCache.GetValueByIndex(i)); + } return m_items; } @@ -171,5 +176,15 @@ namespace GameLogic { return LoopRectView.GetItemStartIndex(); } + + /// + /// 获取Item。 + /// + /// 索引。 + /// TItem。 + public TItem GetItemByIndex(int index) + { + return m_itemCache.GetValueByIndex(index); + } } } diff --git a/UnityProject/Assets/TEngine/Runtime/Core/DataStruct/GameFrameworkDictionary.cs b/UnityProject/Assets/TEngine/Runtime/Core/DataStruct/GameFrameworkDictionary.cs new file mode 100644 index 00000000..cb5e8a03 --- /dev/null +++ b/UnityProject/Assets/TEngine/Runtime/Core/DataStruct/GameFrameworkDictionary.cs @@ -0,0 +1,120 @@ +using System.Collections.Generic; + +namespace TEngine +{ + /// + /// 游戏框架字典类。 + /// + /// 指定字典Key的元素类型。 + /// 指定字典Value的元素类型。 + public class GameFrameworkDictionary + { + protected readonly List KeyList = new List(); + protected readonly Dictionary Dictionary = new Dictionary(); + + /// + /// 存储键的列表。 + /// + public List Keys => KeyList; + + /// + /// 存储字典实例。 + /// + public int Count => KeyList.Count; + + /// + /// 通过KEY的数组下标获取元素。 + /// + /// 下标。 + /// TValue。 + public TValue GetValueByIndex(int index) + { + return Dictionary[KeyList[index]]; + } + + /// + /// 通过KEY的数组下标设置元素。 + /// + /// 下标。 + /// TValue。 + public void SetValue(int index, TValue item) + { + Dictionary[KeyList[index]] = item; + } + + /// + /// 字典索引器。 + /// + /// TKey。 + public TValue this[TKey key] + { + get => Dictionary[key]; + set + { + if (!ContainsKey(key)) + { + Add(key, value); + } + else + { + Dictionary[key] = value; + } + } + } + + /// Removes all keys and values from the . + public void Clear() + { + KeyList.Clear(); + Dictionary.Clear(); + } + + /// Adds the specified key and value to the dictionary. + /// The key of the element to add. + /// The value of the element to add. The value can be for reference types. + public virtual void Add(TKey key, TValue item) + { + KeyList.Add(key); + Dictionary.Add(key, item); + } + + /// Gets the value associated with the specified key. + /// The key of the value to get. + /// When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the parameter. This parameter is passed uninitialized. + public bool TryGetValue(TKey key, out TValue value) + { + return Dictionary.TryGetValue(key, out value); + } + + /// Determines whether the contains the specified key. + /// The key to locate in the + public bool ContainsKey(TKey key) + { + return Dictionary.ContainsKey(key); + } + + public TKey GetKey(int index) + { + return KeyList[index]; + } + + public bool Remove(TKey key) + { + return KeyList.Remove(key) && Dictionary.Remove(key); + } + } + + /// + /// 游戏框架顺序字典类。 + /// + /// 指定字典Key的元素类型。 + /// 指定字典Value的元素类型。 + public class GameFrameworkSortedDictionary : GameFrameworkDictionary + { + public override void Add(TKey key, TValue item) + { + base.Add(key, item); + KeyList.Sort(); + } + } +} \ No newline at end of file diff --git a/UnityProject/Assets/TEngine/Runtime/Core/DataStruct/GameFrameworkDictionary.cs.meta b/UnityProject/Assets/TEngine/Runtime/Core/DataStruct/GameFrameworkDictionary.cs.meta new file mode 100644 index 00000000..74d41812 --- /dev/null +++ b/UnityProject/Assets/TEngine/Runtime/Core/DataStruct/GameFrameworkDictionary.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3df785fede30420dbfa6acb2ff48c166 +timeCreated: 1698296076 \ No newline at end of file From cfaf82a6232b569c0a3f46f57c991088983695bb Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 26 Oct 2023 14:07:38 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E9=87=8A=E6=94=BE=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E8=B5=84=E6=BA=90=E6=98=AF=E5=90=A6=E6=9C=89?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 释放资源判断资源是否有效 --- .../Runtime/Modules/ResourceModule/ResourceManager.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs index f768c5d3..45a28b50 100644 --- a/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs +++ b/UnityProject/Assets/TEngine/Runtime/Modules/ResourceModule/ResourceManager.cs @@ -101,7 +101,6 @@ namespace TEngine internal override void Shutdown() { - ReleaseAllHandle(); #if !UNITY_WEBGL YooAssets.Destroy(); #endif @@ -114,13 +113,12 @@ namespace TEngine while (iter.MoveNext()) { AssetOperationHandle handle = iter.Current; - if (handle != null) + if (handle is { IsValid: true }) { handle.Dispose(); handle = null; } } - iter.Dispose(); _releaseMaps.Clear(); @@ -128,15 +126,15 @@ namespace TEngine while (iter.MoveNext()) { AssetOperationHandle handle = iter.Current; - if (handle != null) + if (handle is { IsValid: true }) { handle.Dispose(); handle = null; } } - iter.Dispose(); _operationHandlesMaps.Clear(); + _arcCacheTable = new ArcCacheTable(ARCTableCapacity, OnAddAsset, OnRemoveAsset); } From b1c7f30be91ec2166e283321e7468dbfe1e70e79 Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Thu, 26 Oct 2023 23:45:26 +0800 Subject: [PATCH 07/12] =?UTF-8?q?ErrorLogger=E5=B1=8F=E5=B9=95=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=BC=80=E5=90=AF=E4=B8=8EDebugModule=E5=85=B3?= =?UTF-8?q?=E8=81=94=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ErrorLogger屏幕显示开启与DebugModule关联。 --- .../Modules/DebugerModule/DebuggerModule.cs | 2 ++ .../UIModule/ErrorLogger/ErrorLogger.cs | 7 +++--- .../Runtime/Modules/UIModule/UIModule.cs | 24 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/DebugerModule/DebuggerModule.cs b/UnityProject/Assets/TEngine/Runtime/Modules/DebugerModule/DebuggerModule.cs index a088c414..b9a727f6 100644 --- a/UnityProject/Assets/TEngine/Runtime/Modules/DebugerModule/DebuggerModule.cs +++ b/UnityProject/Assets/TEngine/Runtime/Modules/DebugerModule/DebuggerModule.cs @@ -38,6 +38,8 @@ namespace TEngine [SerializeField] private DebuggerActiveWindowType m_ActiveWindow = DebuggerActiveWindowType.AlwaysOpen; + public DebuggerActiveWindowType ActiveWindowType => m_ActiveWindow; + [SerializeField] private bool m_ShowFullWindow = false; diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/UIModule/ErrorLogger/ErrorLogger.cs b/UnityProject/Assets/TEngine/Runtime/Modules/UIModule/ErrorLogger/ErrorLogger.cs index 508acb2d..0f79fa7d 100644 --- a/UnityProject/Assets/TEngine/Runtime/Modules/UIModule/ErrorLogger/ErrorLogger.cs +++ b/UnityProject/Assets/TEngine/Runtime/Modules/UIModule/ErrorLogger/ErrorLogger.cs @@ -1,15 +1,16 @@ -using UnityEngine; +using System; +using UnityEngine; namespace TEngine { - public class ErrorLogger + public class ErrorLogger:IDisposable { public ErrorLogger() { Application.logMessageReceived += LogHandler; } - ~ErrorLogger() + public void Dispose() { Application.logMessageReceived -= LogHandler; } diff --git a/UnityProject/Assets/TEngine/Runtime/Modules/UIModule/UIModule.cs b/UnityProject/Assets/TEngine/Runtime/Modules/UIModule/UIModule.cs index ca04cfaf..5f9c0fcd 100644 --- a/UnityProject/Assets/TEngine/Runtime/Modules/UIModule/UIModule.cs +++ b/UnityProject/Assets/TEngine/Runtime/Modules/UIModule/UIModule.cs @@ -68,6 +68,25 @@ namespace TEngine m_InstanceRoot.gameObject.layer = LayerMask.NameToLayer("UI"); UIRootStatic = m_InstanceRoot; + + switch (GameModule.Debugger.ActiveWindowType) + { + case DebuggerActiveWindowType.AlwaysOpen: + m_enableErrorLog = true; + break; + + case DebuggerActiveWindowType.OnlyOpenWhenDevelopment: + m_enableErrorLog = Debug.isDebugBuild; + break; + + case DebuggerActiveWindowType.OnlyOpenInEditor: + m_enableErrorLog = Application.isEditor; + break; + + default: + m_enableErrorLog = false; + break; + } if (m_enableErrorLog) { _errorLogger = new ErrorLogger(); @@ -76,6 +95,11 @@ namespace TEngine private void OnDestroy() { + if (_errorLogger != null) + { + _errorLogger.Dispose(); + _errorLogger = null; + } CloseAll(); } From 7401edac15536d09b1fe2ed41288f8b1583052ad Mon Sep 17 00:00:00 2001 From: ALEXTANG <574809918@qq.com> Date: Fri, 27 Oct 2023 00:13:04 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E7=A7=BB=E9=99=A4UIElement=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=91=E5=AE=9A=E5=B7=A5=E5=85=B7=EF=BC=8C=E4=B8=BA?= =?UTF-8?q?=E5=90=8E=E7=BB=ADAutoBind=E4=BB=A3=E7=A0=81=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E5=81=9A=E5=87=86=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除UIElement代码绑定工具,为后续AutoBind代码绑定工具做准备 --- .../Resources/AssetLoad/UILoadTip.prefab | 26 --- .../Resources/AssetLoad/UILoadUpdate.prefab | 28 --- .../Main/Launcher/Scripts/UI/UILoadTip.cs | 14 +- .../Main/Launcher/Scripts/UI/UILoadUpdate.cs | 16 +- .../TEngine/Editor/UI/UIElementEditor.cs | 179 ------------------ .../TEngine/Editor/UI/UIElementEditor.cs.meta | 3 - .../Runtime/Modules/UIModule/UIBase.cs | 49 ----- .../Runtime/Modules/UIModule/UIElement.cs | 50 ----- .../Modules/UIModule/UIElement.cs.meta | 3 - 9 files changed, 13 insertions(+), 355 deletions(-) delete mode 100644 UnityProject/Assets/TEngine/Editor/UI/UIElementEditor.cs delete mode 100644 UnityProject/Assets/TEngine/Editor/UI/UIElementEditor.cs.meta delete mode 100644 UnityProject/Assets/TEngine/Runtime/Modules/UIModule/UIElement.cs delete mode 100644 UnityProject/Assets/TEngine/Runtime/Modules/UIModule/UIElement.cs.meta diff --git a/UnityProject/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadTip.prefab b/UnityProject/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadTip.prefab index a13dd843..8f20b9ba 100644 --- a/UnityProject/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadTip.prefab +++ b/UnityProject/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadTip.prefab @@ -812,7 +812,6 @@ GameObject: - component: {fileID: 4070374929253206932} - component: {fileID: 4872533144352319846} - component: {fileID: 3352775805385032060} - - component: {fileID: 3859027068210555860} m_Layer: 5 m_Name: UILoadTip m_TagString: Untagged @@ -880,31 +879,6 @@ MonoBehaviour: m_BlockingMask: serializedVersion: 2 m_Bits: 55 ---- !u!114 &3859027068210555860 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7666412045263395013} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: bcd11033283847ee8f7c71eedd9a4771, type: 3} - m_Name: - m_EditorClassIdentifier: - elements: - m_keys: - - m_btnUpdate - - m_btnIgnore - - m_textInfo - - m_textTittle - - m_btnPackage - m_values: - - {fileID: 2745714441875214452} - - {fileID: 467775921333773033} - - {fileID: 3862717357071106210} - - {fileID: 9127528276671758327} - - {fileID: 1387175525974173601} --- !u!1 &8012535748721374403 GameObject: m_ObjectHideFlags: 0 diff --git a/UnityProject/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadUpdate.prefab b/UnityProject/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadUpdate.prefab index 0a9ac199..75dd2abf 100644 --- a/UnityProject/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadUpdate.prefab +++ b/UnityProject/Assets/GameScripts/Main/Launcher/Resources/AssetLoad/UILoadUpdate.prefab @@ -773,7 +773,6 @@ GameObject: - component: {fileID: 1633508802563447727} - component: {fileID: 5827342734203288403} - component: {fileID: 4835021223508371640} - - component: {fileID: 903919243524269039} m_Layer: 5 m_Name: UILoadUpdate m_TagString: Untagged @@ -843,33 +842,6 @@ MonoBehaviour: m_BlockingMask: serializedVersion: 2 m_Bits: 55 ---- !u!114 &903919243524269039 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 9130266365217219149} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: bcd11033283847ee8f7c71eedd9a4771, type: 3} - m_Name: - m_EditorClassIdentifier: - elements: - m_keys: - - m_imgBackGround - - m_scrollbarProgress - - m_textDesc - - m_btnClear - - m_textAppid - - m_textResid - m_values: - - {fileID: 4652061626151979521} - - {fileID: 2347891492826839465} - - {fileID: 8666815445422661327} - - {fileID: 4232232858152633415} - - {fileID: 3038352660368000718} - - {fileID: 8143980099109665604} --- !u!1 &9157096376857424144 GameObject: m_ObjectHideFlags: 0 diff --git a/UnityProject/Assets/GameScripts/Main/Launcher/Scripts/UI/UILoadTip.cs b/UnityProject/Assets/GameScripts/Main/Launcher/Scripts/UI/UILoadTip.cs index 28df109c..a5249dc8 100644 --- a/UnityProject/Assets/GameScripts/Main/Launcher/Scripts/UI/UILoadTip.cs +++ b/UnityProject/Assets/GameScripts/Main/Launcher/Scripts/UI/UILoadTip.cs @@ -20,26 +20,22 @@ namespace GameMain public MessageShowType ShowType = MessageShowType.None; #region 脚本工具生成的代码 - private Button m_btnPackage; private Text m_textTittle; private Text m_textInfo; private Button m_btnIgnore; private Button m_btnUpdate; - public override void ScriptGenerator() { - CheckUIElement(); - m_btnPackage = FChild