/// <summary>This allows you to spawn a prefab via GameObject.</summary> public static GameObject Spawn(GameObject prefab, Vector3 position, Quaternion rotation, Transform parent = null, bool worldPositionStays = true, LeanGameObjectPool.NotificationType notification = LeanGameObjectPool.NotificationType.None) { if (prefab != null) { // Find the pool that handles this prefab var pool = default(LeanGameObjectPool); // Create a new pool for this prefab? if (LeanGameObjectPool.TryFindPoolByPrefab(prefab, ref pool) == false) { pool = new GameObject("LeanPool (" + prefab.name + ")").AddComponent <LeanGameObjectPool> ( ); //Change How notification at first time pool.Notification = notification; pool.Prefab = prefab; } // Try and spawn a clone from this pool var clone = default(GameObject); if (pool.TrySpawn(position, rotation, parent, worldPositionStays, ref clone) == true) { // Clone already registered? if (Links.Remove(clone) == true) { // If this pool recycles clones, then this can be expected if (pool.Recycle == true) { } // This shouldn't happen else { Debug.LogWarning("You're attempting to spawn a clone that hasn't been despawned. Make sure all your Spawn and Despawn calls match, you shouldn't be manually destroying them!", clone); } } // Associate this clone with this pool Links.Add(clone, pool); return(clone); } } else { Debug.LogError("Attempting to spawn a null prefab."); } return(null); }
/// <summary>This allows you to spawn a prefab via GameObject.</summary> public static GameObject Spawn(GameObject prefab, Transform parent = null, bool worldPositionStays = false, LeanGameObjectPool.NotificationType notification = LeanGameObjectPool.NotificationType.None) { if (prefab != null) { return(Spawn(prefab, prefab.transform.position, prefab.transform.rotation, parent, worldPositionStays, notification)); } else { Debug.LogError("Attempting to spawn a null prefab."); } return(null); }