示例#1
0
    void WeaponSwitching()
    {
        ///////////////////////////////////////////////////////// WEAPON SWITCHING //////////////////////////////////////////////
        int prevSelectedWeapon = _currentlySelectedWeapon;

        // DPAD input
        if (XCI.GetDPadDown(XboxDPad.Right, _inputScript.controller))
        {
            //switch to weapon slot 0
            prevSelectedWeapon = 0; //set new selected weapon slot enum
            switchDirection    = SCR_PlayerWorldSpaceUI.WeaponSwitchDirection.Right;
            if (_gunInventory[prevSelectedWeapon].gunObject != null)
            {
                playerWorldSpaceUIScr.StartWeaponSwitchWorldSpaceUI(switchDirection);
            }
        }

        if (XCI.GetDPadDown(XboxDPad.Left, _inputScript.controller))
        {
            prevSelectedWeapon = 1;
            switchDirection    = SCR_PlayerWorldSpaceUI.WeaponSwitchDirection.Left;
            if (_gunInventory[prevSelectedWeapon].gunObject != null)
            {
                playerWorldSpaceUIScr.StartWeaponSwitchWorldSpaceUI(switchDirection);
            }
        }

        if (XCI.GetDPadDown(XboxDPad.Up, _inputScript.controller))
        {
            prevSelectedWeapon = 2; //set new selected weapon slot enum
            switchDirection    = SCR_PlayerWorldSpaceUI.WeaponSwitchDirection.Up;
            if (_gunInventory[prevSelectedWeapon].gunObject != null)
            {
                playerWorldSpaceUIScr.StartWeaponSwitchWorldSpaceUI(switchDirection);
            }
        }

        float leftTrigHeight = MAX_TRG_SCL * (1.0f - XCI.GetAxis(XboxAxis.LeftTrigger, _inputScript.controller));


        if (leftTrigHeight < 1.0f && !bLeftTriggerDown)
        {
            bLeftTriggerDown      = true;
            grenadePreviousWeapon = prevSelectedWeapon;

            prevSelectedWeapon = 3; //set new selected weapon slot enum
            switchDirection    = SCR_PlayerWorldSpaceUI.WeaponSwitchDirection.Down;
            if (_gunInventory[prevSelectedWeapon].gunObject != null)
            {
                playerWorldSpaceUIScr.StartWeaponSwitchWorldSpaceUI(switchDirection);
                _gunInventory[prevSelectedWeapon].gunObject.GetComponent <SCR_GrenadeParent>().GrenadePossible();
            }
        }

        if (leftTrigHeight >= 1.0f && bLeftTriggerDown)
        {
            bLeftTriggerDown   = false;
            prevSelectedWeapon = grenadePreviousWeapon;
            switch (prevSelectedWeapon)
            {
            case 0: switchDirection = SCR_PlayerWorldSpaceUI.WeaponSwitchDirection.Right; break;

            case 1: switchDirection = SCR_PlayerWorldSpaceUI.WeaponSwitchDirection.Left; break;

            case 2: switchDirection = SCR_PlayerWorldSpaceUI.WeaponSwitchDirection.Up; break;
            }

            if (_gunInventory[prevSelectedWeapon].gunObject != null)
            {
                playerWorldSpaceUIScr.StartWeaponSwitchWorldSpaceUI(switchDirection);
                _gunInventory[prevSelectedWeapon].gunObject.GetComponent <SCR_AutomaticWeapon>().SetBulletTimer(0.5f);
            }
        }

        if (XCI.GetButtonUp(XboxButton.Y, _inputScript.controller))
        {
            //loop through inventory until next gunobject is found
            prevSelectedWeapon = CycleWeapons(prevSelectedWeapon);

            //set worldspace UI elements of new gun object
            switch (prevSelectedWeapon)
            {
            case 0:
                switchDirection = SCR_PlayerWorldSpaceUI.WeaponSwitchDirection.Right;
                break;

            case 1:
                switchDirection = SCR_PlayerWorldSpaceUI.WeaponSwitchDirection.Left;
                break;

            case 2:
                switchDirection = SCR_PlayerWorldSpaceUI.WeaponSwitchDirection.Up;
                break;

            case 3:
                switchDirection = SCR_PlayerWorldSpaceUI.WeaponSwitchDirection.Down;
                break;
            }

            if (_gunInventory[prevSelectedWeapon].gunObject != null)
            {
                playerWorldSpaceUIScr.StartWeaponSwitchWorldSpaceUI(switchDirection);
            }
        }

        if (prevSelectedWeapon != _currentlySelectedWeapon)
        {
            if (_gunInventory[prevSelectedWeapon].gunObject != null)
            {
                StopReloadCoroutines();
                uiManagerScript.ResetGaugePin(gameObject.tag);
                if (_gunInventory[_currentlySelectedWeapon].gunObject != null)
                {
                    ResetReloadValues();
                    _gunInventory[_currentlySelectedWeapon].gunObject.SetActive(false);
                }

                // remove reload prompt if they switch weapon to a weapon with ammo
                if (GetAmmo(_currentlySelectedWeapon) > 0)
                {
                    if (playerWorldSpaceUIScr.bIsDisplayed)
                    {
                        playerWorldSpaceUIScr.ShowReloadPrompt(false);
                    }
                }
                else
                {
                    if (!playerWorldSpaceUIScr.bIsDisplayed)
                    {
                        playerWorldSpaceUIScr.ShowReloadPrompt(true);
                    }
                }

                if (!bHasSwitchedWeapons && bTutorialCanSwitchWeapons)
                {
                    GameObject tutorialManager = GameObject.FindGameObjectWithTag("TutorialManager");
                    if (tutorialManager)
                    {
                        SCR_TutorialManager tutorialManagerScr = tutorialManager.GetComponent <SCR_TutorialManager>();
                        tutorialManagerScr.SetHasSwitchedWeapons();
                    }
                    bHasSwitchedWeapons = true;
                }

                if (prevSelectedWeapon != 3)
                {
                    _grenadeSelected                 = false;
                    _currentlySelectedWeapon         = prevSelectedWeapon;
                    _attackScript.setGrenadeSelected = _grenadeSelected;
                    _attackScript.setGrenadeSCR      = null;
                    _currentWeaponInterface          = (IWeapon)_gunInventory[prevSelectedWeapon].gunObject.GetComponent(typeof(IWeapon));
                    _gunInventory[prevSelectedWeapon].gunObject.SetActive(true);
                    _attackScript.UpdateWeaponInterface(_currentWeaponInterface);
                    if (_currentlySelectedWeapon != 2)
                    {
                        float percentage = _currentWeaponInterface.ReturnClipSize() * playerStats.GetUpgradeLevelMultiplier(PlayerUpgradeType.reload);
                        uiManagerScript.SetGauge(gameObject.tag, (int)percentage);
                        float clipPercentage = _currentWeaponInterface.ClipPercentagerFilled();
                        uiManagerScript.SetCurrentAmmoText(gameObject.tag, clipPercentage * _currentWeaponInterface.ReturnClipSize(), _gunInventory[prevSelectedWeapon].currentAmmo, _currentWeaponInterface.ReturnClipSize());
                        uiManagerScript.SwitchGunImages(gameObject.tag, false, ThrowableType.FireGrenade, false, _currentWeaponInterface.RetrieveGunValues().ReturnGunValues().GUNTYPE, _currentWeaponInterface.RetrieveGunValues().ReturnGunValues().RARITY, _currentWeaponInterface.RetrieveGunValues().ReturnGunValues().EFFECT);
                    }
                    else
                    {
                        uiManagerScript.SetGauge(gameObject.tag, 0);
                        float clipPercentage = _currentWeaponInterface.ClipPercentagerFilled();
                        uiManagerScript.SetCurrentAmmoText(gameObject.tag, clipPercentage * _currentWeaponInterface.ReturnClipSize(), _gunInventory[prevSelectedWeapon].currentAmmo, _currentWeaponInterface.ReturnClipSize(), true);
                        uiManagerScript.SwitchGunImages(gameObject.tag, false, ThrowableType.FireGrenade, true);
                    }


                    PlaySwitchingSound();
                }
                else
                {
                    _currentWeaponInterface  = null;
                    _currentlySelectedWeapon = prevSelectedWeapon;
                    _grenadeSelected         = true;
                    SCR_GrenadeParent currentGrenadeScript = _gunInventory[_currentlySelectedWeapon].gunObject.GetComponent <SCR_GrenadeParent>();
                    _attackScript.setGrenadeSCR            = currentGrenadeScript;
                    currentGrenadeScript.bHasResetVelocity = false;
                    _attackScript.setGrenadeSelected       = _grenadeSelected;
                    _gunInventory[_currentlySelectedWeapon].gunObject.SetActive(true);



                    if (_gunInventory[_currentlySelectedWeapon].currentAmmo > 0)
                    {
                        currentGrenadeScript.setCurrentAmmo(_gunInventory[_currentlySelectedWeapon].currentAmmo);
                        //_gunInventory[_currentlySelectedWeapon].currentAmmo = 0;
                    }
                    uiManagerScript.SetCurrentAmmoText(gameObject.tag, _gunInventory[_currentlySelectedWeapon].currentAmmo, 0, 0);
                    uiManagerScript.SetGauge(gameObject.tag, 0);

                    if (currentGrenadeScript)
                    {
                        uiManagerScript.SwitchGunImages(gameObject.tag, true, currentGrenadeScript.GetGrenadeType());
                    }

                    weaponSwitchingSource.PlayOneShot(grenadeSwitchingClip);
                }

                uiManagerScript.SwitchSelectedWeaponUI(gameObject.tag, prevSelectedWeapon);

                //playerWorldSpaceUIScr.StartWeaponSwitchWorldSpaceUI(switchDirection);
            }
            else
            {
                weaponSwitchingSource.PlayOneShot(failedWeaponSwitchClip);
            }
        }
    }