protected BehaviorManager GetSpawner(SpawnerType spawnerType) { GameObject spawner = GameObject.FindGameObjectWithTag(spawnerType.ToString()); if(spawner == null) { Debug.LogErrorFormat("Unable to find Spawner with tag '{0}'", spawnerType.ToString()); return null; } BehaviorManager behavior = spawner.GetComponent<BehaviorManager>(); if(behavior == null) { Debug.LogErrorFormat("Unable to find Behavior Manger on object '{0}'", spawner.name); return null; } return behavior; }
void AddSpawner(SpawnerType type, GameObject spawner) { if (ContainsType(type) == 0) Debug.Log("There are no " + type.ToString() + " here in " + name); else if (ContainsType(type) == 1) { Vector3 randomVector = Random.insideUnitSphere * 5; randomVector.y = 5f; if (type == Spawner1) { Spawners1.Add(AreaPlacement(5, Spawner1Pos + randomVector, spawner, Spawner1Location)); } else if (type == Spawner2) { Spawners2.Add(AreaPlacement(5, Spawner2Pos + randomVector, spawner, Spawner2Location)); } else if (type == Spawner3) { Spawners3.Add(AreaPlacement(5, Spawner3Pos + randomVector, spawner, Spawner3Location)); } } }
int CountSpawners(SpawnerType type) { if (ContainsType(type) == 0) Debug.Log("No instances of " + type.ToString() + " found in " + name); else if (Spawner1 == type) { if (Spawners1.Count > 1) Spawners1.RemoveAll(x => x == null); return Spawners1.Count; } else if (Spawner2 == type) { if (Spawners2.Count > 1) Spawners2.RemoveAll(x => x == null); return Spawners2.Count; } else if (Spawner3 == type) { if (Spawners3.Count > 1) Spawners3.RemoveAll(x => x == null); return Spawners3.Count; } return 0; }
void RemoveSpawner(SpawnerType type) { if (ContainsType(type) == 0) Debug.Log("There are no " + type.ToString() + " here in " + name); else if (type == Spawner3) { if (Spawners3.Count > 0) { Destroy(Spawners3[Spawners3.Count - 1].gameObject); Spawners3.RemoveAt(Spawners3.Count - 1); } if (Spawners3.Count == 0) { Spawner3 = SpawnerType.Unknown; Spawners3 = null; // Remove all children (clean slate) var children = new List<GameObject>(); foreach (Transform child in Spawner3Location) children.Add(child.gameObject); children.ForEach(child => Destroy(child)); } } else if (type == Spawner2) { if (Spawners2.Count > 0) { Destroy(Spawners2[Spawners2.Count - 1].gameObject); Spawners2.RemoveAt(Spawners2.Count - 1); } if (Spawners2.Count == 0) { Spawner2 = SpawnerType.Unknown; Spawners2 = null; // Remove all children (clean slate) var children = new List<GameObject>(); foreach (Transform child in Spawner2Location) children.Add(child.gameObject); children.ForEach(child => Destroy(child)); } } else if (type == Spawner1) { if (Spawners1.Count > 0) { Destroy(Spawners1[Spawners1.Count - 1].gameObject); Spawners1.RemoveAt(Spawners1.Count - 1); } if (Spawners1.Count == 0) { Spawner1 = SpawnerType.Unknown; Spawners1 = null; // Remove all children (clean slate) var children = new List<GameObject>(); foreach (Transform child in Spawner1Location) children.Add(child.gameObject); children.ForEach(child => Destroy(child)); } } }
void AssignSpawnerType(SpawnerType type) { if (ContainsType(type) == 1) Debug.Log(type.ToString() + " already exists in " + name); else if (Spawner1 == SpawnerType.Unknown) { Spawner1 = type; Spawners1 = new List<PickupSpawner>(); setupTypeProps(type, Spawner1Pos); } else if (Spawner2 == SpawnerType.Unknown) { Spawner2 = type; Spawners2 = new List<PickupSpawner>(); setupTypeProps(type, Spawner2Pos); } else if (Spawner3 == SpawnerType.Unknown) { Spawner3 = type; Spawners3 = new List<PickupSpawner>(); setupTypeProps(type, Spawner3Pos); } else { Debug.Log("Cannot add " + type.ToString() + "; no more room in " + name); } }