Esempio n. 1
0
    void Update()
    {
        // Time does not start until Time.timeScale has been set to 1.
        gameTime += Time.deltaTime;
        minutes   = Mathf.FloorToInt(gameTime / 60F);
        seconds   = Mathf.FloorToInt(gameTime - minutes * 60);
        timeFixed = string.Format("{0:0}:{1:00}", minutes, seconds);
        // End time

        timer += Time.deltaTime;
        if (timer >= timerMax)
        {
            if (isLocalPlayer)
            {
                UpdateResources();

                timer = 0;
            }
        }

        if (!WorldHandler.isBeatleUnitSelected() && !WorldHandler.isAntUnitSelected() && !WorldHandler.isAntHillSelected())
        {
            hideUnitInfo();
            anthillInfo.SetActive(false);
        }



        if (Input.GetKeyDown(KeyCode.Escape))            // if the Escape key is pressed, unconfine the cursor from its state set in the Start() function
        {
            Cursor.lockState = CursorLockMode.None;
            // Open Exit Menu
            isExitMenuOpen = !isExitMenuOpen;
            EscapeMenu.SetActive(isExitMenuOpen);
        }

        updateHUD();


        if (!isLocalPlayer)
        {
            return;
        }


        if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter) && EventSystem.current.currentSelectedGameObject.name == "EnterMessage")
        {
            InputField theInputField = inputField.GetComponent <InputField> ();


            if (!string.IsNullOrEmpty(theInputField.text))
            {
                string txtToSend = theInputField.text;



                if (txtToSend == "cls")
                {
                    scrollText.GetComponent <Text> ().text = "";
                }

                if (GetComponent <UnitIdentity> ().id == 0)
                {
                    Cmd_SendMessageToAllClients("<color=#ff0000ff>Player " + GetComponent <UnitIdentity>().id + "</color>: " + txtToSend);
                }
                if (GetComponent <UnitIdentity> ().id == 1)
                {
                    Cmd_SendMessageToAllClients("<color=#0000ffff>Player " + GetComponent <UnitIdentity>().id + "</color>: " + txtToSend);
                }

                theInputField.text = "";
            }
        }


        if (inputField.GetComponent <InputField> ().isFocused)
        {
            Camera.main.GetComponent <CameraController> ().enabled = false;
        }
        else
        {
            Camera.main.GetComponent <CameraController> ().enabled = true;
        }

        // Update FPS Counter

        if (Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl))
        {
            if (Input.GetKeyDown(KeyCode.F))
            {
                displayFrameRate = !displayFrameRate;
            }
        }

        if (displayFrameRate)
        {
            if (float.IsInfinity(FPS))
            {
                fpsText.text = "Game is paused.";
            }
            else
            {
                // Round FPS
                FPS          = Mathf.RoundToInt(FPS);
                fpsText.text = "FPS: " + FPS;
            }
        }
        else
        {
            fpsText.text = "";
        }

        deltaTime += Time.deltaTime;
        deltaTime /= 2.0f;
        FPS        = 1.0f / deltaTime;
        // End Update FPS Counter
        // Sync timer and resource gathering
    }