protected override GameObject NewObject() { GameObject obj = GameObject.Instantiate(Original); obj.name = Original.name + " # " + (ActiveInstances.Count + InactiveInstances.Count); GameObjectPoolReference reference = obj.AddComponent <GameObjectPoolReference>(); reference.PrefabID = Original.GetHashCode(); NotifyOnConstruct(obj); return(obj); }
private static int GetPrefabId(GameObject gameObject) { int objectId = gameObject.GetHashCode(); GameObjectPoolReference poolReferenceComp = gameObject.GetComponent <GameObjectPoolReference>(); if (poolReferenceComp != null) { objectId = poolReferenceComp.PrefabID; } return(objectId); }
protected override GameObject NewObject() { if (Original != null) { GameObject obj = GameObject.Instantiate(Original); obj.name = Original.name + " # " + (ActiveInstances.Count + InactiveInstances.Count); GameObjectPoolReference reference = obj.GetComponent <GameObjectPoolReference>(); if (reference == null) { reference = obj.AddComponent <GameObjectPoolReference>(); reference.PrefabID = Original.GetHashCode(); } NotifyOnConstruct(obj); return(obj); } throw new Exception("[PoolGameObject] -> Original prefab cannot be null."); }
private static PoolGameObject CreateOrGetPool(GameObject gameObject) { if (gameObject == null) { Debug.LogError("[Pool:CreateOrGetPool()] -> GameObject cant be null."); return(null); } int objectId = gameObject.GetHashCode(); GameObjectPoolReference poolReferenceComp = gameObject.GetComponent <GameObjectPoolReference>(); if (poolReferenceComp != null) { objectId = poolReferenceComp.PrefabID; } if (GameObjectPools.TryGetValue(objectId, out PoolGameObject gameObjPool)) { return(gameObjPool); } GameObjectPools.Add(objectId, new PoolGameObject(gameObject)); return(GameObjectPools[objectId]); }