public virtual GameObject Build( PartConfig config, GameObject root, string label ) { if (label == null || label == "") { label = name; } // creation check -- ensure part we are about to build is not a direct parent already in tree if (PartUtil.PartInParent(root, this)) { Debug.Log("detected part loop/invalid part chain, part: " + name + " already instantiated in parent"); return(null); } // create empty parts container var partsGo = PartUtil.BuildGo(config, root, label); var partId = partsGo.AddComponent <PartId>(); partId.partId = this.GetInstanceID(); // create new rigid body for this part, set parts container as parent var rigidbodyGo = PartUtil.BuildGo(config, partsGo, label + ".body", typeof(Rigidbody), typeof(KeepInBounds)); //PartUtil.ApplyRigidBodyProperties(rigidbodyGo, mass, drag, angularDrag); // apply part properties if (mass != null) { mass.Apply(config, partsGo); } if (health != null) { health.Apply(config, partsGo); } if (damage != null) { damage.Apply(config, partsGo); } // apply applicators to parts container if (applicators != null) { for (var i = 0; i < applicators.Length; i++) { if (applicators[i] != null) { applicators[i].Apply(config, partsGo); } } } // instantiate model under rigid body if (models != null) { for (var i = 0; i < models.Length; i++) { models[i].Build(config, rigidbodyGo, label + ".model"); } } // instantiate connected parts if (connectedParts != null && connectedParts.Length > 0) { for (var i = 0; i < connectedParts.Length; i++) { // check for self-references var childGo = connectedParts[i].Build(config, partsGo, label + ".part"); if (childGo != null) { // join child part to current rigidbody var joiner = childGo.GetComponent <Joiner>(); if (joiner != null) { joiner.Join(rigidbodyGo.GetComponent <Rigidbody>()); } } } } return(partsGo); }