GetWinchModuleGrabbed() public static méthode

public static GetWinchModuleGrabbed ( Vessel evaVessel ) : KASModuleWinch
evaVessel Vessel
Résultat KASModuleWinch
Exemple #1
0
        private void UpdateWinchKeyGrab()
        {
            if (Input.GetKeyDown(grabHeadKey.ToLower()))
            {
                if (FlightGlobals.ActiveVessel.isEVA)
                {
                    KASModuleWinch tmpGrabbbedHead = KAS_Shared.GetWinchModuleGrabbed(FlightGlobals.ActiveVessel);
                    if (tmpGrabbbedHead)
                    {
                        tmpGrabbbedHead.DropHead();
                        return;
                    }
                    var nearestColliders = new List <Collider>(
                        Physics.OverlapSphere(FlightGlobals.ActiveVessel.transform.position, radius, 557059));
                    float          shorterDist        = Mathf.Infinity;
                    KASModuleWinch nearestModuleWinch = null;
                    foreach (Collider col in nearestColliders)
                    {
                        KAS_LinkedPart linkedPart = col.transform.gameObject.GetComponent <KAS_LinkedPart>();
                        if (!linkedPart)
                        {
                            continue;
                        }
                        KASModuleWinch winchModule = linkedPart.part.GetComponent <KASModuleWinch>();
                        if (!winchModule)
                        {
                            continue;
                        }

                        // Check if the head is plugged
                        if (winchModule.headState != KASModuleWinch.PlugState.Deployed)
                        {
                            continue;
                        }
                        // Check if it's a head grabbed by another kerbal eva
                        if (winchModule.evaHolderPart)
                        {
                            continue;
                        }
                        // Select the nearest grabbable part
                        float distToGrab = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position,
                                                            winchModule.part.transform.position);
                        if (distToGrab <= shorterDist)
                        {
                            shorterDist        = distToGrab;
                            nearestModuleWinch = winchModule;
                        }
                    }
                    //Grab nearest head if exist
                    if (nearestModuleWinch)
                    {
                        nearestModuleWinch.GrabHead(FlightGlobals.ActiveVessel);
                        return;
                    }
                }
            }
        }
Exemple #2
0
        public void ContextMenuPlugDocked()
        {
            KASModuleWinch winchModule = KAS_Shared.GetWinchModuleGrabbed(FlightGlobals.ActiveVessel);

            if (winchModule)
            {
                winchModule.PlugHead(this, KASModuleWinch.PlugState.PlugDocked);
            }
            else
            {
                ScreenMessages.PostScreenMessage("You didn't have anything to plug !", 5, ScreenMessageStyle.UPPER_CENTER);
            }
        }
Exemple #3
0
        private void UpdateWinchMouseGrab()
        {
            if (Input.GetKeyDown(KeyCode.Mouse1))
            {
                if (clickedWinch)
                {
                    clickedWinch = null;
                    return;
                }
                if (FlightGlobals.ActiveVessel.isEVA)
                {
                    KerbalEVA kerbalEva = KAS_Shared.GetKerbalEvaUnderCursor();
                    if (kerbalEva)
                    {
                        KASModuleWinch winchModule = KAS_Shared.GetWinchModuleGrabbed(kerbalEva.vessel);
                        if (winchModule)
                        {
                            clickedWinch = winchModule;
                            return;
                        }
                    }

                    Transform headTransform = KAS_Shared.GetTransformUnderCursor();
                    if (headTransform)
                    {
                        KAS_LinkedPart linkedPart = headTransform.gameObject.GetComponent <KAS_LinkedPart>();
                        if (linkedPart)
                        {
                            float dist = Vector3.Distance(FlightGlobals.ActiveVessel.transform.position,
                                                          headTransform.position);
                            if (dist <= radius)
                            {
                                clickedWinch = linkedPart.part.GetComponent <KASModuleWinch>();
                                return;
                            }
                        }
                    }
                }
            }
        }
