Пример #1
0
 public PoolSettings(PoolSettings src)
 {
     Prewarm    = src.Prewarm;
     AutoCreate = src.AutoCreate;
     MinItems   = src.MinItems;
     Threshold  = src.Threshold;
     Speed      = src.Speed;
     Debug      = src.Debug;
 }
Пример #2
0
 public Pool(PoolSettings settings = null)
 {
     Settings   = settings ?? new PoolSettings();
     Identifier = typeof(T).FullName;
     mLastTime  = DTTime.TimeSinceStartup + UnityEngine.Random.Range(0, Settings.Speed);
     if (Settings.Prewarm)
     {
         Reset();
     }
 }
Пример #3
0
 public void Initialize(System.Type type, PoolSettings settings)
 {
     m_Identifier = type.AssemblyQualifiedName;
     m_Settings   = settings;
     mLastTime    = DTTime.TimeSinceStartup + UnityEngine.Random.Range(0, Settings.Speed);
     if (Settings.Prewarm)
     {
         Reset();
     }
 }
Пример #4
0
 public void Initialize(string ident, PoolSettings settings, params GameObject[] prefabs)
 {
     Identifier = ident;
     m_Settings = settings;
     Prefabs    = new List <GameObject>(prefabs);
     mLastTime  = DTTime.TimeSinceStartup + UnityEngine.Random.Range(0, Settings.Speed);
     if (Settings.Prewarm)
     {
         Reset();
     }
 }
Пример #5
0
        public Pool <T> CreateTypePool <T>(PoolSettings settings = null)
        {
            PoolSettings s   = settings ?? new PoolSettings(DefaultSettings);
            IPool        res = null;

            if (!TypePools.TryGetValue(typeof(T), out res))
            {
                res = new Pool <T>(s);
                TypePools.Add(typeof(T), res);
            }
            return((Pool <T>)res);
        }
Пример #6
0
        public ComponentPool CreateComponentPool <T>(PoolSettings settings = null) where T : Component
        {
            if (!IsInitialized)
            {
                Initialize();
            }
            PoolSettings s   = settings ?? new PoolSettings(DefaultSettings);
            IPool        res = null;

            if (!Pools.TryGetValue(typeof(T).AssemblyQualifiedName, out res))
            {
                res = gameObject.AddComponent <ComponentPool>();
                ((ComponentPool)res).Initialize(typeof(T), s);
                Pools.Add(res.Identifier, res);
            }
            return((ComponentPool)res);
        }
Пример #7
0
        public PrefabPool CreatePrefabPool(string name, PoolSettings settings = null, params GameObject[] prefabs)
        {
            if (!IsInitialized)
            {
                Initialize();
            }
            PoolSettings s = settings ?? new PoolSettings(DefaultSettings);

            IPool pool = null;

            if (!Pools.TryGetValue(name, out pool))
            {
                PrefabPool p = gameObject.AddComponent <PrefabPool>();
                p.Initialize(name, s, prefabs);
                Pools.Add(name, p);
                return(p);
            }
            return((PrefabPool)pool);
        }