コード例 #1
0
    //create new pool at runtime
    public static void CreatePool(string poolName, GameObject prefab, int preLoad, bool limit, int maxCount)
    {
        //debug error if pool was already added before
        if (Pools.ContainsKey(poolName))
        {
            Debug.LogError("Pool Manager already contains Pool: " + poolName);
            return;
        }

        //create new gameobject which will hold the new pool component
        GameObject newPoolGO = new GameObject(poolName);
        //add pool component to the new object
        Pool newPool = newPoolGO.AddComponent<Pool>();

        //initialize a new pool option for this pool
        PoolOptions newPoolOptions = new PoolOptions();
        //assign default parameters passed in
        newPoolOptions.prefab = prefab;
        newPoolOptions.preLoad = preLoad;
        newPoolOptions.limit = limit;
        newPoolOptions.maxCount = maxCount;

        //add new pool option to its list
        newPool._PoolOptions.Add(newPoolOptions);
        //directly instantiate new instances
        newPool.PreLoad();
    }
コード例 #2
0
ファイル: Pool.cs プロジェクト: HigherLevelGames/GATETutor
 //called before playtime, first initialization of new instances
 public void PreLoad()
 {
     //loop through all pool options of this component
     for (int cnt = 0; cnt < this._PoolOptions.Count; cnt++)
     {
         PoolOptions poolOptions = this._PoolOptions[cnt];
         //instantiate defined preload amount but don't exceed the maximum amount of objects
         for (int i = poolOptions.totalCount; i < poolOptions.preLoad; i++)
         {
             //call PreLoad() within class PoolOptions
             Transform trans = poolOptions.PreLoad(poolOptions.prefab, Vector3.zero, Quaternion.identity).transform;
             //parent the new instance to this transform
             trans.SetParent(container);
         }
     }
 }
コード例 #3
0
    public Dictionary <string, Queue <GameObject> > InitializePools()
    {
        poolQueues  = new Dictionary <string, Queue <GameObject> >();
        poolOptions = new Dictionary <string, PoolOptions>();

        foreach (var pool in pools)
        {
            if (pool.prefabs.Count.Equals(0))
            {
                break;
            }
            var objectPool = new Queue <GameObject>();

            for (var i = 0; i < pool.amount; i++)
            {
                var obj = Instantiate(pool.prefabs[Random.Range(0, pool.prefabs.Count)]);
                var rb  = obj.GetComponent <Rigidbody>();
                obj.SetActive(false);
                obj.transform.parent = transform;
                obj.isStatic         = pool.isStatic;
                if (obj.isStatic)
                {
                    if (rb != null)
                    {
                        rb.isKinematic = true;
                    }
                }
                else
                {
                    if (rb != null)
                    {
                        rb.mass *= obj.transform.localScale.sqrMagnitude;
                    }
                }

                objectPool.Enqueue(obj);
            }

            poolQueues.Add(pool.poolName, objectPool);
            PoolOptions options = pool;
            poolOptions.Add(pool.poolName, options);
        }

        return(poolQueues);
    }
コード例 #4
0
ファイル: Pool.cs プロジェクト: HigherLevelGames/GATETutor
    //destroy (uses the garbace collector) a specific amount of inactive instances
    //of a pool option
    public void DestroyPrefabCount(GameObject prefab, int count)
    {
        //loop through all pool options of this component
        for (int cnt = 0; cnt < this._PoolOptions.Count; cnt++)
        {
            PoolOptions poolOptions = this._PoolOptions[cnt];
            //we found the corresponding pool option prefab
            if (poolOptions.prefab == prefab)
            {
                //let DestroyCount() of class PoolOptions handle futher actions
                poolOptions.DestroyCount(count);
                return;
            }
        }

        //no PoolOption contains the passed in prefab, debug a warning
        Debug.LogError("Prefab to destroy count of Pool " + this.name + " not found: " + prefab.name);
    }
