1
This commit is contained in:
@@ -22,6 +22,7 @@ namespace BITKit
|
||||
public Action<T> OnGet { get; set; } = x=>x.gameObject.SetActive(true);
|
||||
public Action<T> OnReturn { get; set; } = x=>x.gameObject.SetActive(false);
|
||||
public Action<T> OnDestroy { get; set; } = x=>Object.Destroy(x.gameObject);
|
||||
public Action<T> OnSpawn { get; set; }
|
||||
private ObjectPool<T> pool=> _pool ??=
|
||||
new ObjectPool<T>
|
||||
(Spawn, OnGet, OnReturn, OnDestroy,defaultCapacity:DefaultCapacity, maxSize:DefaultCapacity);
|
||||
@@ -71,10 +72,21 @@ namespace BITKit
|
||||
|
||||
public void Return(T element)
|
||||
{
|
||||
pool.Release(element);
|
||||
_list.Remove(element);
|
||||
try
|
||||
{
|
||||
pool.Release(element);
|
||||
}
|
||||
catch (InvalidOperationException){}
|
||||
|
||||
_list.TryRemove(element);
|
||||
}
|
||||
private T Spawn() => Object.Instantiate(prefab, root);
|
||||
private T Spawn()
|
||||
{
|
||||
var newObject = Object.Instantiate(prefab, root);
|
||||
OnSpawn?.Invoke(newObject);
|
||||
return newObject;
|
||||
}
|
||||
|
||||
#region 拓展
|
||||
|
||||
private readonly ConcurrentDictionary<string, T> _dictionary=new();
|
||||
|
Reference in New Issue
Block a user