2026-03-31 17:25:20 +08:00
|
|
|
using System;
|
2025-10-11 15:18:09 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using AlicizaX;
|
|
|
|
|
|
|
|
|
|
namespace AlicizaX.ObjectPool
|
|
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
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 = float.MaxValue,
|
|
|
|
|
int capacity = int.MaxValue,
|
|
|
|
|
float expireTime = float.MaxValue,
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-11 15:18:09 +08:00
|
|
|
/// <summary>
|
|
|
|
|
/// 对象池管理器。
|
|
|
|
|
/// </summary>
|
2026-04-20 13:46:44 +08:00
|
|
|
public interface IObjectPoolService : IService
|
2025-10-11 15:18:09 +08:00
|
|
|
{
|
2026-03-31 17:25:20 +08:00
|
|
|
int Count { get; }
|
2025-10-11 15:18:09 +08:00
|
|
|
|
|
|
|
|
bool HasObjectPool<T>() where T : ObjectBase;
|
|
|
|
|
bool HasObjectPool(Type objectType);
|
|
|
|
|
bool HasObjectPool<T>(string name) where T : ObjectBase;
|
|
|
|
|
bool HasObjectPool(Type objectType, string name);
|
|
|
|
|
bool HasObjectPool(Predicate<ObjectPoolBase> condition);
|
|
|
|
|
|
|
|
|
|
IObjectPool<T> GetObjectPool<T>() where T : ObjectBase;
|
|
|
|
|
ObjectPoolBase GetObjectPool(Type objectType);
|
|
|
|
|
IObjectPool<T> GetObjectPool<T>(string name) where T : ObjectBase;
|
|
|
|
|
ObjectPoolBase GetObjectPool(Type objectType, string name);
|
|
|
|
|
ObjectPoolBase GetObjectPool(Predicate<ObjectPoolBase> condition);
|
|
|
|
|
ObjectPoolBase[] GetObjectPools(Predicate<ObjectPoolBase> condition);
|
|
|
|
|
void GetObjectPools(Predicate<ObjectPoolBase> condition, List<ObjectPoolBase> results);
|
|
|
|
|
ObjectPoolBase[] GetAllObjectPools();
|
|
|
|
|
void GetAllObjectPools(List<ObjectPoolBase> results);
|
|
|
|
|
ObjectPoolBase[] GetAllObjectPools(bool sort);
|
|
|
|
|
void GetAllObjectPools(bool sort, List<ObjectPoolBase> results);
|
|
|
|
|
|
2026-03-31 17:25:20 +08:00
|
|
|
IObjectPool<T> CreatePool<T>(ObjectPoolCreateOptions options = default) where T : ObjectBase;
|
|
|
|
|
ObjectPoolBase CreatePool(Type objectType, ObjectPoolCreateOptions options = default);
|
2025-10-11 15:18:09 +08:00
|
|
|
|
|
|
|
|
bool DestroyObjectPool<T>() where T : ObjectBase;
|
|
|
|
|
bool DestroyObjectPool(Type objectType);
|
|
|
|
|
bool DestroyObjectPool<T>(string name) where T : ObjectBase;
|
|
|
|
|
bool DestroyObjectPool(Type objectType, string name);
|
|
|
|
|
bool DestroyObjectPool<T>(IObjectPool<T> objectPool) where T : ObjectBase;
|
|
|
|
|
bool DestroyObjectPool(ObjectPoolBase objectPool);
|
|
|
|
|
|
|
|
|
|
void Release();
|
|
|
|
|
void ReleaseAllUnused();
|
|
|
|
|
}
|
|
|
|
|
}
|