-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathObjectPooling.cs
More file actions
35 lines (30 loc) · 1.05 KB
/
Copy pathObjectPooling.cs
File metadata and controls
35 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Collections.Generic;
using UnityEngine;
namespace DATA.Scripts.Core
{
public class ObjectPooling : Singleton<ObjectPooling>
{
readonly Dictionary<GameObject, List<GameObject>> _listObject = new Dictionary<GameObject, List<GameObject>>();
public GameObject GetGameObject(GameObject obj)
{
if (_listObject.ContainsKey(obj))
{
foreach (GameObject go in _listObject[obj])
{
if (go.activeSelf) continue;
return go;
}
GameObject g = Instantiate(obj, this.transform.position, Quaternion.identity);
_listObject[obj].Add(g);
g.SetActive(false);
return g;
}
List<GameObject> list = new List<GameObject>();
GameObject g2 = Instantiate(obj, this.transform.position, Quaternion.identity);
list.Add(g2);
g2.SetActive(false);
_listObject.Add(obj, list);
return g2;
}
}
}