public void ShowBot( GameObject botPrefab ) { // clear any previous state Clear(); // spawn the bot (at current sandbox location) spawnedBot = Object.Instantiate(botPrefab, transform.position, transform.rotation); // set layer for all child parts var layer = LayerMask.NameToLayer("sandbox"); var transforms = PartUtil.GetComponentsInChildren <Transform>(spawnedBot); for (var i = 0; i < transforms.Length; i++) { transforms[i].gameObject.layer = layer; } var materialDistributor = spawnedBot.GetComponent <MaterialDistributor>(); if (materialDistributor != null) { materialDistributor.materialTag = botMaterial; } // attach the AI controller var ai = spawnedBot.AddComponent <OnOffAIController>(); ai.randomize = true; ai.delay = 2f; }
void Discover() { int totalHealth = 0; var components = PartUtil.GetComponentsInChildren <Health>(gameObject); for (var i = 0; i < components.Length; i++) { totalHealth += components[i].maxHealth; } Debug.Log(gameObject.name + " # components: " + components.Length + " totalHealth: " + totalHealth); }
void Discover() { float totalMass = 0; var rbs = PartUtil.GetComponentsInChildren <Rigidbody>(gameObject); for (var i = 0; i < rbs.Length; i++) { totalMass += rbs[i].mass; } Debug.Log(gameObject.name + " # rbs: " + rbs.Length + " totalMass: " + totalMass); }
public void SetMaterials(MaterialTag tag) { materialTag = tag; var actuators = PartUtil.GetComponentsInChildren <MaterialActuator>(gameObject); if (actuators == null) { return; } for (var i = 0; i < actuators.Length; i++) { actuators[i].Assign(tag); } }
void Start() { sparksPrefab = (GameObject)Resources.Load("Sparks"); // link health to our on percent change handler health = GetComponent <Health>(); if (health == null) { health = PartUtil.GetComponentInParentBody <Health>(gameObject); } if (health != null) { health.onChangePercent.AddListener(OnHealthPercentChange); } materialActuators = PartUtil.GetComponentsInChildren <MaterialActuator>(gameObject); rb = GetComponent <Rigidbody>(); }
void Discover() { leftScripts = new List <IMotorActuator>(); rightScripts = new List <IMotorActuator>(); var scripts = PartUtil.GetComponentsInChildren <IMotorActuator>(gameObject); for (var i = 0; i < scripts.Length; i++) { if (scripts[i].left) { leftScripts.Add(scripts[i]); } else { rightScripts.Add(scripts[i]); } } }
void Discover() { totalHealth = 0; healthModules = new List <Health>(); var components = PartUtil.GetComponentsInChildren <Health>(gameObject); for (var i = 0; i < components.Length; i++) { // only consider bot modules for overall bot health if (components[i].healthTag == HealthTag.Module) { totalHealth += components[i].maxHealth; healthModules.Add(components[i]); components[i].onTakeDamage.AddListener(OnTakeDamage); } } minHealth = (totalHealth * deathHealthPercent) / 100; Debug.Log(gameObject.name + " # healthModules: " + healthModules.Count + " totalHealth: " + totalHealth + " minHealth: " + minHealth); }
public static T[] GetComponentsInChildren <T>(GameObject rootPartGo) { var allComponents = new List <T>(); // find component of specified type in root's tree T[] components = rootPartGo.GetComponentsInChildren <T>(); allComponents.AddRange(components); // find any part child link components in root var childLinks = rootPartGo.GetComponentsInChildren <ChildLink>(); for (var i = 0; i < childLinks.Length; i++) { // if part has external parts reference if (childLinks[i].childGo != null) { allComponents.AddRange(PartUtil.GetComponentsInChildren <T>(childLinks[i].childGo)); } } return(allComponents.ToArray()); }
void Discover() { actuators = PartUtil.GetComponentsInChildren <IActuator>(gameObject); Debug.Log("# actuators: " + actuators.Length); }
void Discover() { motorScripts = PartUtil.GetComponentsInChildren <IMotorActuator>(gameObject); steeringScripts = PartUtil.GetComponentsInChildren <ISteeringActuator>(gameObject); Debug.Log("# motorSripts: " + motorScripts.Length + " steeringScripts: " + steeringScripts.Length); }