コード例 #5
0
        public SkyIslandMapAbsolutePhase(
            IStageIdentity stageIdentity,
            IStageBounds stageBounds,
            IRasterChunkConfig <Index2D> chunkConfig,
            IAsyncChunkPopulator <ISkyIslandMapChunk> chunkPopulator,
            IChunkStore <ChunkOverheadKey, SerializedSkyIslandMapChunk> chunkStore,
            int maxBufferedChunks,
            BatchSerializeGenerationOptions options = null)
        {
            Contracts.Requires.That(stageIdentity != null);
            Contracts.Requires.That(stageBounds != null);
            Contracts.Requires.That(chunkConfig != null);
            Contracts.Requires.That(chunkPopulator != null);
            Contracts.Requires.That(chunkStore != null);
            Contracts.Requires.That(maxBufferedChunks > 0);

            var phaseIdentity = new GenerationPhaseIdentity(nameof(SkyIslandMapAbsolutePhase));
            var chunkKeys     = new ChunkOverheadKeyCollection(stageBounds);

            var poolOptions = new PoolOptions <SkyIslandMapChunkResources>()
            {
            };

            this.pool = Pool.WithFactory.New(new SkyIslandMapChunkResourcesFactory(chunkConfig), poolOptions);

            var chunkFactory = new SkyIslandMapChunkPoolingFactory(this.pool, chunkPopulator);
            var serializer   = new SkyIslandMapChunkResourcesSerializer(
                SkyIslandMapsSerializer.Get[options?.SerializationEndianness ?? DefaultSerializationEndianness],
                chunkConfig);
            var persister          = new SkyIslandMapChunkPersister(serializer);
            var persistableFactory = ChunkFactory.Persister.Create(chunkFactory, persister);

            this.Phase = new ChunkedBatchingPhase <ChunkOverheadKey, SerializedSkyIslandMapChunk>(
                stageIdentity,
                phaseIdentity,
                chunkKeys,
                persistableFactory,
                chunkStore,
                maxBufferedChunks,
                options);

            this.Completion = this.CompleteAsync();
        }
コード例 #6
0
 public AgentMiddleware(RequestDelegate next,
                        IWalletService walletService,
                        IPoolService poolService,
                        IMessageSerializer messageSerializer,
                        IConnectionService connectionService,
                        ICredentialService credentialService,
                        IProvisioningService provisioningService,
                        IOptions <WalletOptions> walletOptions,
                        IOptions <PoolOptions> poolOptions)
 {
     _next                = next;
     _walletService       = walletService;
     _poolService         = poolService;
     _messageSerializer   = messageSerializer;
     _connectionService   = connectionService;
     _credentialService   = credentialService;
     _provisioningService = provisioningService;
     _poolOptions         = poolOptions.Value;
     _walletOptions       = walletOptions.Value;
 }
コード例 #7
0
        private static IPool <IMutableDivisibleMesh <NormalColorTextureVertex> > CreateMeshBuilderPool()
        {
            var options = new PoolOptions <IMutableDivisibleMesh <NormalColorTextureVertex> >()
            {
                ResetAction     = mesh => mesh.Clear(),
                BoundedCapacity = StaticThreadsCount,
            };

            var initialSize = MeshConstants.MaxVerticesSupportedBy16BitIndices * 2;

            var pool = Pool.New(options);

            pool.GiveUntilFull(Factory.From <IMutableDivisibleMesh <NormalColorTextureVertex> >(
                                   () => new MutableDivisibleMesh <NormalColorTextureVertex>(
                                       initialGroups: initialSize / 4,
                                       initialOffsets: initialSize,
                                       initialVertices: initialSize / 2)));

            return(pool);
        }
