void Update()
    {
        if (cameraRotationLock == false & escMenuActiveStatus == false)
        {
            yaw         += speedH * Input.GetAxis("Mouse X");
            smooth_yaw   = yaw;
            pitch       -= speedV * Input.GetAxis("Mouse Y");
            smooth_pitch = pitch;
            if (pitch > 85)
            {
                pitch = 85;
            }
            else if (pitch < -85)
            {
                pitch = -85;
            }
            transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
        }
        else if (escMenuActiveStatus == true)
        {
            if (Input.mousePosition.x <= Screen.width * 0.99 & Input.mousePosition.x >= Screen.width * 0.01)
            {
                yaw += 0.04f * Input.GetAxis("Mouse X");
            }

            if (Input.mousePosition.y <= Screen.height * 0.99 & Input.mousePosition.y >= Screen.height * 0.01)
            {
                pitch -= 0.04f * Input.GetAxis("Mouse Y");
            }

            if (pitch > 85)
            {
                pitch = 85;
            }
            else if (pitch < -85)
            {
                pitch = -85;
            }
            smooth_pitch          = Mathf.Lerp(smooth_pitch, pitch, 0.1f);
            smooth_yaw            = Mathf.Lerp(smooth_yaw, yaw, 0.1f);
            transform.eulerAngles = new Vector3(smooth_pitch, smooth_yaw, 0.0f);
        }

        if (Input.GetKeyDown("escape"))
        {
            if (escMenuActiveStatus == true)
            {
                if (systemRunningStatusBeforeMenuOpened == true)
                {
                    starSystemObjectScript.StartSystem();
                }
                escMenuActiveStatus = false;
                escMenu.SetActive(false);
            }
            else
            {
                systemRunningStatusBeforeMenuOpened = starSystemObjectScript.systemRunning;
                starSystemObjectScript.PauseSystem();
                escMenuActiveStatus = true;
                escMenu.SetActive(true);
            }
        }

        if (Input.GetKeyDown("l"))
        {
            cameraRotationLock = (cameraRotationLock == false) ? true : false;
            cameraMovementLock = (cameraMovementLock == false) ? true : false;
        }

        if (cameraMovementLock == false & escMenuActiveStatus == false)
        {
            if (Input.GetKey("w"))
            {
                transform.position += nowWalkSpeed * (transform.forward).normalized;
            }
            if (Input.GetKey("s"))
            {
                transform.position -= nowWalkSpeed * (transform.forward).normalized;
            }
            if (Input.GetKey("a"))
            {
                transform.position -= nowWalkSpeed * (transform.right).normalized;
            }
            if (Input.GetKey("d"))
            {
                transform.position += nowWalkSpeed * (transform.right).normalized;
            }
            if (Input.GetKey("left shift"))
            {
                transform.position -= nowWalkSpeed * (Vector3.up).normalized;
            }
            if (Input.GetKey("space"))
            {
                transform.position += nowWalkSpeed * (Vector3.up).normalized;
            }

#if !UNITY_EDITOR
            if (Input.GetKeyDown("left alt"))
            {
                slowWalkCondition = true;
                nowWalkSpeed      = slowWalkSpeed;
            }
            if (Input.GetKeyUp("left alt"))
            {
                slowWalkCondition = false;
                nowWalkSpeed      = normalWalkSpeed;
            }
#endif
            if (Input.GetKeyDown("c"))
            {
                slowWalkCondition = (slowWalkCondition == true) ? false : true;
                if (slowWalkCondition == true)
                {
                    nowWalkSpeed = slowWalkSpeed;
                }
                else
                {
                    nowWalkSpeed = normalWalkSpeed;
                }
            }
        }
    }
示例#2
0
    void OnGUI()
    {
        if (cameraMovementScript.escMenuActiveStatus == false & cameraMovementScript.cameraRotationLock == true)
        {
            haveInvalidInput = false;
            GUILayout.BeginHorizontal("box");
            GUILayout.Label("Pos x: ");
            newStarXStr = GUILayout.TextField(newStarXStr, 25, GUILayout.Width(60));
            StringToFloatCheckAndAssign(ref newStarXStr, ref newStarX);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            GUILayout.Label("Pos y: ");
            newStarYStr = GUILayout.TextField(newStarYStr, 25, GUILayout.Width(60));
            StringToFloatCheckAndAssign(ref newStarYStr, ref newStarY);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            GUILayout.Label("Pos z: ");
            newStarZStr = GUILayout.TextField(newStarZStr, 25, GUILayout.Width(60));
            StringToFloatCheckAndAssign(ref newStarZStr, ref newStarZ);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            GUILayout.Label("V x: ");
            newStarVxStr = GUILayout.TextField(newStarVxStr, 25, GUILayout.Width(60));
            StringToFloatCheckAndAssign(ref newStarVxStr, ref newStarVx);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            GUILayout.Label("V y: ");
            newStarVyStr = GUILayout.TextField(newStarVyStr, 25, GUILayout.Width(60));
            StringToFloatCheckAndAssign(ref newStarVyStr, ref newStarVy);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            GUILayout.Label("V z: ");
            newStarVzStr = GUILayout.TextField(newStarVzStr, 25, GUILayout.Width(60));
            StringToFloatCheckAndAssign(ref newStarVzStr, ref newStarVz);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal("box");
            GUILayout.Label("Mass: ");
            newStarMassStr = GUILayout.TextField(newStarMassStr, 25, GUILayout.Width(60));
            StringToFloatCheckAndAssign(ref newStarMassStr, ref newStarMass);
            GUILayout.EndHorizontal();

            if (haveInvalidInput == true)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Add star"))
            {
                var newStar = Instantiate(myPrefab, new Vector3(float.Parse(newStarXStr, System.Globalization.NumberStyles.Float),
                                                                float.Parse(newStarYStr, System.Globalization.NumberStyles.Float),
                                                                float.Parse(newStarZStr, System.Globalization.NumberStyles.Float)), Quaternion.identity);

                double[] v = new double[3] {
                    double.Parse(newStarVxStr, System.Globalization.NumberStyles.Float),
                    double.Parse(newStarVyStr, System.Globalization.NumberStyles.Float),
                    double.Parse(newStarVzStr, System.Globalization.NumberStyles.Float)
                };
                newStar.GetComponent <starObject>().vel  = new VEC(3, v);
                newStar.GetComponent <starObject>().mass = float.Parse(newStarMassStr, System.Globalization.NumberStyles.Float);
                newStar.GetComponent <starObject>().lineRendererColor = Color.yellow;
            }
            if (haveInvalidInput == true)
            {
                GUI.enabled = true;
            }
            if (GUILayout.Button("Clear all stars"))
            {
                starSystemObjectScript.ClearAllStars(-1);
            }


            if (GUI.Button(new Rect(5, Screen.height - 57, 111, 23), "Start"))
            {
                if (starSystemObjectScript.systemRunning == false)
                {
                    starSystemObjectScript.StartSystem();
                    starSystemObjectScript.systemRunning = true;
                }
            }

            if (GUI.Button(new Rect(5, Screen.height - 30, 110, 23), "Pause"))
            {
                if (starSystemObjectScript.systemRunning == true)
                {
                    starSystemObjectScript.PauseSystem();
                    starSystemObjectScript.systemRunning = false;
                }
            }
        }
        if (cameraMovementScript.escMenuActiveStatus == false & displayStarInfo == true)
        {
            GUI.Label(new Rect(Screen.width - 190, Screen.height - 115, 190, 115), starInfoToDisplay);
        }
    }