сростил проекты

This commit is contained in:
vladislove committed 2026-07-19 19:37:17 +03:00
1 parent a4573f2d12
commit dfd44aa129
684 files changed
+152796 -67

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);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bb56a90f04ee457fbd31022c77a40db6
timeCreated: 1783605341