public GameObject GetCreature(GameObject species) { GameObject speciesInstance = aliveMap[species]; SchoolGenerator sg = speciesInstance.GetComponent <SchoolGenerator>(); if (speciesInstance.GetComponent <TenticleCreatureGenerator>() != null) { return(speciesInstance.GetComponent <TenticleCreatureGenerator>().head.gameObject); } else if (sg != null) { if (sg.alive.Count == 0) { Debug.Log("school 0"); return(null); } return(sg.alive[UnityEngine.Random.Range(0, sg.alive.Count)].GetComponentInChildren <Boid>().gameObject); } else if (speciesInstance.GetComponent <FormationGenerator>() != null) { return(speciesInstance.GetComponent <FormationGenerator>().leader.GetComponentInChildren <Boid>().gameObject); } else { return(Utilities.FindBoidInHierarchy(speciesInstance).gameObject); } }
public GameObject GetSpecies(int speciesIndex, bool useExisting) { Vector3 newPos = Vector3.zero; GameObject newCreature = null; SpawnParameters sp = prefabs[speciesIndex].GetComponent <SpawnParameters>(); if (useExisting && aliveMap.ContainsKey(prefabs[speciesIndex])) { GameObject creature = aliveMap[prefabs[speciesIndex]]; if (!creature.GetComponent <SpawnParameters>().isSuspending) { return(prefabs[speciesIndex]); } } if (suspended.ContainsKey(prefabs[speciesIndex])) { newCreature = suspended.Get(prefabs[speciesIndex]); if (FindPlace(newCreature, out newPos)) { suspended.Remove(prefabs[speciesIndex], newCreature); Teleport(newCreature, newPos); newCreature.SetActive(true); if (newCreature.GetComponent <LifeColours>()) { newCreature.GetComponent <LifeColours>().FadeIn(); } if (newCreature.GetComponentInChildren <CreatureController>()) { newCreature.GetComponentInChildren <CreatureController>().Restart(); } // Change the school size every time we teleport a school SchoolGenerator sg = newCreature.GetComponentInChildren <SchoolGenerator>(); if (sg != null) { sg.transform.position = newPos; sg.targetCreatureCount = Random.Range(sg.minBoidCount, sg.maxBoidCount); } alive.Add(newCreature); aliveMap[prefabs[speciesIndex]] = newCreature; /*GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); * cube.transform.position = newPos; * cube.transform.localScale = Vector3.one * 5; */ } } else { //Debug.Log("Instiantiating a new: " + prefabs[nextCreature]); if (FindPlace(prefabs[speciesIndex], out newPos)) { newCreature = GameObject.Instantiate <GameObject>(prefabs[speciesIndex], newPos , prefabs[speciesIndex].transform.rotation * Quaternion.AngleAxis(Random.Range(0, 360), Vector3.up) ); newCreature.GetComponent <SpawnParameters>().Species = prefabs[speciesIndex]; if (school != null) { Boid b = newCreature.GetComponent <Boid>(); b.school = school; school.boids.Add(b); } if (newCreature.GetComponentInChildren <CreatureController>()) { newCreature.GetComponentInChildren <CreatureController>().mother = this; } newCreature.transform.parent = this.transform; newCreature.transform.position = newPos; newCreature.SetActive(true); alive.Add(newCreature); aliveMap[prefabs[speciesIndex]] = newCreature; } else { Debug.Log("Couldnt find a place for the new creature"); } } return(prefabs[speciesIndex]); }