public void InitialzePool(IPoolInfo poolClassObject, int seed, GameObject[] prefabArray)
    {
        poolInfo = poolClassObject;

        Random.InitState(seed);

        //Debug.Log("Intitializing " + poolInfo.WhatToSpawn.ToString() + " started");

        // Initialize Object Pool
        for (int i = 0; i < poolInfo.PoolAmt; i++)
        {
            GameObject spawnObject = Instantiate(prefabArray[Random.Range(0, prefabArray.Length)]);
            spawnObject.SetActive(false);
            spawnObject.transform.parent = this.gameObject.transform;

            //-------------------------------------------------------------------------
            // Choose a random path in the scene
            PathCreator path = poolInfo.PathsArray[Random.Range(0, poolInfo.PathsArray.Length)];
            spawnObject.GetComponent <PathFollower>().pathCreator = path;

            //---------------------------------------------------------------------------

            poolClassObject.PoolDictionery.Add(spawnObject, path);

            // Make it child of the path gameobject
            spawnObject.transform.parent = path.gameObject.transform;
        }
        //Clear prefabArray
        System.Array.Clear(prefabArray, 0, prefabArray.Length);
        prefabArray = null;
    }
    // CAN BE REFACTORED
    public void PreparePools(int seed)
    {
        // Prepare the poolInfos
        pedestrianPoolInfo = new IPoolInfo(ESpawnSelection.PEDESTRIANS, pedestrianPoolAmt, pedestrianMaxSpawnDelay,
                                           pedestrianPaths, true);
        // Get all prefabs from the list
        pedestriansPrefabs = Resources.LoadAll <GameObject>("PEDESTRIANS");
        pedestrianComponent.InitialzePool(pedestrianPoolInfo, seed, pedestriansPrefabs);

        // Same for the vehicles as well
        vehiclePoolInfo = new IPoolInfo(ESpawnSelection.VEHICLES, vehiclePoolAmt, vehicleMaxSpawnDelay,
                                        vehiclePaths, true);
        vehiclePrefabs = Resources.LoadAll <GameObject>("VEHICLES");
        vehicleComponent.InitialzePool(vehiclePoolInfo, seed, vehiclePrefabs);
    }
Esempio n. 3
0
            /// <summary>
            /// 获取所有引用池的信息
            /// </summary>
            /// <returns>所有引用池的信息。</returns>
            public static IPoolInfo[] GetAllReferencePoolInfos()
            {
                int index = 0;

                IPoolInfo[] results = null;

                lock (_referenceCollections)
                {
                    results = new IPoolInfo[_referenceCollections.Count];
                    foreach (KeyValuePair <Type, ReferenceCollection> referenceCollection in _referenceCollections)
                    {
                        results[index++] = referenceCollection.Value;
                    }
                }
                return(results);
            }
 internal static void Add(IPoolInfo pool)
 {
     pools.Add(pool);
 }
Esempio n. 5
0
 internal static void Add(IPoolInfo pool)
 {
     pools.Add(pool);
 }