Update GameObjectPool.cs

This commit is contained in:
陈思海 2026-03-25 18:41:17 +08:00
parent 4a0465450a
commit c6fe229b4d

View File

@ -9,7 +9,6 @@ using UnityEngine;
namespace AlicizaX namespace AlicizaX
{ {
/// <summary> /// <summary>
/// 对象池配置项。 /// 对象池配置项。
/// </summary> /// </summary>
@ -80,6 +79,10 @@ namespace AlicizaX
public bool isRefCountReduced; public bool isRefCountReduced;
[NonSerialized] public PoolObjectMonitor monitor; [NonSerialized] public PoolObjectMonitor monitor;
public PooledObject()
{
}
public PooledObject(GameObject go, string path) public PooledObject(GameObject go, string path)
{ {
gameObject = go; gameObject = go;
@ -223,6 +226,7 @@ namespace AlicizaX
{ {
availableObjects += queue.Count; availableObjects += queue.Count;
} }
loadedPrefabs = pool.LoadedPrefabs.Count; loadedPrefabs = pool.LoadedPrefabs.Count;
assetPaths.Clear(); assetPaths.Clear();
@ -248,6 +252,7 @@ namespace AlicizaX
objectIndex++; objectIndex++;
} }
} }
ReleasePoolObjectInfos(objectIndex); ReleasePoolObjectInfos(objectIndex);
int prefabIndex = 0; int prefabIndex = 0;
@ -267,6 +272,7 @@ namespace AlicizaX
info.UpdateFromPrefabRefInfo(kvp.Value); info.UpdateFromPrefabRefInfo(kvp.Value);
prefabIndex++; prefabIndex++;
} }
ReleasePrefabRefInfos(prefabIndex); ReleasePrefabRefInfos(prefabIndex);
} }
@ -311,6 +317,7 @@ namespace AlicizaX
public class ConfigPool public class ConfigPool
{ {
public readonly PoolConfig Config; public readonly PoolConfig Config;
// 按资源路径分组的可用对象队列 // 按资源路径分组的可用对象队列
public readonly Dictionary<string, Queue<PooledObject>> AvailableObjectsByPath; public readonly Dictionary<string, Queue<PooledObject>> AvailableObjectsByPath;
public readonly HashSet<PooledObject> AllObjects; public readonly HashSet<PooledObject> AllObjects;
@ -536,6 +543,7 @@ namespace AlicizaX
// 只需要从集合中移除,不需要减少引用计数 // 只需要从集合中移除,不需要减少引用计数
AllObjects.Remove(obj); AllObjects.Remove(obj);
} }
continue; continue;
} }
@ -611,6 +619,7 @@ namespace AlicizaX
queue = new Queue<PooledObject>(); queue = new Queue<PooledObject>();
AvailableObjectsByPath[pooledObj.assetPath] = queue; AvailableObjectsByPath[pooledObj.assetPath] = queue;
} }
queue.Enqueue(pooledObj); queue.Enqueue(pooledObj);
} }
} }
@ -1358,5 +1367,3 @@ namespace AlicizaX
} }
} }
} }