コード例 #8
0
        public ActionResult CreatePool(Pool model)
        {
            int numberOfTokens;

            PoolOptions poolOptionsModel = (PoolOptions)Session["PoolOptions"];

            try
            {
                if (String.IsNullOrEmpty(poolOptionsModel.NumberOfTokens))
                {
                    throw new Exception("Object is empty");
                }
                else
                {
                    numberOfTokens = Convert.ToInt32(poolOptionsModel.NumberOfTokens.Replace(" ", ""));
                }
            }
            catch (Exception)
            {
                numberOfTokens = 200;
            }

            List <string> Tokens = new List <string>();
            string        token;

            model.Tokens = new List <Token>();

            for (int i = 0; i < numberOfTokens; i++)
            {
                token = Guid.NewGuid().ToString().Substring(0, 13);
                model.Tokens.Add(new Token()
                {
                    TokenValue = token, Used = false
                });
                Tokens.Add(token);
            }

            var excelFile = excelProvider.CreateExcelFile(Tokens);

            return(View(model));
        }
コード例 #9
0
        public ActionResult InitialisePool(PoolOptions model)
        {
            Session["PoolOptions"] = model;

            return(RedirectToAction("CreatePool"));
        }
コード例 #10
0
        public ActionResult InitialisePool()
        {
            PoolOptions model = new PoolOptions();

            return(View(model));
        }
コード例 #11
0
        /// <summary>
        /// Sets the <see cref="PoolOptions"/> for this agent
        /// </summary>
        /// <param name="poolOptions">The pool options.</param>
        /// <returns></returns>
        public AgentConfigurationBuilder SetPoolOptions(PoolOptions poolOptions)
        {
            PoolOptions = poolOptions;

            return(this);
        }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AgentConfigurationBuilder"/> class.
 /// </summary>
 /// <param name="services">The services.</param>
 /// <exception cref="System.ArgumentNullException">services</exception>
 internal AgentConfigurationBuilder(IServiceCollection services)
 {
     WalletOptions = new WalletOptions();
     PoolOptions   = new PoolOptions();
     Services      = services ?? throw new ArgumentNullException(nameof(services));
 }
コード例 #13
0
 internal AgentConfiguration()
 {
     WalletOptions = new WalletOptions();
     PoolOptions   = new PoolOptions();
 }
コード例 #14
0
ファイル: Pool.cs プロジェクト: patte88/Monsters-Incoming
    //find corresponding pool option of submitted prefab and forward call to Activate() of class PoolOptions
    //in case there is no pool option for this prefab, this method will create a new one
    public GameObject Spawn(GameObject prefab, Vector3 position, Quaternion rotation)
    {
        //loop through all pool options of this component
        for (int cnt = 0; cnt < this._PoolOptions.Count; cnt++)
        {
            PoolOptions poolOptions = this._PoolOptions[cnt];
            //we found the corresponding pool option prefab
            if (poolOptions.prefab == prefab)
            {
                //activate (or instantiate) a new instance of this prefab
                GameObject obj = poolOptions.Activate(position, rotation);

                //Activate() returned null - we can't instantiate a new instance
                //the possible amount of instances are active and limited
                if (obj == null) return null;

                //add returned instance to the list of all instances
                this._AllActive.Add(obj);

                //get instance transform
                Transform trans = obj.transform;
                //in case it wasn't parented to this transform, parent it now
                if (trans.parent != container)
                    trans.parent = container;

                //submit instance
                return obj;
            }
        }

        //no PoolOption contains the passed in prefab, debug a warning
        Debug.Log("Prefab not found: " + prefab.name + " added to Pool " + this.name);
        //create new PoolOption for the prefab gameobject
        PoolOptions newPoolOptions = new PoolOptions();
        //assign it as base prefab
        newPoolOptions.prefab = prefab;
        //add the new PoolOption to the list of PoolOptions of this pool
        _PoolOptions.Add(newPoolOptions);

        //instantiate a new instance of that prefab
        GameObject newObj = newPoolOptions.Activate(position, rotation);
        //parent it to this transform
        newObj.transform.parent = container;
        //add returned instance to the list of all instances
        this._AllActive.Add(newObj);

        //submit instance
        return newObj;
    }