// Find the prop in the IVA. If not present, spawn it. private void GetProp() { // Find the existing prop. InternalProp closedHatch = this.Part.internalModel.props[ClosedPropIndex]; if (closedHatch == null) { // Spawn a new prop. closedHatch = PartLoader.GetInternalProp(this.ClosedPropName); if (closedHatch == null) { Debug.LogError("[FreeIVA] Unable to load closed prop hatch \"" + this.ClosedPropName + "\" in part " + this.Part.name); } else { closedHatch.propID = FreeIva.CurrentPart.internalModel.props.Count; closedHatch.internalModel = this.Part.internalModel; closedHatch.transform.parent = this.Part.internalModel.transform; closedHatch.transform.gameObject.layer = (int)Layers.InternalSpace; closedHatch.hasModel = true; this.Part.internalModel.props.Add(closedHatch); closedHatch.transform.localRotation = this.Rotation; closedHatch.transform.localPosition = this.LocalPosition; } } else if (closedHatch.name != ClosedPropName) { Debug.LogError($"[FreeIVA] Prop at closedPropIndex {ClosedPropIndex} didn't match expected closedPropName {ClosedPropName}."); } MeshRenderer mrC = closedHatch.GetComponentInChildren <MeshRenderer>(); mrC.enabled = true; ClosedProp = closedHatch; InternalProp openHatch = PartLoader.GetInternalProp(this.OpenPropName); if (openHatch == null) { Debug.LogError("[FreeIVA] Unable to load open prop hatch \"" + this.OpenPropName + "\" in part " + this.Part.name); } else { Debug.Log("# Adding PropHatch to part " + this.Part.name); openHatch.propID = FreeIva.CurrentPart.internalModel.props.Count; openHatch.internalModel = this.Part.internalModel; openHatch.transform.parent = this.Part.internalModel.transform; openHatch.hasModel = true; this.Part.internalModel.props.Add(openHatch); openHatch.transform.rotation = this.Rotation; openHatch.transform.localPosition = this.LocalPosition; MeshRenderer[] mrO = openHatch.GetComponentsInChildren <MeshRenderer>(); if (mrO != null && mrO.Length > 0) { mrO[0].enabled = false; } OpenProp = openHatch; } }
// Can be safely called multiple times for the same part. public static void AddPropHatches(InternalModel internalModel) { Debug.Log("# Adding prop hatch for " + internalModel.part); if (internalModel == null) { Debug.LogWarning("Unable to create prop hatches: internal model was null"); return; } int propCount = internalModel.props.Count; // This list will be added to in the loop below. for (int i = 0; i < propCount; i++) { InternalProp prop = internalModel.props[i]; if (prop.name == "Hatch_Plane" && !HatchInitialised(prop)) // TODO: Generalise this. { Debug.Log("# Found Hatch_Plane"); InternalProp openHatch = PartLoader.GetInternalProp("Hatch_Plane_Frame"); openHatch.propID = FreeIva.CurrentPart.internalModel.props.Count; openHatch.internalModel = FreeIva.CurrentPart.internalModel; //openHatch.get_transform().set_parent(base.get_transform()); TODO: Set parent openHatch.hasModel = true; internalModel.props.Add(openHatch); openHatch.transform.rotation = prop.transform.rotation; openHatch.transform.position = prop.transform.position; MeshRenderer mr = openHatch.GetComponentInChildren <MeshRenderer>(); mr.enabled = false; PropHatch propHatch = new PropHatch(); propHatch.ClosedProp = prop; propHatch.OpenProp = openHatch; PropHatches.Add(propHatch); } } }