public SpawnGroupData(SpawnGroup group) { SpawnPos = new SerializableVector3[group.SpawnPos.Length]; for (int i = 0; i < group.SpawnPos.Length; i++) { SpawnPos[i] = group.SpawnPos[i]; } SpawnRot = group.SpawnRot; }
/// <summary> /// Removes a new spawn group from the level and data structure. /// </summary> public void RemoveSpawnGroup(SpawnGroup group) { for (int i = 0; i < SpawnGroups.Count; i++) { if (group.GetInstanceID() == SpawnGroups[i].GetInstanceID()) { SpawnGroups.RemoveAt(i); return; } } Debug.LogError("Spawn Group Doesn't Exist"); }
/// <summary> /// Gets a random list of enemy spawns that will scale depending on the difficulty of the mission. /// </summary> /// <param name="id"> The ID of the block that the mission is located in. </param> /// <param name="difficulty"> The difficulty of the mission. </param> /// <param name="positions"> The list of the enemy spawn positions. </param> /// <param name="rotations"> The list of the enemy spawn rotations. </param> public void GetScaledSpawns(int id, int difficulty, out List <Vector3> positions, out List <float> rotations) { positions = new List <Vector3>(); rotations = new List <float>(); // If block doesn't exist or spawns don't exist then return null values List <SpawnGroup> spawnGroups = null; foreach (SpawnGroupHandler handler in enemySpawnPoints) { if (handler.BlockId == id) { spawnGroups = handler.SpawnGroups; break; } } if (spawnGroups == null) { #if UNITY_EDITOR if (Application.isPlaying) { Debug.LogError("No Spawn points found for block " + id); } #endif return; } if (id == 38) { positions.Add(spawnGroups[0].SpawnPos[0]); rotations.Add(spawnGroups[0].SpawnRot[0]); return; } difficulty = Mathf.Clamp(difficulty, 1, 5); // Sets spawn chance (may need tweaking) int[] chance = new int[5]; switch (difficulty) { case 1: chance = difficultyOne; break; case 2: chance = difficultyTwo; break; case 3: chance = difficultyThree; break; case 4: chance = difficultyFour; break; case 5: chance = difficultyFive; break; } if (chance[0] + chance[1] + chance[2] + chance[3] + chance[4] != 100) { Debug.Log("EnemySpawnHandler: Difficulty [" + difficulty + "] percentages don't add to 100, incorrect spawning possible"); } // Makes sure groups aren't repeated bool[] used = new bool[spawnGroups.Count]; for (int i = 0; i < used.Length; i++) { used[i] = false; } // Gets a random group for each spawn and gets the positions and rotations for each group used for (int i = 0; i < spawnGroups.Count; i++) { SpawnGroup group = spawnGroups[i]; // Chance for spawn group size int percentage = UnityEngine.Random.Range(0, 100); int spawnNumber = 0; // Gets the positions and rotations for the spawn size wanted if (percentage < chance[0]) { spawnNumber = 2; } else if (percentage < chance[0] + chance[1]) { spawnNumber = 3; } else if (percentage < chance[0] + chance[1] + chance[2]) { spawnNumber = 4; } else if (percentage < chance[0] + chance[1] + chance[2] + chance[3]) { spawnNumber = 5; } else { spawnNumber = 6; } for (int j = 0; j < spawnNumber; j++) { positions.Add(group.SpawnPos[j]); } for (int j = 0; j < spawnNumber; j++) { rotations.Add(group.SpawnRot[j]); } } }