//static bool _initialised = false; public static void EnableInternals() { try { //if (_initialised) return; foreach (Part p in FlightGlobals.ActiveVessel.parts) { if (p.internalModel == null) { p.CreateInternalModel(); } if (p.internalModel != null) { p.internalModel.SetVisible(true); PropHatch.AddPropHatches(p.internalModel); //PrintInternals(p); } } // TODO InternalCollider.HideAllColliders(); // TODO Hatch.InitialiseAllHatchesClosed(); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // Colliders, hatches and hatch props are all unhidden by this. //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //_initialised = true; } catch (Exception ex) { Debug.LogError("[FreeIVA] Error enabling internals: " + ex.Message + ", " + ex.StackTrace); } }
// 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); } } }
public static PropHatch LoadPropHatchFromCfg(ConfigNode node) { Vector3 position = Vector3.zero; Vector3 scale = Vector3.one; if (!node.HasValue("closedPropIndex")) { Debug.LogWarning("[FreeIVA] Prop hatch closedPropIndex not found: Skipping hatch."); return(null); } PropHatch propHatch = new PropHatch(); propHatch.ClosedPropIndex = int.Parse(node.GetValue("closedPropIndex")); if (node.HasValue("closedPropName")) { propHatch.ClosedPropName = node.GetValue("closedPropName"); } if (node.HasValue("openPropName")) { propHatch.OpenPropName = node.GetValue("openPropName"); } if (node.HasValue("attachNodeId")) { propHatch.AttachNodeId = node.GetValue("attachNodeId"); } if (node.HasValue("position")) { string posString = node.GetValue("position"); string[] p = posString.Split(Utils.CfgSplitChars, StringSplitOptions.RemoveEmptyEntries); if (p.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid prop hatch position definition \"" + posString + "\": Must be in the form x, y, z."); return(null); } else { propHatch.LocalPosition = new Vector3(float.Parse(p[0]), float.Parse(p[1]), float.Parse(p[2])); } } else { Debug.LogWarning("[FreeIVA] PropHatch does not have a position"); } Debug.Log("# PropHatch position: " + propHatch.LocalPosition); if (node.HasValue("scale")) { string scaleString = node.GetValue("scale"); string[] s = scaleString.Split(Utils.CfgSplitChars, StringSplitOptions.RemoveEmptyEntries); if (s.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid prop hatch scale definition \"" + scaleString + "\": Must be in the form x, y, z."); return(null); } else { propHatch.Scale = new Vector3(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2])); } } if (node.HasValue("rotation")) { string rotationString = node.GetValue("rotation"); string[] s = rotationString.Split(Utils.CfgSplitChars, StringSplitOptions.RemoveEmptyEntries); if (s.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid prop hatch rotation definition \"" + rotationString + "\": Must be in the form x, y, z."); return(null); } else { propHatch.Rotation = Quaternion.Euler(float.Parse(s[0]), float.Parse(s[1]), float.Parse(s[2])); } } if (node.HasValue("HatchOpenSoundFile")) { propHatch.HatchOpenSoundFile = node.GetValue("HatchOpenSoundFile"); } if (node.HasValue("HatchCloseSoundFile")) { propHatch.HatchCloseSoundFile = node.GetValue("HatchCloseSoundFile"); } if (node.HasNode("HideWhenOpen")) { ConfigNode[] hideNodes = node.GetNodes("HideWhenOpen"); foreach (var hideNode in hideNodes) { if (!hideNode.HasValue("name")) { Debug.LogWarning("[FreeIVA] HideWhenOpen name not found."); continue; } string propName = hideNode.GetValue("name"); if (hideNode.HasValue("position")) { string posString = hideNode.GetValue("position"); string[] p = posString.Split(Utils.CfgSplitChars, StringSplitOptions.RemoveEmptyEntries); if (p.Length != 3) { Debug.LogWarning("[FreeIVA] Invalid HideWhenOpen position definition \"" + posString + "\": Must be in the form x, y, z."); continue; } else { Vector3 propPos = new Vector3(float.Parse(p[0]), float.Parse(p[1]), float.Parse(p[2])); propHatch.HideWhenOpen.Add(new KeyValuePair <Vector3, string>(propPos, propName)); } } } } if (node.HasNode("InternalCollider")) { ConfigNode hatchColliderNode = node.GetNode("InternalCollider"); if (hatchColliderNode != null) { propHatch.Collider = InternalCollider.LoadFromCfg(hatchColliderNode); } } return(propHatch); }
public override void OnLoad(ConfigNode node) { if (node.HasNode("Hatch")) { ConfigNode[] hatchNodes = node.GetNodes("Hatch"); foreach (var hn in hatchNodes) { IHatch h = Hatch.LoadFromCfg(hn); if (h != null) { Hatches.Add(h); } } PersistenceManager.instance.AddHatches(part.name, Hatches); } Debug.Log("# Hatches loaded from config for part " + part.name + ": " + Hatches.Count); if (node.HasNode("PropHatch")) { ConfigNode[] propHatchNodes = node.GetNodes("PropHatch"); foreach (var phn in propHatchNodes) { PropHatch ph = PropHatch.LoadPropHatchFromCfg(phn); if (ph != null) { Hatches.Add(ph); } } PersistenceManager.instance.AddHatches(part.name, Hatches); } if (node.HasNode("MeshHatch")) { ConfigNode[] meshHatchNodes = node.GetNodes("MeshHatch"); foreach (var mhn in meshHatchNodes) { MeshHatch mh = MeshHatch.LoadMeshHatchFromCfg(mhn); if (mh != null) { Hatches.Add(mh); } } PersistenceManager.instance.AddHatches(part.name, Hatches); } //if (node.HasNode("PropHatchAnimated")) //{ // ConfigNode[] propHatchAnimatedNodes = node.GetNodes("PropHatchAnimated"); // foreach (var phan in propHatchAnimatedNodes) // { // PropHatchAnimated pha = PropHatchAnimated.LoadPropHatchFromCfg(phan); // if (pha != null) // { // Hatches.Add(pha); // if (pha.Collider != null) // InternalColliders.Add(pha.Collider); // } // } // PersistenceManager.instance.AddHatches(part.name, Hatches); //} Debug.Log("# Hatches loaded from config for part " + part.name + ": " + Hatches.Count); if (node.HasNode("InternalCollider")) { ConfigNode[] colliderNodes = node.GetNodes("InternalCollider"); foreach (var cn in colliderNodes) { InternalCollider ic = InternalCollider.LoadFromCfg(cn); if (ic != null) { InternalColliders.Add(ic); } } PersistenceManager.instance.AddInternalColliders(part.name, InternalColliders); Debug.Log("# Internal colliders loaded from config for part " + part.name + ": " + InternalColliders.Count); } else if (InternalColliders != null && InternalColliders.Count > 0) { PersistenceManager.instance.AddInternalColliders(part.name, InternalColliders); Debug.Log("# Internal colliders loaded from config for part " + part.name + ": " + InternalColliders.Count); } }