Example #1
0
        // 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;
            }
        }