Пример #1
0
        public static T Create <T>(PoolInternalBase pool) where T : new()
        {
            var instance = new T();

            PoolInternalBase.CallOnSpawn(instance, pool);

            return(instance);
        }
Пример #2
0
 T IPoolImplementation.PoolSpawn <T>(System.Action <T> destructor)
 {
     if (this.isNull == true)
     {
         var res = new T();
         PoolInternalBase.CallOnSpawn(res, null);
         return(res);
     }
     return(this.pools.Spawn <T, byte>(0, (state) => new T(), destructor));
 }
Пример #3
0
        public static object Spawn(System.Type type)
        {
            var key      = WorldUtilities.GetKey(type);
            var instance = PoolComponents.Spawn_INTERNAL(type, key, out var pool);

            if (instance == null)
            {
                instance = (IComponent)System.Activator.CreateInstance(type);
                PoolInternalBase.CallOnSpawn(instance, pool);
            }

            return(instance);
        }
Пример #4
0
        T IPoolImplementation.PoolSpawn <T, TState>(TState state, System.Func <TState, T> constructor, System.Action <T> destructor)
        {
            if (this.isNull == true)
            {
                var res = constructor.Invoke(state);
                PoolInternalBase.CallOnSpawn(res, null);
                //ME.WeakRef.Reg(res);
                return(res);
            }
            var instance = this.pools.Spawn <T, TState>(state, constructor, destructor);

            //ME.WeakRef.Reg(instance);
            return(instance);
        }
Пример #5
0
        public T Spawn <T, TState>(TState state, System.Func <TState, T> constructor, System.Action <T> destructor = null) where T : class
        {
            if (Pools.isActive == false)
            {
                var instance = constructor.Invoke(state);
                PoolInternalBase.CallOnSpawn(instance, null);
                return(instance);
            }

            var type = typeof(T);

            if (this.pool.TryGetValue(type, out var pool) == true)
            {
                return((T)pool.Spawn(state));
            }

            pool = new PoolInternal <T, TState>(type, constructor, destructor);
            this.pool.Add(type, pool);

            return((T)pool.Spawn(state));
        }