Exemplo n.º 1
0
        void Update()
        {
            if (!chatField.gameObject.activeInHierarchy)
            {
                if (!classCreation.classes.activeInHierarchy)
                {
                    if (!menu.activeInHierarchy)
                    {
                        if (Input.GetKeyDown(KeyCode.Escape))
                        {
                            menu.SetActive(true);
                        }
                        if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
                        {
                            chatField.gameObject.SetActive(true);
                        }
                    }
                    else
                    {
                        if (Input.GetKeyDown(KeyCode.Escape))
                        {
                            UI_Resume();
                        }
                    }
                }
                else
                {
                    UI_Resume();
                }
            }
            else
            {
                if (!chatField.isFocused)
                {
                    chatField.Select();
                    chatField.ActivateInputField();
                }

                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    chatField.text = "";
                    chatField.gameObject.SetActive(false);
                }

                if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
                {
                    if (chatField.text != "")
                    {
                        SendChatMessage(chatField.text);
                    }

                    chatField.text = "";
                    chatField.gameObject.SetActive(false);
                }
            }

            scoreboard.scoreboard.SetActive((Input.GetKey(KeyCode.Tab) && !GameController.IsPaused()) || (ServerController.HasRoundEnded && !menu.activeSelf));

            float time    = (float)ServerController.RemainingTime;
            int   minutes = Mathf.FloorToInt(time / 60);
            int   seconds = Mathf.FloorToInt(time % 60);

            timerText.text = string.Format("{0}:{1:00}", minutes, seconds);

            hitCG.alpha          = Mathf.Lerp(hitCG.alpha, 0f, hitLerpSpeed * Time.deltaTime);
            crosshairImage.color = Color.Lerp(crosshairImage.color, Color.white, hitmarkerLerpSpeed * Time.deltaTime);

            Player player = ServerController.player;

            if (player != null)
            {
                GunBase currentGunBase = player.items.currentGun;
                if (currentGunBase != null)
                {
                    GunInfo currentGunInfo = currentGunBase.info;

                    bool isCrosshairHidden = player.isDead || (currentGunInfo.hideCrosshair && !player.reloading);
                    bool hidingCrosshair   = player.aiming;

                    if (currentGunBase is Grenade)
                    {
                        Grenade currentGrenade = (Grenade)currentGunBase;
                        hidingCrosshair = currentGrenade.throwing;
                    }

                    float targetCrosshairAlpha = hidingCrosshair ? (currentGunInfo.showCrosshairWhileAiming ? 1f : 0f) : (isCrosshairHidden ? 0f : 1f);

                    float multiplier = 1f;

                    if (hidingCrosshair)
                    {
                        multiplier = 0f;
                    }
                    else if (player.running)
                    {
                        multiplier = currentGunInfo.runningMultiplier;
                    }
                    else if (player.crouching)
                    {
                        multiplier = currentGunInfo.crouchingMultiplier;
                    }
                    else
                    {
                        multiplier = 1f;
                    }

                    Vector2 targetCrosshairSize = Vector2.one * (currentGunInfo.defaultCrosshairSize * multiplier);

                    crosshairCP.alpha   = Mathf.Lerp(crosshairCP.alpha, targetCrosshairAlpha, Gun.aimingLerpSpeed * Time.deltaTime);
                    crosshair.sizeDelta = Vector2.Lerp(crosshair.sizeDelta, targetCrosshairSize, crosshairSizeLerpSpeed * Time.deltaTime);

                    if (currentGunBase is Gun)
                    {
                        Gun currentGun = currentGunBase as Gun;

                        ammoText.gameObject.SetActive(true);

                        if (currentGun.maxAmmo >= 0)
                        {
                            ammoText.text = string.Format("{0}/{1}", currentGun.ammo, currentGun.maxAmmo);
                        }
                        else
                        {
                            ammoText.text = currentGun.ammo.ToString();
                        }

                        if (player.reloading)
                        {
                            float value = Mathf.InverseLerp(currentGun.reloadingT, currentGun.reloadingT + currentGunInfo.reloadTime, Time.time);
                            crosshairCP.transform.localEulerAngles = Vector3.Lerp(Vector3.zero, Vector3.forward * 90f, value);
                            crosshairCP.transform.localScale       = Vector3.one;
                        }
                    }
                    else if (currentGunBase is Grenade)
                    {
                        Grenade currentGrenade = currentGunBase as Grenade;

                        ammoText.gameObject.SetActive(true);
                        ammoText.text = currentGrenade.grenades.ToString();
                    }
                    else if (currentGunBase is Knife)
                    {
                        ammoText.gameObject.SetActive(false);
                    }

                    healthBarMask.localScale = new Vector3(Mathf.Clamp01((float)player.health / 100f), 1f, 1f);

                    if (healthBarMask.localScale.x > 0f)
                    {
                        healthBar.localScale = new Vector3(1f / healthBarMask.localScale.x, 1f, 1f);
                    }
                }
            }
        }