/// <summary>
 /// Despawns this gameObject by returning it to Pooly's prefab pool.
 /// </summary>
 public void Despawn()
 {
     if (cStartTimer != null)
     {
         StopCoroutine(cStartTimer); cStartTimer = null;
     }
     OnDespawn.Invoke();
     Pooly.Despawn(transform);
 }
Beispiel #2
0
 /// <summary>
 /// Starts a despawn timer with a random duration.
 /// If the timerType was set to Start.Never you can manually call this method in order to start the timer.
 /// <para>If durationMinimum and durationMaximum are less than or equal to zero, or if durationMinimum is greater than durationMaximum, it will trigger an instant despawn.</para>
 /// </summary>
 /// <param name="durationMinimum">Minimum duration time.</param>
 /// <param name="durationMaximum">Maximumt duration time.</param>
 public void StartTimer(float durationMinimum, float durationMaximum)
 {
     if(cStartTimer != null) { StopCoroutine(cStartTimer); cStartTimer = null; }
     if(durationMinimum < 0) { durationMinimum = 0; }
     if(durationMaximum < 0) { durationMaximum = 0; }
     if(durationMinimum == durationMaximum && durationMinimum == 0) { OnDespawn.Invoke(); Pooly.Despawn(transform); return; }
     if(durationMinimum > durationMaximum) { OnDespawn.Invoke(); Pooly.Despawn(transform); return; }
     cStartTimer = StartCoroutine(iStartTimer(Random.Range(durationMinimum, durationMaximum)));
 }
 /// <summary>
 /// Starts a despawn timer with a set duration.
 /// If the timerType was set to Start.Never you can manually call this method in order to start the timer.
 /// <para>If the duration is less than or equal to zero, it will trigger an instant despawn.</para>
 /// </summary>
 public void StartTimer(float duration = 0)
 {
     if (cStartTimer != null)
     {
         StopCoroutine(cStartTimer); cStartTimer = null;
     }
     if (duration <= 0)
     {
         OnDespawn.Invoke(); Pooly.Despawn(transform); return;
     }
     cStartTimer = StartCoroutine(iStartTimer(duration));
 }
 /// <summary>
 /// Removes the pooled items that were registered by this pool extension
 /// </summary>
 private void UnregisterItemsFromPooly()
 {
     if (!registeredToPooly)
     {
         return;
     }
     if (Pool.Keys.Count > 0)
     {
         Pooly.DespawnAllClonesFromPoolExtension(this);
         foreach (var pooledItemName in Pool.Keys)
         {
             Pooly.RemovePooledItemFromPool(pooledItemName);
         }
     }
     registeredToPooly = false;
 }
Beispiel #5
0
        void Awake()
        {
            if (_instance != null)
            {
                if (debug)
                {
                    Debug.Log("[Pooly] There cannot be two Main Pools active at the same time. Destryoing this one!");
                }
                Destroy(gameObject);
                return;
            }
            mainPoolSceneName = gameObject.scene.name;
            _instance         = this;
            DontDestroyOnLoad(gameObject);

            Initialize();
        }
Beispiel #6
0
        /// <summary>
        /// Spawns a prefab at one of the set locations without modifying the spawnedCount value.
        /// </summary>
        private Transform Spawn()
        {
            int prefabIndex = GetNextSpawnIndex();

            if (prefabIndex == -1)
            {
                Debug.LogWarning("[Pooly][PoolySpawner] The " + name + " PoolySpawner is trying to spawn a null prefab. Check your referenced prefab slots, one or more may be empty."); return(null);
            }
            GenerateNextSpawnParametersSet();
            if (!matchTransformScale)
            {
                return(Pooly.Spawn(spawnPrefabs[prefabIndex].prefab, nextSpawnParams.spawnPosition, nextSpawnParams.spawnRotation, nextSpawnParams.parent));
            }
            else
            {
                return(Pooly.Spawn(spawnPrefabs[prefabIndex].prefab, nextSpawnParams.spawnPosition, nextSpawnParams.spawnRotation, nextSpawnParams.spawnScale, nextSpawnParams.parent));
            }
        }
Beispiel #7
0
 private IEnumerator iStartTimer(float duration)
 {
     if(useRealTime)
     {
         if(despawnWaitForSecondsRealTime == null || despawnWFSRealTimeCurrentDuration != duration)
         { despawnWaitForSecondsRealTime = new WaitForSecondsRealtime(duration); despawnWFSRealTimeCurrentDuration = duration; }
         yield return despawnWaitForSecondsRealTime;
     }
     else
     {
         if(despawnWaitForSeconds == null || despawnWFSCurrentDuration != duration)
         { despawnWaitForSeconds = new WaitForSeconds(duration); despawnWFSCurrentDuration = duration; }
         yield return despawnWaitForSeconds;
     }
     OnDespawn.Invoke();
     cStartTimer = null;
     Pooly.Despawn(transform);
 }
Beispiel #8
0
 /// <summary>
 /// Spawns the given prefab at one of the set locations without modifying the spawnedCount value.
 /// <para>Note: The prefab has to be registered to this spawner in order to work (and in the Pooly pool as well)</para>
 /// </summary>
 /// <param name="prefab">Target prefab.</param>
 private Transform Spawn(Transform prefab)
 {
     if (prefab == null)
     {
         return(null);
     }
     if (!IsRegisteredPrefab(prefab))
     {
         return(null);
     }
     GenerateNextSpawnParametersSet();
     if (!matchTransformScale)
     {
         return(Pooly.Spawn(prefab, nextSpawnParams.spawnPosition, nextSpawnParams.spawnRotation, nextSpawnParams.parent));
     }
     else
     {
         return(Pooly.Spawn(prefab, nextSpawnParams.spawnPosition, nextSpawnParams.spawnRotation, nextSpawnParams.spawnScale, nextSpawnParams.parent));
     }
 }
Beispiel #9
0
 /// <summary>
 /// Despawns this gameObject by returning it to the Pooly pool
 /// This method is useful only if you have this gameObject spawned from Pooly, thus it exists in the pool.
 /// </summary>
 public void Despawn()
 {
     Pooly.Despawn(transform);
 }