public override void Instantiate(Part p) { Part = p; Debug.Log("# Instantiating prop hatch for part " + p); if (IvaGameObject != null) { Debug.LogError("[FreeIVA] Hatch has already been instantiated."); return; } GetProp(); IvaGameObject = ClosedProp.gameObject; IvaGameObject.layer = (int)Layers.InternalSpace; PropHatches.Add(this); if (Collider != null) { Collider.Instantiate(p); ModuleFreeIva mfi = p.GetModule <ModuleFreeIva>(); if (mfi != null) { mfi.InternalColliders.Add(Collider); } } SetupAudio(); }
/// <summary> /// Gets a list of parts that have /// </summary> /// <returns></returns> private static List <Part> GetVisibleParts(Part part, ref List <Part> visibleParts) { ModuleFreeIva iva = part.GetModule <ModuleFreeIva>(); if (iva != null) { if (!visibleParts.Contains(part)) { visibleParts.Add(part); } for (int i = 0; i < iva.Hatches.Count; i++) { Hatch h = iva.Hatches[i]; if (h.IsOpen && h.ConnectedHatch != null && h.ConnectedHatch.IsOpen && h.ConnectedHatch.Part != null && !visibleParts.Contains(h.ConnectedHatch.Part)) { visibleParts.AddRange(GetVisibleParts(h.ConnectedHatch.Part, ref visibleParts)); } } } return(visibleParts); }
private void GetConnectedHatch() { AttachNode hatchNode = GetHatchNode(AttachNodeId); if (hatchNode == null) { return; } ModuleFreeIva iva = hatchNode.attachedPart.GetModule <ModuleFreeIva>(); if (iva == null) { return; } for (int i = 0; i < iva.Hatches.Count; i++) { AttachNode otherHatchNode = iva.Hatches[i].HatchNode; if (otherHatchNode != null && otherHatchNode.attachedPart != null && otherHatchNode.attachedPart.Equals(Part)) { _connectedHatch = iva.Hatches[i]; break; } } }
public static void InitialiseAllHatchesClosed() { foreach (Part p in FlightGlobals.ActiveVessel.Parts) { ModuleFreeIva mfi = p.GetModule <ModuleFreeIva>(); if (mfi != null) { for (int i = 0; i < mfi.Hatches.Count; i++) { if (mfi.Hatches[i].IvaGameObject != null) { mfi.Hatches[i].IvaGameObjectRenderer = mfi.Hatches[i].IvaGameObject.GetComponent <Renderer>(); // TODO: Why get this every time? } if (mfi.Hatches[i].IvaGameObjectRenderer != null) { mfi.Hatches[i].IvaGameObjectRenderer.enabled = false; } else { //Debug.LogError("[FreeIVA] Hatch " + i + " renderer not found in part " + p); } if (mfi.Hatches[i].Collider != null) { mfi.Hatches[i].Collider.Enable(true); } } } } }
//public override void OnLoad(ConfigNode node) //{ // Hatch h = LoadFromCfg(node); // Instantiate(this.part); //} public override void Instantiate(Part p) { Part = p; Debug.Log("# Creating hatch for part " + p); if (IvaGameObject != null) { Debug.LogError("[FreeIVA] Hatch has already been instantiated."); return; } // These values will be cleared on creating the object. Vector3 scale = Scale; Vector3 localPosition = LocalPosition; Quaternion rotation = Rotation; IvaGameObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder); UnityEngine.Object.Destroy(IvaGameObject.GetComponentCached(ref IvaGameObjectCollider)); if (p.internalModel == null) { p.CreateInternalModel(); // TODO: Detect this in an event instead. } IvaGameObject.transform.parent = p.internalModel.transform; IvaGameObject.layer = (int)Layers.InternalSpace; // Restore cleared values. Scale = scale; LocalPosition = localPosition; Rotation = rotation; IvaGameObject.transform.localScale = scale; IvaGameObject.transform.localPosition = localPosition; IvaGameObject.transform.localRotation = rotation; IvaGameObject.name = Name; if (Collider != null) { Collider.Instantiate(p); ModuleFreeIva mfi = p.GetModule <ModuleFreeIva>(); if (mfi != null) { mfi.InternalColliders.Add(Collider); } } Shader depthMask = Utils.GetDepthMask(); if (depthMask != null) { IvaGameObjectRenderer.material.shader = depthMask; } IvaGameObjectRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; ChangeMesh(IvaGameObject); SetupAudio(); //IvaGameObject.renderer.enabled = false; Gets reenabled by EnableInternals. }
public static void CloseAllHatches() { foreach (Part p in FlightGlobals.ActiveVessel.Parts) { ModuleFreeIva mfi = p.GetModule <ModuleFreeIva>(); if (mfi != null) { for (int i = 0; i < mfi.Hatches.Count; i++) { mfi.Hatches[i].IvaGameObject.renderer.enabled = false; mfi.Hatches[i].Collider.Enable(true); } } } }
public static void HideAllColliders() { foreach (Part p in FlightGlobals.ActiveVessel.Parts) { ModuleFreeIva mfi = p.GetModule <ModuleFreeIva>(); if (mfi != null) { for (int i = 0; i < mfi.InternalColliders.Count; i++) { if (!mfi.InternalColliders[i].AlwaysVisible) { mfi.InternalColliders[i].Visible = false; } } } } }
// TODO: Replace this with clickable interaction colliders. public void TargetHatches() { if (FreeIva.CurrentModuleFreeIva == null) { return; } Hatch targetedHatch = null; float closestDistance = Settings.MaxInteractDistance; if (FreeIva.CurrentModuleFreeIva.Hatches.Count != 0) { //for (int i = 0; i < CurrentModuleFreeIva.Hatches.Count; i++) foreach (Hatch h in FreeIva.CurrentModuleFreeIva.Hatches) { if (IsTargeted(h.WorldPosition)) { float distance = Vector3.Distance(h.WorldPosition, InternalCamera.Instance.transform.position); if (distance < closestDistance) { targetedHatch = h; closestDistance = distance; } } } } else { // Part has no hatches but does have a ModuleFreeIva. Passable part without hatches, like a tube. // TODO: Restrict this to node attachments? ModuleFreeIva parentModule = FreeIva.CurrentPart.parent.GetModule <ModuleFreeIva>(); if (parentModule != null) { foreach (Hatch h in parentModule.Hatches) { if (IsTargeted(h.WorldPosition)) { float distance = Vector3.Distance(h.WorldPosition, InternalCamera.Instance.transform.position); if (distance < closestDistance) { targetedHatch = h; closestDistance = distance; } } } } foreach (Part child in FreeIva.CurrentPart.children) { ModuleFreeIva childModule = child.GetModule <ModuleFreeIva>(); if (childModule == null) { continue; } foreach (Hatch h in childModule.Hatches) { if (IsTargeted(h.WorldPosition)) { float distance = Vector3.Distance(h.WorldPosition, InternalCamera.Instance.transform.position); if (distance < closestDistance) { targetedHatch = h; closestDistance = distance; } } } } } if (targetedHatch != null) { ScreenMessages.PostScreenMessage((targetedHatch.IsOpen ? "Close" : "Open") + " hatch [" + Settings.OpenHatchKey + "]", 0.1f, ScreenMessageStyle.LOWER_CENTER); if (Input.GetKeyDown(Settings.OpenHatchKey) && !Input.GetKey(Settings.ModifierKey)) { targetedHatch.ToggleHatch(); } // Allow reaching through an open hatch to open or close the connected hatch. if (targetedHatch.IsOpen && targetedHatch.ConnectedHatch != null && IsTargeted(targetedHatch.ConnectedHatch.WorldPosition)) { float distance = Vector3.Distance(targetedHatch.ConnectedHatch.WorldPosition, InternalCamera.Instance.transform.position); if (distance < Settings.MaxInteractDistance) { ScreenMessages.PostScreenMessage((targetedHatch.ConnectedHatch.IsOpen ? "Close" : "Open") + " far hatch [" + Settings.ModifierKey + " + " + Settings.OpenHatchKey + "]", 0.1f, ScreenMessageStyle.LOWER_CENTER); if (Input.GetKeyDown(Settings.OpenHatchKey) && Input.GetKey(Settings.ModifierKey)) { targetedHatch.ConnectedHatch.ToggleHatch(); } } } } }