Inheritance: UnityEngine.MonoBehaviour
Exemplo n.º 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;
                    }
                }
            }
        }
Exemplo n.º 2
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;
                            }
                        }
                    }
                }
            }
        }