123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// This component is responsible for pre-creating the pools before they are needed.
- /// This is useful for objects like bullets, which are not part of a PooledLootTable
- /// (which would automatically pool the objects).
- /// </summary>
- public class PrePooler : MonoBehaviour
- {
- [System.Serializable]
- public class PrePoolInfo
- {
- public PoolObject prefab;
- public int quantity;
- }
- public PrePoolInfo[] prePools;
- void Awake()
- {
- PrePool();
- NotificationCenter.AddListener(OnApplySkin, NotificationType.ApplySkin);
- }
- void OnDestroy()
- {
- NotificationCenter.RemoveListener(OnApplySkin, NotificationType.ApplySkin);
- }
- void OnApplySkin(Notification note)
- {
- DestroyImmediate(GameObject.Find("Pools"));
- Pool.ClearAllPools();
- PrePool();
- }
- void PrePool()
- {
- foreach (PrePoolInfo prePool in prePools)
- {
- Pool.Create(prePool.prefab, prePool.quantity);
- }
- }
- }
|