com.alicizax.unity.framework/Runtime/ABase/ObjectPool/IObjectPoolService.cs
陈思海 e42be670fe 彻底重构ObjectPoolService模块
重构ObjectPoolService模块
去掉过度设计移除旧的容器列表
使用自定义Hash提高整体性能速度
单线程高吞吐
2026-04-22 13:04:31 +08:00

75 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
namespace AlicizaX.ObjectPool
{
public readonly struct ObjectPoolCreateOptions
{
public readonly string Name;
public readonly bool AllowMultiSpawn;
public readonly float? AutoReleaseInterval;
public readonly int? Capacity;
public readonly float? ExpireTime;
public readonly int Priority;
public ObjectPoolCreateOptions(
string name = "",
bool allowMultiSpawn = false,
float? autoReleaseInterval = null,
int? capacity = null,
float? expireTime = null,
int priority = 0)
{
Name = name ?? string.Empty;
AllowMultiSpawn = allowMultiSpawn;
AutoReleaseInterval = autoReleaseInterval;
Capacity = capacity;
ExpireTime = expireTime;
Priority = priority;
}
public ObjectPoolCreateOptions WithName(string name)
=> new ObjectPoolCreateOptions(name, AllowMultiSpawn, AutoReleaseInterval, Capacity, ExpireTime, Priority);
public static ObjectPoolCreateOptions Single(string name = "")
=> new ObjectPoolCreateOptions(name: name);
public static ObjectPoolCreateOptions Multi(string name = "")
=> new ObjectPoolCreateOptions(name: name, allowMultiSpawn: true);
}
public interface IObjectPoolService : IService
{
int Count { get; }
bool HasObjectPool<T>() where T : ObjectBase;
bool HasObjectPool<T>(string name) where T : ObjectBase;
bool HasObjectPool(Type objectType);
bool HasObjectPool(Type objectType, string name);
IObjectPool<T> GetObjectPool<T>() where T : ObjectBase;
IObjectPool<T> GetObjectPool<T>(string name) where T : ObjectBase;
ObjectPoolBase GetObjectPool(Type objectType);
ObjectPoolBase GetObjectPool(Type objectType, string name);
ObjectPoolBase[] GetAllObjectPools();
ObjectPoolBase[] GetAllObjectPools(bool sort);
void GetAllObjectPools(List<ObjectPoolBase> results);
void GetAllObjectPools(bool sort, List<ObjectPoolBase> results);
IObjectPool<T> CreatePool<T>(ObjectPoolCreateOptions options = default) where T : ObjectBase;
ObjectPoolBase CreatePool(Type objectType, ObjectPoolCreateOptions options = default);
bool DestroyObjectPool<T>() where T : ObjectBase;
bool DestroyObjectPool<T>(string name) where T : ObjectBase;
bool DestroyObjectPool(Type objectType);
bool DestroyObjectPool(Type objectType, string name);
bool DestroyObjectPool<T>(IObjectPool<T> objectPool) where T : ObjectBase;
bool DestroyObjectPool(ObjectPoolBase objectPool);
void Release();
void ReleaseAllUnused();
}
}