Exemple #4
0
 private void UpdateWinchCableControl()
 {
     //Extend key pressed
     if (winchExtendKey != "")
     {
         if (Input.GetKeyDown(winchExtendKey.ToLower()))
         {
             KAS_Shared.SendMsgToWinch("EventWinchExtend", true, vess: FlightGlobals.ActiveVessel);
         }
         if (Input.GetKeyUp(winchExtendKey.ToLower()))
         {
             KAS_Shared.SendMsgToWinch("EventWinchExtend", false, vess: FlightGlobals.ActiveVessel);
         }
     }
     //Retract key pressed
     if (winchRetractKey != "")
     {
         if (Input.GetKeyDown(winchRetractKey.ToLower()))
         {
             KAS_Shared.SendMsgToWinch("EventWinchRetract", true, vess: FlightGlobals.ActiveVessel);
         }
         if (Input.GetKeyUp(winchRetractKey.ToLower()))
         {
             KAS_Shared.SendMsgToWinch("EventWinchRetract", false, vess: FlightGlobals.ActiveVessel);
         }
     }
     //Head left key pressed
     if (winchHeadLeftKey != "")
     {
         if (Input.GetKey(winchHeadLeftKey.ToLower()))
         {
             KAS_Shared.SendMsgToWinch("EventWinchHeadLeft", vess: FlightGlobals.ActiveVessel);
         }
     }
     //Head right key pressed
     if (winchHeadRightKey != "")
     {
         if (Input.GetKey(winchHeadRightKey.ToLower()))
         {
             KAS_Shared.SendMsgToWinch("EventWinchHeadRight", vess: FlightGlobals.ActiveVessel);
         }
     }
     //Eject key pressed
     if (winchEjectKey != "")
     {
         if (Input.GetKeyDown(winchEjectKey.ToLower()))
         {
             KAS_Shared.SendMsgToWinch("EventWinchEject", vess: FlightGlobals.ActiveVessel);
         }
     }
     //Hook key pressed
     if (winchHookKey != "")
     {
         if (Input.GetKeyDown(winchHookKey.ToLower()))
         {
             KAS_Shared.SendMsgToWinch("EventWinchHook", vess: FlightGlobals.ActiveVessel);
         }
     }
     //Eva Extend key pressed
     if (winchEvaExtendKey != "")
     {
         if (Input.GetKeyDown(winchEvaExtendKey.ToLower()))
         {
             var grabbedWinchModule = KAS_Shared.GetWinchModuleGrabbed(FlightGlobals.ActiveVessel);
             if (grabbedWinchModule)
             {
                 grabbedWinchModule.EventWinchExtend(true);
             }
         }
         if (Input.GetKeyUp(winchEvaExtendKey.ToLower()))
         {
             var grabbedWinchModule = KAS_Shared.GetWinchModuleGrabbed(FlightGlobals.ActiveVessel);
             if (grabbedWinchModule)
             {
                 grabbedWinchModule.EventWinchExtend(false);
             }
         }
     }
     //Eva Retract key pressed
     if (winchEvaRetractKey != "")
     {
         if (Input.GetKeyDown(winchEvaRetractKey.ToLower()))
         {
             var grabbedWinchModule = KAS_Shared.GetWinchModuleGrabbed(FlightGlobals.ActiveVessel);
             if (grabbedWinchModule)
             {
                 grabbedWinchModule.EventWinchRetract(true);
             }
         }
         if (Input.GetKeyUp(winchEvaRetractKey.ToLower()))
         {
             var grabbedWinchModule = KAS_Shared.GetWinchModuleGrabbed(FlightGlobals.ActiveVessel);
             if (grabbedWinchModule)
             {
                 grabbedWinchModule.EventWinchRetract(false);
             }
         }
     }
 }
Exemple #5
0
        public void Drop()
        {
            if (grabbed)
            {
                KAS_Shared.DebugLog("Drop - Dropping part :" + this.part.partInfo.name);
                base.SendMessage("OnPartDrop", SendMessageOptions.DontRequireReceiver);

                if (this.part.vessel.isEVA)
                {
                    this.part.decouple();
                }

                //Remove created joints between eva and part if exist
                KAS_Shared.RemoveFixedJointBetween(this.part, evaHolderPart);
                KAS_Shared.RemoveHingeJointBetween(this.part, evaHolderPart);

                List <Collider> allColliders = new List <Collider>(this.part.GetComponentsInChildren <Collider>() as Collider[]);
                foreach (Collider col in allColliders)
                {
                    col.isTrigger = false;
                }

                if (customGroundPos && evaHolderPart.checkLanded())
                {
                    KAS_Shared.MoveRelatedTo(this.part.transform, evaCollider.transform, dropPartPos, dropPartRot);
                }
                else
                {
                    KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform);
                }

                if (evaNodeTransform)
                {
                    Destroy(evaNodeTransform.gameObject);
                }
                if (evaJoint)
                {
                    Destroy(evaJoint);
                }

                this.part.transform.parent          = null;
                this.part.rigidbody.isKinematic     = false;
                this.part.physicalSignificance      = Part.PhysicalSignificance.FULL;
                this.part.rigidbody.velocity        = evaHolderPart.rigidbody.velocity;
                this.part.rigidbody.angularVelocity = evaHolderPart.rigidbody.angularVelocity;

                if (addPartMass & !physicJoint)
                {
                    evaHolderPart.mass = orgKerbalMass;
                }

                KASModuleWinch grabbedWinchHead = KAS_Shared.GetWinchModuleGrabbed(evaHolderPart.vessel);
                if (grabbedWinchHead)
                {
                    if (grabbedWinchHead.grabbedPortModule)
                    {
                        KAS_Shared.DebugLog("Drop - Grabbed part have a port connected");
                        grabbedWinchHead.PlugHead(grabbedWinchHead.grabbedPortModule, KASModuleWinch.PlugState.PlugDocked, fireSound: false);
                    }
                }

                evaJoint            = null;
                evaNodeTransform    = null;
                evaHolderVesselName = null;
                evaHolderPart       = null;
                grabbed             = false;

                RefreshContextMenu();

                //Send drop message to all child objects
                base.SendMessage("OnPartDropped", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                KAS_Shared.DebugWarning("Drop - Part not grabbed, ignoring drop...");
            }
        }
