папочка навёл порядок в папках

This commit is contained in:
vladislove committed 2026-07-20 21:07:50 +03:00
1 parent 9374a984e6
commit b407380203
1123 files changed
+2764 -133233

No files matched your search

@@ -0,0 +1,46 @@
using System.Collections.Generic;
using UnityEngine;
public class SimpleObjectPool : MonoBehaviour
{
public static SimpleObjectPool Instance { get; private set; }
private Dictionary<GameObject, Queue<GameObject>> _pools = new Dictionary<GameObject, Queue<GameObject>>();
void Awake()
{
if (Instance == null) Instance = this;
else Destroy(gameObject);
}
public GameObject Get(GameObject prefab, Vector3 position, Quaternion rotation)
{
if (!_pools.ContainsKey(prefab))
{
_pools.Add(prefab, new Queue<GameObject>());
}
GameObject obj;
if (_pools[prefab].Count > 0)
{
obj = _pools[prefab].Dequeue();
obj.transform.position = position;
obj.transform.rotation = rotation;
obj.SetActive(true);
}
else
{
obj = Instantiate(prefab, position, rotation);
}
return obj;
}
public void ReturnToPool(GameObject prefab, GameObject obj)
{
obj.SetActive(false);
if (_pools.ContainsKey(prefab))
{
_pools[prefab].Enqueue(obj);
}
}
}