diff --git a/Assets/TEngine/Scripts/Editor/Inspector/ObjectPoolManagerInspector.cs b/Assets/TEngine/Scripts/Editor/Inspector/ObjectPoolManagerInspector.cs index d20f512b..22d3e05d 100644 --- a/Assets/TEngine/Scripts/Editor/Inspector/ObjectPoolManagerInspector.cs +++ b/Assets/TEngine/Scripts/Editor/Inspector/ObjectPoolManagerInspector.cs @@ -4,7 +4,7 @@ using UnityEngine; namespace TEngine.Editor { - [CustomEditor(typeof(ObjectPoolManager))] + [CustomEditor(typeof(GameObjectPoolManager))] internal sealed class ObjectPoolManagerInspector : TEngineInspector { public override void OnInspectorGUI() @@ -15,14 +15,14 @@ namespace TEngine.Editor return; } - if (ObjectPoolManager.Instance.Helper.ObjectPools.Count == 0) + if (GameObjectPoolManager.Instance.Helper.ObjectPools.Count == 0) { GUILayout.BeginHorizontal(); GUILayout.Label("No Runtime Data!"); GUILayout.EndHorizontal(); } - foreach (var pool in ObjectPoolManager.Instance.Helper.ObjectPools) + foreach (var pool in GameObjectPoolManager.Instance.Helper.ObjectPools) { GUILayout.BeginHorizontal(); GUILayout.Space(20); diff --git a/Assets/TEngine/Scripts/Runtime/Core/Constant/Constant.Setting.cs b/Assets/TEngine/Scripts/Runtime/Core/Constant/Constant.Setting.cs index b4dc2e6a..74429257 100644 --- a/Assets/TEngine/Scripts/Runtime/Core/Constant/Constant.Setting.cs +++ b/Assets/TEngine/Scripts/Runtime/Core/Constant/Constant.Setting.cs @@ -2,6 +2,11 @@ namespace TEngine { public static partial class Constant { + /// + /// 默认优先级。 + /// + internal const int DefaultPriority = 0; + public static class Setting { public const string HotFixedDllName = "GameHotFixed"; diff --git a/Assets/TEngine/Scripts/Runtime/ObjectPool.meta b/Assets/TEngine/Scripts/Runtime/ObjectPool.meta deleted file mode 100644 index 1ad3cbea..00000000 --- a/Assets/TEngine/Scripts/Runtime/ObjectPool.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 18905312db3bc3d448630110b4a9bcd3 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper.meta b/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper.meta deleted file mode 100644 index cc235d82..00000000 --- a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: eaa7867dbaa447e42b63eb98f3dd8687 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/DefaultObjectPoolHelper.cs b/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/DefaultObjectPoolHelper.cs deleted file mode 100644 index 9b8a1c94..00000000 --- a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/DefaultObjectPoolHelper.cs +++ /dev/null @@ -1,221 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace TEngine.Runtime -{ - /// - /// 默认的对象池管理器助手 - /// - public sealed class DefaultObjectPoolHelper : IObjectPoolHelper - { - /// - /// 对象池默认上限 - /// - private int _limit; - - /// - /// 所有对象池 - /// - public Dictionary ObjectPools { get; private set; } = - new Dictionary(); - - /// - /// 初始化助手 - /// - public DefaultObjectPoolHelper() - { - _limit = ObjectPoolManager.Instance.Limit; - } - - /// - /// ShutDown - /// - public void ShutDown() - { - ClearAll(); - } - - /// - /// 注册对象池 - /// - /// 对象池名称 - /// 对象模板 - /// 对象生成时初始化委托 - /// 对象回收时处理委托 - /// 对象池上限,等于0时,表示使用默认值 - public void RegisterPool(string name, GameObject allocItem, Action onAlloc, - Action onRelease, int limit) - { - if (allocItem == null) - return; - - if (!ObjectPools.ContainsKey(name)) - { - ObjectPools.Add(name, new ObjectPool(allocItem, limit <= 0 ? _limit : limit, onAlloc, onRelease)); - } - else - { - Log.Error($"RegisterPool Failed ,Reason :已存在对象池 {name}"); - } - } - - /// - /// 是否存在指定名称的对象池 - /// - /// 对象池名称 - /// 是否存在 - public bool IsExistPool(string name) - { - return ObjectPools.ContainsKey(name); - } - - /// - /// 移除已注册的对象池 - /// - /// 对象池名称 - public void UnRegisterPool(string name) - { - if (ObjectPools.ContainsKey(name)) - { - ObjectPools[name].Clear(); - ObjectPools.Remove(name); - } - else - { - Log.Error("UnRegisterPool ObjectPool Failed:不存在对象池 " + name + " !"); - } - } - - /// - /// 获取对象池中对象数量 - /// - /// 对象池名称 - /// 对象数量 - public int GetPoolCount(string name) - { - if (ObjectPools.ContainsKey(name)) - { - return ObjectPools[name].Count; - } - else - { - Log.Warning("GetPoolCount ObjectPool Failed:不存在对象池 " + name + " !"); - return 0; - } - } - - /// - /// 生成对象 - /// - /// 对象池名称 - /// 对象 - public GameObject Alloc(string name) - { - if (ObjectPools.ContainsKey(name)) - { - return ObjectPools[name].Alloc(); - } - else - { - Log.Error("Alloc ObjectPool Failed:不存在对象池 " + name + " !"); - return null; - } - } - - /// - /// 回收对象 - /// - /// 对象池名称 - /// 对象 - public void Release(string name, GameObject target) - { - if (target == null) - return; - - if (ObjectPools.ContainsKey(name)) - { - ObjectPools[name].Release(target); - } - else - { - Log.Error("Releases ObjectPool Failed:不存在对象池 " + name + " !"); - } - } - - /// - /// 批量回收对象 - /// - /// 对象池名称 - /// 对象数组 - public void Releases(string name, GameObject[] targets) - { - if (targets == null) - return; - - if (ObjectPools.ContainsKey(name)) - { - for (int i = 0; i < targets.Length; i++) - { - ObjectPools[name].Release(targets[i]); - } - } - else - { - Log.Error("Releases ObjectPool Failed:不存在对象池 " + name + " !"); - } - } - - /// - /// 批量回收对象 - /// - /// 对象池名称 - /// 对象集合 - public void Releases(string name, List targets) - { - if (targets == null) - return; - - if (ObjectPools.ContainsKey(name)) - { - for (int i = 0; i < targets.Count; i++) - { - ObjectPools[name].Release(targets[i]); - } - - targets.Clear(); - } - else - { - Log.Error("Releases ObjectPool Failed:不存在对象池 " + name + " !"); - } - } - - /// - /// 清空指定的对象池 - /// - /// 对象池名称 - public void Clear(string name) - { - if (ObjectPools.ContainsKey(name)) - { - ObjectPools[name].Clear(); - } - else - { - Log.Error("Clear ObjectPool Failed:不存在对象池 " + name + " !"); - } - } - - /// - /// 清空所有对象池 - /// - public void ClearAll() - { - foreach (var pool in ObjectPools) - { - pool.Value.Clear(); - } - } - } -} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/DefaultObjectPoolHelper.cs.meta b/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/DefaultObjectPoolHelper.cs.meta deleted file mode 100644 index 646e2226..00000000 --- a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/DefaultObjectPoolHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7f19a0d9040fd24439a22aa1b33b1752 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {fileID: 2800000, guid: 701b9bfeb6deef341a599f8d0f1ec080, type: 3} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/IObjectPoolHelper.cs b/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/IObjectPoolHelper.cs deleted file mode 100644 index 84d3abd3..00000000 --- a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/IObjectPoolHelper.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace TEngine.Runtime -{ - /// - /// 对象池管理器的助手接口 - /// - public interface IObjectPoolHelper - { - /// - /// 所有对象池 - /// - Dictionary ObjectPools { get; } - - /// - /// 注册对象池 - /// - /// 对象池名称 - /// 对象模板 - /// 对象生成时初始化委托 - /// 对象回收时处理委托 - /// 对象池上限,等于0时,表示使用默认值 - void RegisterPool(string name, GameObject allocItem, Action onAlloc, - Action onRelease, int limit); - - /// - /// 是否存在指定名称的对象池 - /// - /// 对象池名称 - /// 是否存在 - bool IsExistPool(string name); - - /// - /// 移除已注册的对象池 - /// - /// 对象池名称 - void UnRegisterPool(string name); - - /// - /// 获取对象池中对象数量 - /// - /// 对象池名称 - /// 对象数量 - int GetPoolCount(string name); - - /// - /// 生成对象 - /// - /// 对象池名称 - /// 对象 - GameObject Alloc(string name); - - /// - /// 回收对象 - /// - /// 对象池名称 - /// 对象 - void Release(string name, GameObject target); - - /// - /// 批量回收对象 - /// - /// 对象池名称 - /// 对象数组 - void Releases(string name, GameObject[] targets); - - /// - /// 批量回收对象 - /// - /// 对象池名称 - /// 对象集合 - void Releases(string name, List targets); - - /// - /// 清空指定的对象池 - /// - /// 对象池名称 - void Clear(string name); - - /// - /// 清空所有对象池 - /// - void ClearAll(); - } -} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/IObjectPoolHelper.cs.meta b/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/IObjectPoolHelper.cs.meta deleted file mode 100644 index 5c62b232..00000000 --- a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/IObjectPoolHelper.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9f0af4beea5247d40a447b27c807de3a -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {fileID: 2800000, guid: 701b9bfeb6deef341a599f8d0f1ec080, type: 3} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/ObjectPool.cs b/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/ObjectPool.cs deleted file mode 100644 index 3a9a41f1..00000000 --- a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/ObjectPool.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace TEngine.Runtime -{ - /// - /// 对象池 - /// - public sealed class ObjectPool - { - private readonly GameObject _allocItem; - private readonly int _limit = 100; - private readonly Queue _objectQueue = new Queue(); - private readonly Action _onAlloc; - private readonly Action _onRelease; - - /// - /// 对象数量 - /// - public int Count - { - get { return _objectQueue.Count; } - } - - /// - /// 构造函数对象池 - /// - /// - /// - /// - /// - public ObjectPool(GameObject allocItem, int limit, Action onAlloc, - Action onRelease) - { - _allocItem = allocItem; - _limit = limit; - _onAlloc = onAlloc; - _onRelease = onRelease; - } - - /// - /// 生成对象 - /// - /// 对象 - public GameObject Alloc() - { - GameObject obj; - if (_objectQueue.Count > 0) - { - obj = _objectQueue.Dequeue(); - } - else - { - obj = Utility.GameObjectUtils.CloneGameObject(_allocItem); - } - - obj.SetActive(true); - - obj.transform.SetParent(null); - - _onAlloc?.Invoke(obj); - - return obj; - } - - /// - /// 回收对象 - /// - /// 对象 - public void Release(GameObject obj) - { - if (_objectQueue.Count >= _limit) - { - _onRelease?.Invoke(obj); - - Utility.GameObjectUtils.Kill(obj); - } - else - { - obj.SetActive(false); - - _onRelease?.Invoke(obj); - - _objectQueue.Enqueue(obj); - - obj.transform.SetParent(ObjectPoolManager.Instance.gameObject.transform); - } - } - - /// - /// 清空所有对象 - /// - public void Clear() - { - while (_objectQueue.Count > 0) - { - GameObject obj = _objectQueue.Dequeue(); - if (obj) - { - Utility.GameObjectUtils.Kill(obj); - } - } - } - } -} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/ObjectPool.cs.meta b/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/ObjectPool.cs.meta deleted file mode 100644 index d1d11628..00000000 --- a/Assets/TEngine/Scripts/Runtime/ObjectPool/Helper/ObjectPool.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 27382aff833de094e97dd246ad567aad -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {fileID: 2800000, guid: 701b9bfeb6deef341a599f8d0f1ec080, type: 3} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/TEngine/Scripts/Runtime/ObjectPool/ObjectPoolManager.cs b/Assets/TEngine/Scripts/Runtime/ObjectPool/ObjectPoolManager.cs deleted file mode 100644 index e2843c3f..00000000 --- a/Assets/TEngine/Scripts/Runtime/ObjectPool/ObjectPoolManager.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; - -namespace TEngine.Runtime -{ - /// - /// 对象池管理器 - /// - public sealed class ObjectPoolManager : UnitySingleton - { - private IObjectPoolHelper _helper; - - public IObjectPoolHelper Helper => _helper; - - public override int Priority => -1; - - public override void Awake() - { - base.Awake(); - _helper = new DefaultObjectPoolHelper(); - } - - /// - /// 单个对象池上限 - /// - [SerializeField] internal int Limit = 100; - - /// - /// 注册对象池 - /// - /// 对象池名称 - /// 对象模板 - /// 对象生成时初始化委托 - /// 对象回收时处理委托 - /// 对象池上限,等于0时,表示使用默认值 - public void RegisterPool(string name, GameObject allocItem, Action onAlloc = null, - Action onRelease = null, int limit = 0) - { - _helper.RegisterPool(name, allocItem, onAlloc, onRelease, limit); - } - - /// - /// 是否存在指定名称的对象池 - /// - /// 对象池名称 - /// 是否存在 - public bool IsExistPool(string name) - { - return _helper.IsExistPool(name); - } - - /// - /// 移除已注册的对象池 - /// - /// 对象池名称 - public void UnRegisterPool(string name) - { - _helper.UnRegisterPool(name); - } - - /// - /// 获取对象池中对象数量 - /// - /// 对象池名称 - /// 对象数量 - public int GetPoolCount(string name) - { - return _helper.GetPoolCount(name); - } - - /// - /// 生成对象 - /// - /// 对象池名称 - /// 对象 - public GameObject Alloc(string name) - { - return _helper.Alloc(name); - } - - /// - /// 回收对象 - /// - /// 对象池名称 - /// 对象 - public void Release(string name, GameObject target) - { - _helper.Release(name, target); - } - - /// - /// 批量回收对象 - /// - /// 对象池名称 - /// 对象数组 - public void Releases(string name, GameObject[] targets) - { - _helper.Releases(name, targets); - } - - /// - /// 批量回收对象 - /// - /// 对象池名称 - /// 对象集合 - public void Releases(string name, List targets) - { - _helper.Releases(name, targets); - } - - /// - /// 清空指定的对象池 - /// - /// 对象池名称 - public void Clear(string name) - { - _helper.Clear(name); - } - - /// - /// 清空所有对象池 - /// - public void ClearAll() - { - _helper.ClearAll(); - } - } -} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/ObjectPool/ObjectPoolManager.cs.meta b/Assets/TEngine/Scripts/Runtime/ObjectPool/ObjectPoolManager.cs.meta deleted file mode 100644 index fccde163..00000000 --- a/Assets/TEngine/Scripts/Runtime/ObjectPool/ObjectPoolManager.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: bef095b963a40b54fa82ba105bd1e98e -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: