public static KASModuleWinch GetConnectedWinch(Part p) { KASModulePort portModule = p.GetComponent<KASModulePort>(); if (!portModule) { return null; } return portModule.winchConnected; }
public void ContextMenuLink() { KASModulePort portModule = this.part.GetComponent <KASModulePort>(); if (portModule && portModule.plugged) { ScreenMessages.PostScreenMessage("Cannot link, port is already used", 5, ScreenMessageStyle.UPPER_CENTER); return; } KASModuleStrut EvaLinkedStrutModule = GetEvaLinkedStrutModule(FlightGlobals.ActiveVessel); if (EvaLinkedStrutModule) { if (EvaLinkedStrutModule.LinkTo(this)) { fxSndLink.audio.Play(); } } else { SetEvaLink(); ScreenMessages.PostScreenMessage("Link mode enabled, press Escape or Enter to cancel", 10, ScreenMessageStyle.UPPER_CENTER); } }
public void Update() { if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.K)) { if (GuiConfigToogle) { Debug.Log("KASAddonDebugMenu - Closing KAS debug tools"); GuiConfigToogle = false; } else { Debug.Log("KASAddonDebugMenu - Opening KAS debug tools"); GuiConfigToogle = true; } } if (GuiConfigToogle) { if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Mouse0)) { Debug.Log("KASAddonDebugMenu - On click"); clickedPart = KAS_Shared.GetPartUnderCursor(); if (clickedPart) { moduleWinch = null; moduleGrab = null; moduleMagnet = null; moduleSuctionCup = null; moduleGrapple = null; moduleTimedBomb = null; modulePort = null; moduleAnchor = null; moduleStrut = null; moduleRotor = null; moduleWinch = clickedPart.GetComponent<KASModuleWinch>(); moduleGrab = clickedPart.GetComponent<KASModuleGrab>(); moduleMagnet = clickedPart.GetComponent<KASModuleMagnet>(); moduleSuctionCup = clickedPart.GetComponent<KASModuleSuctionCup>(); moduleGrapple = clickedPart.GetComponent<KASModuleGrapplingHook>(); moduleTimedBomb = clickedPart.GetComponent<KASModuleTimedBomb>(); modulePort = clickedPart.GetComponent<KASModulePort>(); moduleAnchor = clickedPart.GetComponent<KASModuleAnchor>(); moduleStrut = clickedPart.GetComponent<KASModuleStrut>(); moduleRotor = clickedPart.GetComponent<KASModuleRotor>(); } } } if (FlightGlobals.ActiveVessel.heightFromTerrain == -1f) { if (FlightGlobals.ActiveVessel.Landed) { KAS_Shared.DebugWarning("Warning ! ActiveVessel is landed and heightFromTerrain are negative (" + FlightGlobals.ActiveVessel.heightFromTerrain + ")"); } } }
public void Update() { if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.K)) { if (GuiConfigToogle) { Debug.Log("KASAddonDebugMenu - Closing KAS debug tools"); GuiConfigToogle = false; } else { Debug.Log("KASAddonDebugMenu - Opening KAS debug tools"); GuiConfigToogle = true; } } if (GuiConfigToogle) { if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Mouse0)) { Debug.Log("KASAddonDebugMenu - On click"); clickedPart = KAS_Shared.GetPartUnderCursor(); if (clickedPart) { moduleWinch = null; moduleGrab = null; moduleMagnet = null; moduleSuctionCup = null; moduleGrapple = null; moduleTimedBomb = null; modulePort = null; moduleAnchor = null; moduleStrut = null; moduleRotor = null; moduleWinch = clickedPart.GetComponent <KASModuleWinch>(); moduleGrab = clickedPart.GetComponent <KASModuleGrab>(); moduleMagnet = clickedPart.GetComponent <KASModuleMagnet>(); moduleSuctionCup = clickedPart.GetComponent <KASModuleSuctionCup>(); moduleGrapple = clickedPart.GetComponent <KASModuleGrapplingHook>(); moduleTimedBomb = clickedPart.GetComponent <KASModuleTimedBomb>(); modulePort = clickedPart.GetComponent <KASModulePort>(); moduleAnchor = clickedPart.GetComponent <KASModuleAnchor>(); moduleStrut = clickedPart.GetComponent <KASModuleStrut>(); moduleRotor = clickedPart.GetComponent <KASModuleRotor>(); } } } if (FlightGlobals.ActiveVessel.heightFromTerrain == -1f) { if (FlightGlobals.ActiveVessel.Landed) { KAS_Shared.DebugWarning("Warning ! ActiveVessel is landed and heightFromTerrain are negative (" + FlightGlobals.ActiveVessel.heightFromTerrain + ")"); } } }
public void DropHead() { if (!evaHolderPart) { KAS_Shared.DebugWarning("DropHead(Winch) - Nothing to drop !"); return; } Collider evaCollider = KAS_Shared.GetEvaCollider(evaHolderPart.vessel, "jetpackCollider"); KAS_Shared.MoveRelatedTo(headTransform, evaCollider.transform, evaDropHeadPos, evaDropHeadRot); SetHeadToPhysic(true); SetCableJointConnectedBody(headTransform.rigidbody); if (evaHeadNodeTransform) Destroy(evaHeadNodeTransform.gameObject); grabbedPortModule = null; release.active = false; cableJointLength = cableRealLenght; evaHolderPart = null; evaHeadNodeTransform = null; }
public void GrabHead(Vessel kerbalEvaVessel, KASModulePort grabbedPort = null) { KAS_Shared.DebugLog("GrabHead(Winch) Grabbing part"); //Drop already grabbed head KASModuleWinch tmpGrabbbedHead = KAS_Shared.GetWinchModuleGrabbed(kerbalEvaVessel); if (tmpGrabbbedHead) { KAS_Shared.DebugLog("GrabHead(Winch) - Drop current grabbed head"); tmpGrabbbedHead.DropHead(); } if (headState == PlugState.PlugDocked || headState == PlugState.PlugUndocked) { KAS_Shared.DebugLog("GrabHead(Winch) - Unplug head"); UnplugHead(); } if (headState == PlugState.Locked) { KAS_Shared.DebugLog("GrabHead(Winch) - Deploy head"); Deploy(); } evaCollider = KAS_Shared.GetEvaCollider(kerbalEvaVessel, "jetpackCollider"); evaHeadNodeTransform = new GameObject("KASEvaHeadNode").transform; evaHeadNodeTransform.parent = evaCollider.transform; evaHeadNodeTransform.localPosition = evaGrabHeadPos; evaHeadNodeTransform.rotation = KAS_Shared.DirectionToQuaternion(evaCollider.transform, evaGrabHeadDir); SetHeadToPhysic(false); grabbedPortModule = grabbedPort; if (grabbedPort) { KAS_Shared.DebugLog("GrabHead(Winch) - Moving head to grabbed port node..."); headTransform.rotation = Quaternion.FromToRotation(headPortNode.forward, -grabbedPort.portNode.forward) * headTransform.rotation; headTransform.position = headTransform.position - (headPortNode.position - grabbedPort.portNode.position); } else { KAS_Shared.DebugLog("GrabHead(Winch) - Moving head to eva node..."); KAS_Shared.MoveAlign(headTransform, headPortNode, evaHeadNodeTransform); } // Parent eva to head for moving eva with the head kerbalEvaVessel.rootPart.transform.parent = headTransform; // Set cable joint connected body to eva SetCableJointConnectedBody(kerbalEvaVessel.rootPart.rigidbody); // Unparent eva to head kerbalEvaVessel.rootPart.transform.parent = null; headTransform.parent = evaHeadNodeTransform; cableJointLength = cableRealLenght; evaHolderPart = kerbalEvaVessel.rootPart; release.active = true; fxSndHeadGrab.audio.Play(); }
public void PlugHead(KASModulePort portModule, PlugState plugMode, bool fromSave = false, bool fireSound = true, bool alreadyDocked = false) { if (plugMode == PlugState.Locked || plugMode == PlugState.Deployed) return; if (!alreadyDocked) { if (portModule.strutConnected()) { ScreenMessages.PostScreenMessage(portModule.part.partInfo.title + " is already used !", 5, ScreenMessageStyle.UPPER_CENTER); return; } if (portModule.plugState == KASModulePort.KASPlugState.PlugDock || portModule.plugState == KASModulePort.KASPlugState.PlugUndock) { ScreenMessages.PostScreenMessage(portModule.part.partInfo.title + " is already used !", 5, ScreenMessageStyle.UPPER_CENTER); return; } if (this.part.vessel == portModule.part.vessel && fromSave == false) { plugMode = PlugState.PlugUndocked; } } if (!cableJoint) Deploy(); DropHead(); if (plugMode == PlugState.PlugUndocked) { KAS_Shared.DebugLog("PlugHead(Winch) - Plug using undocked mode"); headState = PlugState.PlugUndocked; if (fireSound) portModule.fxSndPlug.audio.Play(); } if (plugMode == PlugState.PlugDocked) { KAS_Shared.DebugLog("PlugHead(Winch) - Plug using docked mode"); // This should be safe even if already connected AttachDocked(portModule); // Remove joints between connector and winch KAS_Shared.RemoveAttachJointBetween(this.part, portModule.part); headState = PlugState.PlugDocked; //nodeConnectedPort = portModule; if (fireSound) portModule.fxSndPlugDocked.audio.Play(); } KAS_Shared.DebugLog("PlugHead(Winch) - Moving head..."); headTransform.rotation = Quaternion.FromToRotation(headPortNode.forward, -portModule.portNode.forward) * headTransform.rotation; headTransform.position = headTransform.position - (headPortNode.position - portModule.portNode.position); SetHeadToPhysic(false); // Parent port to head for moving port with the head portModule.part.transform.parent = headTransform; // Set cable joint connected body to eva SetCableJointConnectedBody(portModule.part.rigidbody); // Unparent eva to head portModule.part.transform.parent = null; headTransform.parent = portModule.part.transform; cableJointLength = cableRealLenght + 0.01f; // Set variables connectedPortInfo.module = portModule; portModule.winchConnected = this; }
void OnGUI() { if (!clickedWinch) { return; } GUI.skin = HighLogic.Skin; GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUI.skin.button.alignment = TextAnchor.MiddleCenter; guiButtonStyle = new GUIStyle(GUI.skin.button); guiButtonStyle.normal.textColor = guiButtonStyle.focused.textColor = Color.white; guiButtonStyle.hover.textColor = guiButtonStyle.active.textColor = Color.yellow; guiButtonStyle.onNormal.textColor = guiButtonStyle.onFocused.textColor = guiButtonStyle.onHover.textColor = guiButtonStyle.onActive.textColor = Color.green; guiButtonStyle.padding = new RectOffset(4, 4, 4, 4); guiButtonStyle.alignment = TextAnchor.MiddleCenter; Vector3 headScreenPoint = Camera.main.WorldToScreenPoint(clickedWinch.headTransform.position); GUILayout.BeginArea(new Rect(headScreenPoint.x, Screen.height - headScreenPoint.y, 200, 200)); GUILayout.BeginVertical(); if (clickedWinch.evaHolderPart) { if (GUILayout.Button("Drop (Key " + grabHeadKey + ")", guiButtonStyle, GUILayout.Width(100f))) { clickedWinch.DropHead();; clickedWinch = null; } } else { if (GUILayout.Button("Grab (Key " + grabHeadKey + ")", guiButtonStyle, GUILayout.Width(100f))) { clickedWinch.GrabHead(FlightGlobals.ActiveVessel); clickedWinch = null; } if (clickedWinch) { if (clickedWinch.headState == KASModuleWinch.PlugState.Deployed) { KASModuleGrab grabbedModule = KAS_Shared.GetGrabbedPartModule(FlightGlobals.ActiveVessel); if (grabbedModule) { KASModulePort grabbedPort = grabbedModule.GetComponent <KASModulePort>(); if (grabbedPort) { if (GUILayout.Button("Plug grabbed", guiButtonStyle, GUILayout.Width(100f))) { grabbedModule.Drop(); grabbedPort.transform.rotation = Quaternion.FromToRotation(grabbedPort.portNode.forward, -clickedWinch.headPortNode.forward) * grabbedPort.transform.rotation; grabbedPort.transform.position = grabbedPort.transform.position - (grabbedPort.portNode.position - clickedWinch.headPortNode.position); clickedWinch.PlugHead(grabbedPort, KASModuleWinch.PlugState.PlugDocked); clickedWinch = null; } } } } } } GUILayout.EndHorizontal(); GUILayout.EndArea(); }
public void PlugHead(KASModulePort portModule, PlugState plugMode, bool fromSave = false, bool fireSound = true, bool alreadyDocked = false) { if (plugMode == PlugState.Locked || plugMode == PlugState.Deployed) { return; } if (!alreadyDocked && !fromSave) { if (portModule.strutConnected()) { ScreenMessages.PostScreenMessage( string.Format("{0} is already used !", portModule.part.partInfo.title), 5, ScreenMessageStyle.UPPER_CENTER); return; } if (portModule.plugged) { ScreenMessages.PostScreenMessage( string.Format("{0} is already used !", portModule.part.partInfo.title), 5, ScreenMessageStyle.UPPER_CENTER); return; } if (this.part.vessel == portModule.part.vessel) { plugMode = PlugState.PlugUndocked; } } if (!cableJoint) { Deploy(); } DropHead(); if (plugMode == PlugState.PlugUndocked) { KAS_Shared.DebugLog("PlugHead(Winch) - Plug using undocked mode"); headState = PlugState.PlugUndocked; if (fireSound) { AudioSource.PlayClipAtPoint(GameDatabase.Instance.GetAudioClip(portModule.plugSndPath), portModule.part.transform.position); } } if (plugMode == PlugState.PlugDocked) { KAS_Shared.DebugLog("PlugHead(Winch) - Plug using docked mode"); // This should be safe even if already connected AttachDocked(portModule); // Set attached part portModule.part.FindAttachNode(portModule.attachNode).attachedPart = this.part; this.part.FindAttachNode(connectedPortNodeName).attachedPart = portModule.part; // Remove joints between connector and winch KAS_Shared.RemoveAttachJointBetween(this.part, portModule.part); headState = PlugState.PlugDocked; if (fireSound) { AudioSource.PlayClipAtPoint( GameDatabase.Instance.GetAudioClip(portModule.plugDockedSndPath), portModule.part.transform.position); } // Kerbal Joint Reinforcement compatibility GameEvents.onPartUndock.Fire(portModule.part); } KAS_Shared.DebugLog("PlugHead(Winch) - Moving head..."); headTransform.rotation = Quaternion.FromToRotation(headPortNode.forward, -portModule.portNode.forward) * headTransform.rotation; headTransform.position = headTransform.position - (headPortNode.position - portModule.portNode.position); SetHeadToPhysic(false); SetCableJointConnectedBody(portModule.part.rb); headTransform.parent = portModule.part.transform; cableJointLength = cableRealLenght + 0.01f; // Set variables connectedPortInfo.module = portModule; connectedPortInfo.module.plugged = true; portModule.winchConnected = this; }
public void Grab(Vessel kerbalEvaVessel) { KAS_Shared.DebugLog("Grab - Grabbing part :" + this.part.partInfo.name); //Get eva transform evaCollider = KAS_Shared.GetEvaCollider(kerbalEvaVessel, evaTransformName); if (!evaCollider) { KAS_Shared.DebugLog("Grab - " + evaTransformName + "transform not found on eva !"); return; } //Get attach node if (attachNodeName == null || attachNodeName == "") { if (this.part.srfAttachNode == null) { KAS_Shared.DebugLog("Grab - surface attach node cannot be found on the part !"); return; } KAS_Shared.AddNodeTransform(this.part, this.part.srfAttachNode); partNode = this.part.srfAttachNode; } else { AttachNode an = this.part.findAttachNode(attachNodeName); if (an == null) { KAS_Shared.DebugLog("Grab - " + attachNodeName + " node cannot be found on the part !"); return; } KAS_Shared.AddNodeTransform(this.part, an); partNode = an; } //Send message to other modules base.SendMessage("OnPartGrab", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver); //Drop grabbed part on eva if needed KASModuleGrab tmpGrabbbedPartModule = KAS_Shared.GetGrabbedPartModule(kerbalEvaVessel); if (tmpGrabbbedPartModule) { KAS_Shared.DebugWarning("Grab - Drop current grabbed part"); tmpGrabbbedPartModule.Drop(); } evaNodeTransform = new GameObject("KASEvaNode").transform; evaNodeTransform.parent = evaCollider.transform; evaNodeTransform.localPosition = evaPartPos; evaNodeTransform.rotation = KAS_Shared.DirectionToQuaternion(evaCollider.transform, evaPartDir); KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform); //Grab winch connected head if any KASModuleWinch moduleWinch = KAS_Shared.GetConnectedWinch(this.part); if (moduleWinch) { KASModulePort modulePort = this.part.GetComponent <KASModulePort>(); moduleWinch.UnplugHead(false); moduleWinch.GrabHead(kerbalEvaVessel, modulePort); } List <Collider> allColliders = new List <Collider>(this.part.GetComponentsInChildren <Collider>() as Collider[]); foreach (Collider col in allColliders) { col.isTrigger = true; } Detach(); KAS_Shared.DecoupleFromAll(this.part); this.part.Couple(kerbalEvaVessel.rootPart); //Destroy joint to avoid buggy eva move Destroy(this.part.attachJoint); this.part.rigidbody.velocity = kerbalEvaVessel.rootPart.rigidbody.velocity; if (physicJoint) { if (evaJoint) { Destroy(evaJoint); } evaJoint = this.part.gameObject.AddComponent <FixedJoint>(); evaJoint.connectedBody = evaCollider.attachedRigidbody; evaJoint.breakForce = 5; evaJoint.breakTorque = 5; } else { this.part.physicalSignificance = Part.PhysicalSignificance.NONE; this.part.transform.parent = evaNodeTransform; this.part.rigidbody.isKinematic = true; } //Add grabbed part mass to eva if (addPartMass && !physicJoint) { orgKerbalMass = kerbalEvaVessel.rootPart.mass; kerbalEvaVessel.rootPart.mass += this.part.mass; } evaHolderVesselName = kerbalEvaVessel.vesselName; evaHolderPart = kerbalEvaVessel.rootPart; grabbed = true; RefreshContextMenu(); //Play grab sound fxSndGrab.audio.Play(); base.SendMessage("OnPartGrabbed", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver); }
public void Grab(Vessel kerbalEvaVessel) { KAS_Shared.DebugLog("Grab - Grabbing part :" + this.part.partInfo.name); if (!AlignEvaPosition(kerbalEvaVessel)) { return; } //Grab winch connected head if any KASModuleWinch moduleWinch = KAS_Shared.GetConnectedWinch(this.part); if (moduleWinch) { KASModulePort modulePort = this.part.GetComponent <KASModulePort>(); moduleWinch.UnplugHead(false); moduleWinch.GrabHead(kerbalEvaVessel, modulePort); } keepTriggers = new List <Collider>(); List <Collider> allColliders = new List <Collider>(this.part.GetComponentsInChildren <Collider>() as Collider[]); foreach (Collider col in allColliders) { if (col.isTrigger) { keepTriggers.Add(col); } col.isTrigger = true; } Detach(); if (this.part.vessel != kerbalEvaVessel) { KAS_Shared.DecoupleFromAll(this.part); this.part.Couple(kerbalEvaVessel.rootPart); } else { if (this.part.parent != kerbalEvaVessel.rootPart) { this.part.setParent(null); this.part.setParent(kerbalEvaVessel.rootPart); } this.part.PromoteToPhysicalPart(); } //Destroy joint to avoid buggy eva move Destroy(this.part.attachJoint); this.part.rigidbody.velocity = kerbalEvaVessel.rootPart.rigidbody.velocity; if (physicJoint) { if (evaJoint) { Destroy(evaJoint); } evaJoint = this.part.gameObject.AddComponent <FixedJoint>(); evaJoint.connectedBody = evaCollider.attachedRigidbody; evaJoint.breakForce = 5; evaJoint.breakTorque = 5; KAS_Shared.ResetCollisionEnhancer(this.part); } else { this.part.physicalSignificance = Part.PhysicalSignificance.NONE; this.part.transform.parent = evaNodeTransform; this.part.rigidbody.isKinematic = true; KAS_Shared.ResetCollisionEnhancer(this.part, false); } //Add grabbed part mass to eva if (addPartMass && !physicJoint) { orgKerbalMass = kerbalEvaVessel.rootPart.mass; kerbalEvaVessel.rootPart.mass += this.part.mass; } GameEvents.onCrewBoardVessel.Add(new EventData <GameEvents.FromToAction <Part, Part> > .OnEvent(this.OnCrewBoardVessel)); evaHolderVesselName = kerbalEvaVessel.vesselName; evaHolderPart = kerbalEvaVessel.rootPart; grabbed = true; grab_pending = false; RefreshContextMenu(); //Play grab sound fxSndGrab.audio.Play(); base.SendMessage("OnPartGrabbed", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver); }
private IEnumerator GrabCoroutine(Vessel kerbalEvaVessel) { KAS_Shared.DebugLog("Grab - Grabbing part :" + this.part.partInfo.name); //Send message to other modules base.SendMessage("OnPartGrab", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver); //Set attach node on EVA SetEvaNode(kerbalEvaVessel); //Drop grabbed eva part if any KASModuleGrab grabbbedPartModule = KAS_Shared.GetGrabbedPartModule(kerbalEvaVessel); if (grabbbedPartModule) { grabbbedPartModule.Drop(); } //Unplug winch connected head if any KASModuleWinch moduleWinch = KAS_Shared.GetConnectedWinch(this.part); if (moduleWinch) { moduleWinch.UnplugHead(false); } //Disable all colliders on part DisableColliders(); //Detach if needed Detach(); //Decouple part (if not already done, in case of loading after a save with the part grabbed) if (this.part.vessel != kerbalEvaVessel) { KAS_Shared.DecoupleFromAll(this.part); } //Wait decouple action (x64 fix) yield return(new WaitForFixedUpdate()); //Move part to eva node KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform); //Grab winch connected head if any if (moduleWinch) { KASModulePort modulePort = this.part.GetComponent <KASModulePort>(); moduleWinch.GrabHead(kerbalEvaVessel, modulePort); } //Couple part to eva (if not already done, in case of loading after a save with the part grabbed) if (this.part.vessel != kerbalEvaVessel) { this.part.Couple(kerbalEvaVessel.rootPart); } //Destroy joint to avoid buggy eva move if (this.part.attachJoint) { this.part.attachJoint.DestroyJoint(); } //Set part to physic join or kinematic with parent if (physicJoint) { if (evaJoint) { Destroy(evaJoint); } evaJoint = this.part.gameObject.AddComponent <FixedJoint>(); evaJoint.connectedBody = evaCollider.attachedRigidbody; evaJoint.breakForce = 5; evaJoint.breakTorque = 5; KAS_Shared.ResetCollisionEnhancer(this.part); } else { syncGrab = true; KAS_Shared.ResetCollisionEnhancer(this.part, false); } //Add grabbed part mass to eva if (addPartMass && !physicJoint) { orgKerbalMass = kerbalEvaVessel.rootPart.mass; kerbalEvaVessel.rootPart.mass += this.part.mass; } //Add event GameEvents.onCrewBoardVessel.Add(new EventData <GameEvents.FromToAction <Part, Part> > .OnEvent(this.OnCrewBoardVessel)); //Set variables evaHolderVesselName = kerbalEvaVessel.vesselName; evaHolderPart = kerbalEvaVessel.rootPart; grabbed = true; grab_pending = false; //Refresh Context Menu RefreshContextMenu(); //Play grab sound fxSndGrab.audio.Play(); //Send message to other modules base.SendMessage("OnPartGrabbed", kerbalEvaVessel, SendMessageOptions.DontRequireReceiver); }