Exemple #6
0
        public void Drop(bool forAttach = false)
        {
            if (grabbed)
            {
                KAS_Shared.DebugLog("Drop - Dropping part :" + this.part.partInfo.name);

                base.SendMessage("OnPartDrop", SendMessageOptions.DontRequireReceiver);

                if (this.part.vessel.isEVA || grab_pending)
                {
                    this.part.decouple();
                }

                if (grab_pending)
                {
                    Destroy(evaNodeTransform.gameObject);
                    evaNodeTransform    = null;
                    evaHolderVesselName = null;
                    evaHolderPart       = null;
                    grabbed             = grab_pending = false;
                    RefreshContextMenu();
                    return;
                }

                //Remove created joints between eva and part if exist
                KAS_Shared.RemoveFixedJointBetween(this.part, evaHolderPart);
                KAS_Shared.RemoveHingeJointBetween(this.part, evaHolderPart);

                List <Collider> allColliders = new List <Collider>(this.part.GetComponentsInChildren <Collider>() as Collider[]);
                foreach (Collider col in allColliders)
                {
                    col.isTrigger = (keepTriggers != null && keepTriggers.Contains(col));
                }

                if (customGroundPos && evaHolderPart.checkLanded())
                {
                    KAS_Shared.MoveRelatedTo(this.part.transform, evaCollider.transform, dropPartPos, dropPartRot);
                }
                else
                {
                    KAS_Shared.MoveAlign(this.part.transform, partNode.nodeTransform, evaNodeTransform);
                }

                if (evaNodeTransform)
                {
                    Destroy(evaNodeTransform.gameObject);
                }
                if (evaJoint)
                {
                    Destroy(evaJoint);
                }

                this.part.rigidbody.velocity        = evaHolderPart.rigidbody.velocity;
                this.part.rigidbody.angularVelocity = evaHolderPart.rigidbody.angularVelocity;

                KAS_Shared.ResetCollisionEnhancer(this.part);

                if (addPartMass & !physicJoint)
                {
                    evaHolderPart.mass = orgKerbalMass;
                }

                KASModuleWinch grabbedWinchHead = KAS_Shared.GetWinchModuleGrabbed(evaHolderPart.vessel);
                if (grabbedWinchHead)
                {
                    if (grabbedWinchHead.grabbedPortModule && grabbedWinchHead.grabbedPortModule.part == part)
                    {
                        KAS_Shared.DebugLog("Drop - Grabbed part have a port connected");

                        if (forAttach)
                        {
                            // Docked causes big problems when the part is later coupled
                            grabbedWinchHead.PlugHead(grabbedWinchHead.grabbedPortModule, KASModuleWinch.PlugState.PlugUndocked, fireSound: false);
                        }
                        else
                        {
                            grabbedWinchHead.PlugHead(grabbedWinchHead.grabbedPortModule, KASModuleWinch.PlugState.PlugDocked, fireSound: false);
                        }
                    }
                }

                GameEvents.onCrewBoardVessel.Remove(new EventData <GameEvents.FromToAction <Part, Part> > .OnEvent(this.OnCrewBoardVessel));

                syncGrab            = false;
                keepTriggers        = null;
                evaJoint            = null;
                evaNodeTransform    = null;
                evaHolderVesselName = null;
                evaHolderPart       = null;
                grabbed             = grab_pending = false;

                RefreshContextMenu();

                //Send drop message to all child objects
                base.SendMessage("OnPartDropped", SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                KAS_Shared.DebugWarning("Drop - Part not grabbed, ignoring drop...");
            }
        }