Ejemplo n.º 1
0
    private bool GetMouseWorldPoint(out Vector3 worldPos)
    {
      worldPos = Vector3.zero;
      float maxTargetingRange = 5000;
      //MouseControl
      Vector3 mouseAim = new Vector3(Input.mousePosition.x / Screen.width, Input.mousePosition.y / Screen.height, 0);
      Ray ray = FlightCamera.fetch.mainCamera.ViewportPointToRay(mouseAim);
      bool raycastFailed = false;
      RaycastHit hit;
      if (Physics.Raycast(ray, out hit, maxTargetingRange, 557057))
      {
        if (FlightGlobals.getAltitudeAtPos(hit.point) < 0)
        {
          raycastFailed = true;
        }
        else
        {
          worldPos = hit.point;
        }

      }
      else
      {
        raycastFailed = true;
      }

      if (raycastFailed)
      {
        double dist;
        if (VMUtils.SphereRayIntersect(ray, FlightGlobals.currentMainBody.transform.position, FlightGlobals.currentMainBody.Radius, out dist))
        {
          worldPos = ray.GetPoint((float)dist);
          return true;
        }
        else
        {
          return false;
        }
      }
      else
      {
        return true;
      }

    }
Ejemplo n.º 2
0
        private void ToolbarWindow(int windowID)
        {
            float line = 0;

            line += 1.25f;

            if (FlightGlobals.ActiveVessel && (FlightGlobals.ActiveVessel.LandedOrSplashed || VesselMove.Instance.IsMovingVessel))
            {
                if (!VesselMove.Instance.IsMovingVessel)
                {
                    if (GUI.Button(LineRect(ref line, 1.5f), "Move Vessel", HighLogic.Skin.button))
                    {
                        VesselMove.Instance.StartMove(FlightGlobals.ActiveVessel, true);
                    }
                    line += 0.2f;

                    Rect spawnVesselRect = LineRect(ref line);
                    svRectScreenSpace    = new Rect(spawnVesselRect);
                    svRectScreenSpace.x += toolbarRect.x;
                    svRectScreenSpace.y += toolbarRect.y;

                    if (GUI.Button(spawnVesselRect, "Spawn Vessel", HighLogic.Skin.button))
                    {
                        VesselSpawn.instance.StartVesselSpawn();
                    }

                    line += .75f;
                    Rect crewRect1 = LineRect(ref line);
                    Rect crewRect2 = new Rect(crewRect1.x + crewRect1.width / 2 + 5f, crewRect1.y, crewRect1.width / 2, crewRect1.height);
                    crewRect1.width      = crewRect1.width / 2;
                    svCrewScreenSpace    = new Rect(crewRect1);
                    svCrewScreenSpace.x += toolbarRect.x;
                    svCrewScreenSpace.y += toolbarRect.y;
                    addCrewMembers       = GUI.Toggle(crewRect1, addCrewMembers, "Spawn Crew");
                    if (!addCrewMembers)
                    {
                        GUI.enabled = false;
                    }
                    selectCrewMembers = GUI.Toggle(crewRect2, selectCrewMembers, "Choose Crew");
                    GUI.enabled       = true;
                    showMoveHelp      = false;
                }
                else
                {
                    if (GUI.Button(LineRect(ref line, 2), "Place Vessel", HighLogic.Skin.button))
                    {
                        VesselMove.Instance.EndMove();
                    }

                    line += 0.3f;

                    if (GUI.Button(LineRect(ref line, 2), "Drop Vessel", HighLogic.Skin.button))
                    {
                        VesselMove.Instance.DropMove();
                    }

                    line += 0.3f;

                    if (GUI.Button(LineRect(ref line), "Help", HighLogic.Skin.button))
                    {
                        showMoveHelp = !showMoveHelp;
                    }
                }
            }
            else
            {
                GUIStyle centerLabelStyle = new GUIStyle(HighLogic.Skin.label);
                centerLabelStyle.alignment = TextAnchor.UpperCenter;
                GUI.Label(LineRect(ref line), "You need to be landed to use this!", centerLabelStyle);
            }

            toolbarRect.height = (line * toolbarLineHeight) + (toolbarMargin * 2);
            GUI.DragWindow(new Rect(0, 0, Screen.width, 30));
            VMUtils.RepositionWindow(ref toolbarRect);
        }