-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameObjectPool.cs
37 lines (32 loc) · 930 Bytes
/
GameObjectPool.cs
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
36
37
using System;
using UnityEngine;
namespace ObjectPool
{
[Serializable]
public class GameObjectPool : ObjectPool<GameObject>
{
public static bool IsPooled (GameObject gameObject)
{
return gameObject.GetComponent<PooledGameObjectController> ();
}
public static void ReturnObjectToPool (GameObject usedObject)
{
usedObject.GetComponent<PooledGameObjectController> ().ReturnToPool ();
}
protected override GameObject CreateObjectInstance ()
{
GameObject objectInstance = GameObject.Instantiate (template);
PooledGameObjectController controller = objectInstance.GetComponent<PooledGameObjectController> ();
controller.parentPool = this;
return objectInstance;
}
protected override void ActivateObject (GameObject objectInstance)
{
objectInstance.SetActive (true);
}
protected override void DeactivateObject (GameObject usedObject)
{
usedObject.SetActive (false);
}
}
}