public override void Apply(PartConfig config, GameObject target) { if (target == null) { return; } // find rigid body gameobject under target var rigidbodyGo = PartUtil.GetBodyGo(target); if (rigidbodyGo == null) { return; } // add rigid body properties var rigidbody = rigidbodyGo.GetComponent <Rigidbody>(); if (rigidbody == null) { return; } rigidbody.mass = mass; rigidbody.drag = drag; rigidbody.angularDrag = angularDrag; }
public override GameObject Build( PartConfig config, GameObject root, string label ) { GameObject partsGo = null; GameObject bodyGo = null; GameObject steeringGo = null; GameObject hubBodyGo = null; // build out part model first partsGo = base.Build(config, root, label); bodyGo = partsGo.transform.Find(partsGo.name + ".body").gameObject; // now build out wheel parts hierarchy // frame is instantiated under parts.body if (frame != null) { frame.Build(config, bodyGo, "frame"); } // steering goes next (if specified) under parts if (steering != null) { steeringGo = steering.Build(config, partsGo, "steering"); } // hub/wheel goes next under parts if (hub != null) { var hubGo = hub.Build(config, (steeringGo != null) ? steeringGo : partsGo, "hub"); // if hub part isn't specified, build dummy hub rigidbody for wheel if (hubGo == null) { hubBodyGo = PartUtil.BuildGo(config, partsGo, "hub.body", typeof(Rigidbody), typeof(KeepInBounds)); } else { hubBodyGo = PartUtil.GetBodyGo(hubGo); } if (wheel != null) { wheel.Build(config, hubBodyGo, "wheel"); } } return(partsGo); }
public override void Apply(PartConfig config, GameObject target) { if (target == null) { return; } // find rigid body gameobject under target var rigidbodyGo = PartUtil.GetBodyGo(target); if (rigidbodyGo == null) { return; } // add fixed joint component to target var joint = ApplyJoint(rigidbodyGo, config, target); if (joint == null) { return; } //joint.enablePreprocessing = false; // apply break limits, as specified if (applyBreakForce) { joint.breakForce = breakForce; } if (applyBreakTorque) { joint.breakTorque = breakTorque; } // add damage actuator to joint rigidbody if joint can be damaged if (applyDamageToForce || applyDamageToTorque) { var actuator = rigidbodyGo.AddComponent <JointDamageActuator>(); actuator.applyDamageToForce = applyDamageToForce; actuator.applyDamageToTorque = applyDamageToTorque; actuator.gameEventChannel = gameEventChannel; } // add simple joiner script to target, allowing quick joint join var joiner = target.AddComponent <Joiner>(); joiner.joint = joint; }
public override void Apply(PartConfig config, GameObject target) { if (target == null) { return; } // find rigid body gameobject under target var rigidbodyGo = PartUtil.GetBodyGo(target); if (rigidbodyGo == null) { return; } // apply impact damage actuator if (impactApplyDamage) { var actuator = rigidbodyGo.AddComponent <ImpactDamageActuator>(); actuator.minDamage = impactMinDamage; actuator.maxDamage = impactMaxDamage; actuator.damageModifier = impactDamageModifier; actuator.emitScrews = impactScrews; actuator.minScrewDamage = impactScrewDamage; actuator.smallImpactSfx = smallImpactSfx; actuator.smallImpactSfxThreshold = smallImpactSfxThreshold; actuator.mediumImpactSfx = mediumImpactSfx; actuator.mediumImpactSfxThreshold = mediumImpactSfxThreshold; actuator.largeImpactSfx = largeImpactSfx; actuator.largeImpactSfxThreshold = largeImpactSfxThreshold; actuator.debug = debug; } // apply fire damage applicator if (fireApplyDamage) { var actuator = rigidbodyGo.AddComponent <FlameDamageActuator>(); actuator.fireRate = fireRate; actuator.fireDamageDelay = fireDamageDelay; //actuator.plume = plume; //actuator.sparks = sparks; actuator.burntMaterial = burntMaterial; actuator.burnThreshold = burnThreshold; actuator.explodeThreshold = explodeThreshold; actuator.debug = debug; } }
public override void Apply(PartConfig config, GameObject target) { if (target == null) { return; } // find rigid body gameobject under target var rigidbodyGo = PartUtil.GetBodyGo(target); if (rigidbodyGo == null) { return; } // add damage modifier var modifier = rigidbodyGo.AddComponent <ImpactDamageModifier>(); modifier.impactDamageMultiplier = impactDamageMultiplier; }
public override void Apply(PartConfig config, GameObject target) { if (target == null) { return; } // find rigid body gameobject under target var rigidbodyGo = PartUtil.GetBodyGo(target); if (rigidbodyGo == null) { return; } // add health component var actuator = rigidbodyGo.AddComponent <MaterialActuator>(); actuator.materials = materials; actuator.debug = debug; }
public override void Apply(PartConfig config, GameObject target) { if (target == null) { return; } // find rigid body gameobject under target var rigidbodyGo = PartUtil.GetBodyGo(target); if (rigidbodyGo == null) { return; } // add health component var health = rigidbodyGo.AddComponent <Health>(); health.maxHealth = (int)maxHealth; health.healthTag = healthTag; health.debug = debug; }
public GameObject Build( PartConfig config, GameObject root, string label ) { GameObject partGo = null; // instantiate part if (part != null) { partGo = part.Build(config, root, label != null ? label : part.name); if (partGo == null) { return(null); } partGo.transform.localPosition = offset; partGo.transform.localEulerAngles = rotation; } // joint specifies how part is to be attached to root, if specified, apply joint and join to root if (joint != null && partGo != null) { var partBodyGo = PartUtil.GetBodyGo(partGo); if (partBodyGo != null) { joint.Apply(config, partBodyGo); var joiner = partBodyGo.GetComponent <Joiner>(); var rootBodyGo = PartUtil.GetBodyGo(root); if (joiner != null && rootBodyGo != null) { joiner.Join(rootBodyGo.GetComponent <Rigidbody>()); } } } return(partGo); }
public override GameObject Build( PartConfig config, GameObject root, string label ) { GameObject partsGo = null; GameObject bodyGo = null; Vector3 rotation = Vector3.zero; Vector3 offset = Vector3.zero; if (label == null || label == "") { label = name; } // compute merged config for root var mergedConfig = PartConfig.Merge(this.config, config); // for a bot, we want to attach rigidbody for frame directly to root // only do this in-game, not for in-editor preview if (root != null && Application.isPlaying) { if (root.GetComponent <Rigidbody>() == null) { root.AddComponent <Rigidbody>(); } if (root.GetComponent <KeepInBounds>() == null) { root.AddComponent <KeepInBounds>(); } bodyGo = root; // apply part properties if (mass != null) { mass.Apply(mergedConfig, root); } if (health != null) { health.Apply(mergedConfig, root); } if (damage != null) { damage.Apply(mergedConfig, root); } // apply applicators to parts container if (applicators != null) { for (var i = 0; i < applicators.Length; i++) { if (applicators[i] != null) { applicators[i].Apply(mergedConfig, root); } } } //PartUtil.ApplyRigidBodyProperties(bodyGo, mass, drag, angularDrag); // empty parts object to parent the rest of the bot partsGo = PartUtil.BuildGo(mergedConfig, null, label + ".parts"); partsGo.transform.position = root.transform.position; partsGo.transform.rotation = root.transform.rotation; // keep track of parent/child links var childLink = root.AddComponent <ChildLink>(); childLink.childGo = partsGo; var parentLink = partsGo.AddComponent <ParentLink>(); parentLink.parentGo = root; // otherwise, instantiate rigidbody/parts as a normal part } else { // build out frame model first partsGo = base.Build(mergedConfig, root, label); if (partsGo != null) { // set local position to match that of root bodyGo = partsGo.transform.Find(partsGo.name + ".body").gameObject; } } // frame is instantiated under parts.body if (frame != null) { frame.Build(mergedConfig, bodyGo, "frame"); } // now build out modules if (modules != null) { for (var i = 0; i < modules.Length; i++) { if (modules[i] != null && modules[i].part != null) { // build the module under the top level parts var moduleGo = modules[i].part.Build(PartConfig.Merge(modules[i].config, config), partsGo, modules[i].label); if (moduleGo != null) { var moduleBodyGo = PartUtil.GetBodyGo(moduleGo); if (moduleBodyGo != null) { // connect module to the var joiner = moduleBodyGo.GetComponent <Joiner>(); if (joiner != null) { joiner.Join(bodyGo.GetComponent <Rigidbody>()); } } } } } } return(partsGo); }