using System; using System.Collections.Generic; using AlicizaX; 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 = 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); } /// /// 对象池管理器。 /// public interface IObjectPoolService : IService { int Count { get; } bool HasObjectPool() where T : ObjectBase; bool HasObjectPool(Type objectType); bool HasObjectPool(string name) where T : ObjectBase; bool HasObjectPool(Type objectType, string name); bool HasObjectPool(Predicate condition); IObjectPool GetObjectPool() where T : ObjectBase; ObjectPoolBase GetObjectPool(Type objectType); IObjectPool GetObjectPool(string name) where T : ObjectBase; ObjectPoolBase GetObjectPool(Type objectType, string name); ObjectPoolBase GetObjectPool(Predicate condition); ObjectPoolBase[] GetObjectPools(Predicate condition); void GetObjectPools(Predicate condition, List results); ObjectPoolBase[] GetAllObjectPools(); void GetAllObjectPools(List results); ObjectPoolBase[] GetAllObjectPools(bool sort); void GetAllObjectPools(bool sort, List results); IObjectPool CreatePool(ObjectPoolCreateOptions options = default) where T : ObjectBase; ObjectPoolBase CreatePool(Type objectType, ObjectPoolCreateOptions options = default); bool DestroyObjectPool() where T : ObjectBase; bool DestroyObjectPool(Type objectType); bool DestroyObjectPool(string name) where T : ObjectBase; bool DestroyObjectPool(Type objectType, string name); bool DestroyObjectPool(IObjectPool objectPool) where T : ObjectBase; bool DestroyObjectPool(ObjectPoolBase objectPool); void Release(); void ReleaseAllUnused(); } }