public Spawned SpawnSpecificTrashArea(int indexForm, int indexSpawnArea) { Spawned ret = null; TA_SHAPES standard = TA_SHAPES.Plane_Small; SpawnedList spawnable_curList = spawnable_TrashAreas[indexForm]; SpawnedList spawned_curList = spawned_TrashAreas[indexForm]; Spawned curPopped; int lastPos; if (spawnable_curList.Count == 0) { lastPos = 0; curPopped = spawned_curList[0]; spawned_curList.RemoveAt(0); spawnable_curList.Add(curPopped); } else { lastPos = spawnable_TrashAreas[indexForm].Count - 1; curPopped = spawnable_curList[lastPos]; } curPopped.gameObject.SetActive(true); //trashAreaHandler.Spawn(current + i, spawnArea[/*Random.Range(0, spawnArea.Length)*/4], curPopped); bool spawnedCorrectly = trashAreaHandler.Spawn(standard + indexForm, spawnArea[indexSpawnArea], curPopped, Random.Range(100, 160)); if (spawnedCorrectly) { StartCoroutine(GrowToSize(curPopped)); spawnable_curList.RemoveAt(lastPos); spawned_curList.Add(curPopped); ret = curPopped; LevelBalancing.SetTrashValue(curPopped.personalTrashValue); } else if (!spawnedCorrectly) { curPopped.gameObject.SetActive(false); } return(ret); }
void Start() { spawnArea = new MeshFilter[center.Length]; for (int i = 0; i < center.Length; i++) { spawnArea[i] = center[i].gameObject.GetComponent <MeshFilter>(); } if (maxSpawnRadius < minSpawnRadius) { throw new System.Exception("SpawnController: maxRadius is smaller then the planed min Distance to the player."); } int counter = 0; // Trash Setup before // spawnable_SmallTrash = new List<Spawned>(); // // // serves as a unique number for every trash element // foreach (Spawned sp in Prefabs_SmallTrash) // { // for (int i = 0; i < totalNrCopies; i++) // { // Spawned curObject = Instantiate<Spawned>(sp); // spawnable_SmallTrash.Add(curObject); // curObject.SpawnMaster = this; // curObject.PoolNumber = counter++; // curObject.gameObject.SetActive(false); // } // } // spawned_SmallTrash = new List<Spawned>(); // ----------------------------------- // Create jagged Arrays for TrashArea Pooling spawnable_SmallTrash = new SpawnedList[Prefabs_SmallTrash.Length]; spawned_SmallTrash = new SpawnedList[Prefabs_SmallTrash.Length]; for (int i = 0; i < Prefabs_SmallTrash.Length; i++) { SpawnedList spawnable_temp = new SpawnedList(); for (int j = 0; j < totalNrCopies; j++) { Spawned newSmallObject = Instantiate <Spawned>(Prefabs_SmallTrash[i]); spawnable_temp.Add(newSmallObject); newSmallObject.SpawnMaster = this; newSmallObject.PoolNumber = counter++; newSmallObject.gameObject.SetActive(false); } spawnable_SmallTrash[i] = spawnable_temp; SpawnedList spawned_temp = new SpawnedList(); spawned_SmallTrash[i] = spawned_temp; } /*dTInstance = GameObject.Instantiate(DirtThrow); * dTInstance.transform.position = Vector3.up * -10f; * dTInstance.Stop();*/ codes = new KeyCode[] { KeyCode.Alpha1, KeyCode.Alpha2, KeyCode.Alpha3, KeyCode.Alpha4, KeyCode.Alpha5 }; /* * Prepare */ trashAreaHandler = new SpawnTrashArea(VisibleDebug); // Create jagged Arrays for TrashArea Pooling spawnable_TrashAreas = new SpawnedList[Prefabs_TrashAreas.Length]; spawned_TrashAreas = new SpawnedList[Prefabs_TrashAreas.Length]; for (int i = 0; i < Prefabs_TrashAreas.Length; i++) { SpawnedList spawnable_temp = new SpawnedList(); for (int j = 0; j < totalNrCopies; j++) { Spawned newAreaObject = Instantiate <Spawned>(Prefabs_TrashAreas[i]); spawnable_temp.Add(newAreaObject); newAreaObject.SpawnMaster = this; newAreaObject.PoolNumber = counter++; newAreaObject.gameObject.SetActive(false); } spawnable_TrashAreas[i] = spawnable_temp; SpawnedList spawned_temp = new SpawnedList(); spawned_TrashAreas[i] = spawned_temp; } }