Rhytm minigame base
This commit is contained in:
1 parent
258900d1d6
commit
329cc98ade
7696 files changed
+238891
-619017
No files matched your search
@@ -0,0 +1,56 @@
|
||||
namespace Code.Infrastructure.Utils
|
||||
{
|
||||
using UnityEngine;
|
||||
using UnityEngine.Pool;
|
||||
|
||||
public class UltraGenericPool<T> where T : Component
|
||||
{
|
||||
public T Prefab;
|
||||
public int DefaultCapacity = 20;
|
||||
public int MaxSize = 100;
|
||||
public bool CollectionCheck = true;
|
||||
|
||||
private IObjectPool<T> _pool;
|
||||
|
||||
public UltraGenericPool()
|
||||
{
|
||||
_pool = new ObjectPool<T>(
|
||||
createFunc: CreateInstance,
|
||||
actionOnGet: OnGetFromPool,
|
||||
actionOnRelease: OnReleaseToPool,
|
||||
actionOnDestroy: OnDestroyPooledObject,
|
||||
collectionCheck: CollectionCheck,
|
||||
defaultCapacity: DefaultCapacity,
|
||||
maxSize: MaxSize
|
||||
);
|
||||
}
|
||||
|
||||
private T CreateInstance()
|
||||
{
|
||||
T instance = Object.Instantiate(Prefab);
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void OnGetFromPool(T instance)
|
||||
{
|
||||
instance.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void OnReleaseToPool(T instance)
|
||||
{
|
||||
instance.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnDestroyPooledObject(T instance)
|
||||
{
|
||||
if (instance != null)
|
||||
{
|
||||
Object.Destroy(instance.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
public T Get() => _pool.Get();
|
||||
public void Release(T element) => _pool.Release(element);
|
||||
public void Clear() => _pool.Clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7296caebfaef4b8cbf63d563bce80536
|
||||
timeCreated: 1794698258
|
||||
Reference in new issue
Block a user