public static Transform Spawn(Transform prefab, Vector3 pos, Quaternion rot, Vector3 localScale, Pool.UpdateDelegate update = null, Pool.DespawnTestDelegate despawn = null) { if (sInstance == null) { Debug.LogError("Hydra.PoolManager: No PoolManager instance. Add a PoolManager object to the scene."); return(null); } #if UNITY_EDITOR if (sInstance.editorDynamicResize && !sInstance.mRuntimePools.ContainsKey(prefab)) { // make a new pool Pool newPool = ScriptableObject.CreateInstance <Pool>(); newPool.name = "Pool_" + prefab.name; newPool.prefab = UnityEditor.PrefabUtility.FindPrefabRoot(prefab.gameObject).transform; newPool.size = 1; newPool.onDespawn = Pool.DespawnAction.Deactivate; newPool.onCapacityReached = Pool.CapacityReachedAction.Recycle; sInstance.pools.pools.Add(newPool); UnityEditor.AssetDatabase.AddObjectToAsset(newPool, sInstance.pools); UnityEditor.AssetDatabase.ImportAsset(UnityEditor.AssetDatabase.GetAssetPath(sInstance.pools)); RuntimePool runtimePool = new RuntimePool(); runtimePool.InitializePool(newPool); sInstance.mRuntimePools[newPool.prefab] = runtimePool; } #endif Transform t = sInstance.mRuntimePools[prefab].ActivateObject(pos, rot, localScale); if (t != null) { sInstance.TrackSpawnedObject(t, prefab, update, despawn); } return(t); }
private void Awake() { mRuntimePools = new Dictionary <Transform, RuntimePool>(); mUpdates = new List <SpawnedUpdate>(); mDespawnChecks = new List <DespawnCheck>(); mSpawnedObjects = new Dictionary <Transform, RuntimePool>(); foreach (var pool in pools.pools) { RuntimePool runtimePool = new RuntimePool(); runtimePool.InitializePool(pool); mRuntimePools[pool.prefab] = runtimePool; } if (sInstance == null) { sInstance = this; } }