Skip to content

Commit 407de4d

Browse files
committed
added init event
1 parent 8079ffe commit 407de4d

File tree

3 files changed

+43
-28
lines changed

3 files changed

+43
-28
lines changed

.idea/.idea.Unity-Object-Pooling/.idea/workspace.xml

Lines changed: 32 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
namespace CustomTools.ObjectPooling
1+
using System;
2+
3+
namespace CustomTools.ObjectPooling
24
{
35
public interface IObjectPoolInitializable
46
{
57
void Init(object sender, PooledObjectInitializationArgs args);
8+
event EventHandler<PooledObjectInitializationArgs> OnPooledObjectInitializedEvent;
69
}
710
}

Assets/CustomTools/ObjectPooling/Scripts/ObjectPooler.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System.Collections.Generic;
2-
using UnityEngine;
3-
4-
namespace CustomTools.ObjectPooling
1+
namespace CustomTools.ObjectPooling
52
{
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
66
public class ObjectPooler : MonoBehaviour
77
{
88
[SerializeField] private List<PoolObjects> _pool;
@@ -66,11 +66,12 @@ public GameObject SpawnFromPool(PooledObjectType pooledObjectType, Vector3 posit
6666

6767
IObjectPoolInitializable iInitializable = objToSpawn.GetComponent<IObjectPoolInitializable>();
6868

69-
if (args != null)
69+
if (args != null && iInitializable != null)
7070
{
71-
iInitializable?.Init(this, args);
71+
iInitializable.Init(this, args);
7272
}
7373

74+
7475
iPooledObj.OnObjectSpawn();
7576

7677
_poolDictionary[pooledObjectType].Dequeue();

0 commit comments

Comments
 (0)