public void OnKISAction(BaseEventData baseEventData) { if (allowStaticAttach == ItemAttachMode.Disabled || useExternalStaticAttach) { return; } string action = baseEventData.GetString("action"); Part tgtPart = (Part)baseEventData.Get("targetPart"); //FIXME: use enum values if (action == KIS_Shared.MessageAction.Store.ToString() || action == KIS_Shared.MessageAction.DropEnd.ToString() || action == KIS_Shared.MessageAction.AttachStart.ToString()) { GroundDetach(); var modulePickup = KISAddonPickup.instance.GetActivePickupNearest(this.transform.position); if (modulePickup) { KIS_Shared.PlaySoundAtPoint(modulePickup.detachStaticSndPath, this.transform.position); } } if (action == KIS_Shared.MessageAction.AttachEnd.ToString() && tgtPart == null) { GroundAttach(); var modulePickup = KISAddonPickup.instance.GetActivePickupNearest(this.transform.position); if (modulePickup) { KIS_Shared.PlaySoundAtPoint(modulePickup.attachStaticSndPath, this.transform.position); } } }
public void DisableAttachMode() { List <ModuleKISPickup> pickupModules = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleKISPickup>(); if (pickupModules.Count > 0) { if (!draggedPart && !grabActive && !KISAddonPointer.isRunning) { detachActive = false; KISAddonCursor.StopPartDetection(); KISAddonCursor.CursorDefault(); } if (KISAddonPointer.isRunning && KISAddonPickup.instance.pointerMode == KISAddonPickup.PointerMode.Attach) { KISAddonPickup.instance.pointerMode = KISAddonPickup.PointerMode.Drop; KIS_Shared.PlaySoundAtPoint("KIS/Sounds/click", FlightGlobals.ActiveVessel.transform.position); } } }
public void EnableAttachMode() { List <ModuleKISPickup> pickupModules = FlightGlobals.ActiveVessel.FindPartModulesImplementing <ModuleKISPickup>(); // Attach/detach only if pickup module is present on vessel if (pickupModules.Count > 0) { if (!draggedPart && !grabActive && !KISAddonPointer.isRunning) { KISAddonCursor.StartPartDetection(OnMouseDetachPartClick, OnMouseDetachEnterPart, null, OnMouseDetachExitPart); KISAddonCursor.CursorEnable("KIS/Textures/detach", "Detach", ""); detachActive = true; } if (KISAddonPointer.isRunning && KISAddonPointer.pointerTarget != KISAddonPointer.PointerTarget.PartMount) { KISAddonPickup.instance.pointerMode = KISAddonPickup.PointerMode.Attach; KIS_Shared.PlaySoundAtPoint("KIS/Sounds/click", FlightGlobals.ActiveVessel.transform.position); } } }
public void GroundDetach() { if (staticAttached) { KIS_Shared.DebugLog("Removing static rigidbody and fixed joint on " + this.part.partInfo.title); if (fixedJoint) { Destroy(fixedJoint); } if (connectedGameObject) { Destroy(connectedGameObject); } fixedJoint = null; connectedGameObject = null; staticAttached = false; ModuleKISPickup modulePickup = KISAddonPickup.instance.GetActivePickupNearest(this.transform.position); if (modulePickup) { KIS_Shared.PlaySoundAtPoint(modulePickup.detachStaticSndPath, this.transform.position); } } }
public void GroundAttach() { KIS_Shared.DebugLog("Create kinematic rigidbody"); if (connectedGameObject) { Destroy(connectedGameObject); } GameObject obj = new GameObject("KISBody"); obj.AddComponent <Rigidbody>(); obj.rigidbody.mass = 100; obj.rigidbody.isKinematic = true; obj.transform.position = this.part.transform.position; obj.transform.rotation = this.part.transform.rotation; connectedGameObject = obj; KIS_Shared.DebugLog("Create fixed joint on the kinematic rigidbody"); if (fixedJoint) { Destroy(fixedJoint); } FixedJoint CurJoint = this.part.gameObject.AddComponent <FixedJoint>(); CurJoint.breakForce = staticAttachBreakForce; CurJoint.breakTorque = staticAttachBreakForce; CurJoint.connectedBody = obj.rigidbody; fixedJoint = CurJoint; this.part.vessel.Landed = true; staticAttached = true; ModuleKISPickup modulePickup = KISAddonPickup.instance.GetActivePickupNearest(this.transform.position); if (modulePickup) { KIS_Shared.PlaySoundAtPoint(modulePickup.attachStaticSndPath, this.transform.position); } }
void OnMouseDetachPartClick(Part part) { if (KISAddonPointer.isRunning) { return; } if (hoverInventoryGui()) { return; } if (!HighLogic.LoadedSceneIsFlight) { return; } if (!detachOk) { return; } if (!HasActivePickupInRange(part)) { return; } detachActive = false; KISAddonCursor.StopPartDetection(); KISAddonCursor.CursorDefault(); ModuleKISItem item = part.GetComponent <ModuleKISItem>(); if (item) { if (item.staticAttached) { item.GroundDetach(); if (item.allowPartAttach == 1) { ModuleKISPickup pickupModule = GetActivePickupNearest(part); KIS_Shared.PlaySoundAtPoint(pickupModule.detachStaticSndPath, pickupModule.part.transform.position); } if (item.allowPartAttach == 2) { ModuleKISPickup pickupModule = GetActivePickupNearest(part, canStaticAttachOnly: true); KIS_Shared.PlaySoundAtPoint(pickupModule.detachStaticSndPath, pickupModule.part.transform.position); } return; } } part.decouple(); if (item) { if (item.allowPartAttach == 1) { ModuleKISPickup pickupModule = GetActivePickupNearest(part); KIS_Shared.PlaySoundAtPoint(pickupModule.detachPartSndPath, pickupModule.part.transform.position); } if (item.allowPartAttach == 2) { ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true); KIS_Shared.PlaySoundAtPoint(pickupModule.detachPartSndPath, pickupModule.part.transform.position); } } else { ModuleKISPickup pickupModule = GetActivePickupNearest(part, canPartAttachOnly: true); KIS_Shared.PlaySoundAtPoint(pickupModule.detachPartSndPath, pickupModule.part.transform.position); } }