예제 #1
0
        void Awake()
        {
            object[] data        = photonView.instantiationData;
            int      primaryID   = (int)data[0];
            int      secondaryID = (int)data[1];
            int      meleeID     = (int)data[2];
            int      item1ID     = (int)data[3];
            int      item2ID     = (int)data[4];

            if (primaryID >= 0)
            {
                primary = InstantiateGun(primaryID);
            }
            if (secondaryID >= 0)
            {
                secondary = InstantiateGun(secondaryID);
            }
            if (meleeID >= 0)
            {
                melee = InstantiateGun(meleeID);
            }
            if (item1ID >= 0)
            {
                item1 = InstantiateGun(item1ID);
            }
            if (item2ID >= 0)
            {
                item2 = InstantiateGun(item2ID);
            }

            hasStarted = true;
        }
예제 #2
0
        public GunBase InstantiateGun(int ID)
        {
            GunInfo    gunInfo = GameController.GetGun(ID);
            GameObject go      = Instantiate(gunInfo.viewmodel) as GameObject;

            go.name = string.Format("VM_{0}", gunInfo.Name);

            go.transform.SetParent(mainGunsScript.transform, false);
            go.transform.localPosition = Vector3.zero;
            go.transform.localRotation = Quaternion.identity;
            go.transform.localScale    = Vector3.one;

            GunBase gun = go.GetComponent <GunBase>();

            gun.info = gunInfo;
            gun.main = mainGunsScript;

            CharacterCustomization customization = go.GetComponent <CharacterCustomization>();

            customization.StartUp();

            return(gun);
        }
예제 #3
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);
                    }
                }
            }
        }