Example #1
0
    public override void OnInspectorGUI()
    {
        ReflectionUpdateGroup rug = (ReflectionUpdateGroup)target;

        base.OnInspectorGUI();
        GUILayout.Space(10f);

        if (GUILayout.Button("AUTO-ASSIGN"))
        {
            rendList = new List <Renderer>();
            RecursiveFindRenderers(rug.transform);
            rug.allRenderers = rendList.ToArray();
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(rug);
        }
    }
Example #2
0
    private IEnumerator SelectWeaponCoroutine(int weaponIndex, bool immediate)
    {
        prepareToSwitch = true;

        while (ac.aimTransition > 0.05f)
        {
            yield return(0);
        }

        prepareToSwitch = false;

        if (currentGC != null && currentGC.reloading)
        {
            currentGC.CancelReload();
        }

        int prevWeaponNum = curWeaponNum;

        if (Topan.Network.isConnected && rootNetView != null)
        {
            if (weaponIndex == 0 || weaponIndex == 1)
            {
                rootNetView.RPC(Topan.RPCMode.OthersBuffered, "RefreshWeapon", (byte)heldWeapons[weaponIndex].weaponID);

                if (heldWeapons[weaponIndex].gunVisuals != null && heldWeapons[weaponIndex].gunVisuals.flashlight != null)
                {
                    rootNetView.RPC(Topan.RPCMode.OthersBuffered, "SetFlashlight", heldWeapons[weaponIndex].flashlightOn);
                }
            }
            else
            {
                if (weaponIndex <= -1)
                {
                    rootNetView.RPC(Topan.RPCMode.OthersBuffered, "SetSpecialActive", (byte)0); //Hands
                }
                else if (weaponIndex == 2)
                {
                    rootNetView.RPC(Topan.RPCMode.OthersBuffered, "SetSpecialActive", (byte)1); //Melee
                }
                else if (weaponIndex == 3)
                {
                    grenadeManager.OnSelect(true);
                }
            }
        }

        if (!immediate)
        {
            if (!isQuickThrowState)
            {
                curAmmoDisplay.text  = "--";
                ammoLeftDisplay.text = "---";
            }

            float weightFactorTime = 0f;
            if (weaponIndex == 0 || weaponIndex == 1)
            {
                if (ignoreWeightDelayOnce)
                {
                    ignoreWeightDelayOnce = false;
                }
                else
                {
                    weightFactorTime = (heldWeapons[weaponIndex].weaponWeight * 0.05f);
                }
            }

            dm.Draw(drawTime + weightFactorTime);
            switching          = true;
            pv.jumpRattleEquip = true;

            float waitPeriod       = 0f;
            bool  cyclingGrenades  = false;
            bool  ignoreFirstPress = true;
            while (waitPeriod < drawTime + weightFactorTime)
            {
                if (weaponIndex == 3 && Input.GetKeyDown(KeyCode.Alpha4) && grenadeManager.availableGrenades.Count > 1)
                {
                    if (!ignoreFirstPress)
                    {
                        cyclingGrenades = true;

                        if (grenadeManager.grenadeIndex == 0 && gam.typeTwoGrenades > 0)
                        {
                            grenadeManager.grenadeIndex = 1;
                        }
                        else if (grenadeManager.grenadeIndex == 1 && gam.typeOneGrenades > 0)
                        {
                            grenadeManager.grenadeIndex = 0;
                        }

                        grenadeSelection.alpha     = grenadeSelection.defaultAlpha;
                        grenadeSelectionLabel.text = grenadeManager.grenadeInventory[grenadeManager.grenadeIndex].grenadeName;

                        dm.ExtendDrawTime(waitPeriod);
                        waitPeriod = 0f;
                    }
                    else
                    {
                        grenadeSelectionLabel.alpha = 0.4f;
                    }

                    ignoreFirstPress = false;
                }

                if (cyclingGrenades)
                {
                    grenadeSelectionLabel.alpha = Mathf.Lerp(grenadeSelectionLabel.alpha, 0.8f, Time.deltaTime * 18f);
                }

                waitPeriod += Time.deltaTime;
                yield return(null);
            }

            switching = false;
        }

        bool          sameWeapon = false;
        GunController gc1        = null;
        GunController gc2        = null;

        if (prevWeaponNum > -1 && prevWeaponNum >= 0 && prevWeaponNum <= 1 && weaponIndex >= 0 && weaponIndex <= 1)
        {
            gc1 = heldWeapons[prevWeaponNum];
            gc2 = heldWeapons[weaponIndex];

            if (gc1 != null && gc2 != null && gc1.weaponID == gc2.weaponID)
            {
                sameWeapon = true;
            }
        }

        if (weaponIndex > -2)
        {
            pv.jumpRattleEquip = true;
            GetComponent <AudioSource>().PlayOneShot(drawSound, 0.2f);
        }

        if (currentWeaponTransform == grenadeManager.transform)
        {
            grenadeManager.OnDeselect();
        }

        DeselectAll();

        curWeaponNum  = weaponIndex;
        curWeaponMode = (curWeaponNum == 0 || curWeaponNum == 1) ? CurrentWeaponMode.GenericWeapon : CurrentWeaponMode.AlternateWeapon;

        if (curWeaponMode == CurrentWeaponMode.GenericWeapon)
        {
            currentGC.gameObject.SetActive(true);
            currentGC.OnWeaponDraw();
            currentWeaponTransform = currentGC.transform;

            if (queuedAmmo > -1)
            {
                AntiHackSystem.ProtectInt("currentAmmo", queuedAmmo);
                queuedAmmo = -1;
            }

            if (queuedReserve > -1)
            {
                AntiHackSystem.ProtectInt("ammoLeft", queuedReserve);
                queuedReserve = -1;
            }

            currentGC.bulletInChamber = queuedChamber;
            queuedChamber             = false;

            curWepName = currentGC.gunName;

            if (!pe.hasEMP)
            {
                weaponIcon.mainTexture             = currentGC.iconTexture;
                weaponIcon.transform.localPosition = defaultIconPos + new Vector3(currentGC.iconOffset.x, currentGC.iconOffset.y, 0f);
                weaponIcon.SetDimensions((int)currentGC.iconScale.x, (int)currentGC.iconScale.y);
            }
        }
        else
        {
            if (curWeaponNum == 3)
            {
                grenadeManager.gameObject.SetActive(true);
                grenadeManager.OnSelect(false);

                if (pressedQuickThrow)
                {
                    grenadeManager.QuickThrow(prevWeaponNum);
                }

                currentWeaponTransform = grenadeManager.transform;
                pressedQuickThrow      = false;
            }
            else if (curWeaponNum == 2)
            {
                meleeController.gameObject.SetActive(true);
                currentWeaponTransform = meleeController.transform;

                weaponIcon.mainTexture             = meleeController.iconTexture;
                weaponIcon.transform.localPosition = defaultIconPos + new Vector3(meleeController.iconOffset.x, meleeController.iconOffset.y, 0f);
                weaponIcon.SetDimensions((int)meleeController.iconSize.x, (int)meleeController.iconSize.y);
            }
            else if (curWeaponNum <= -1)
            {
                if (curWeaponNum == -1)
                {
                    hands.SetActive(true);
                    currentWeaponTransform = hands.transform;
                }
                else
                {
                    currentWeaponTransform = null;
                }

                curWepName             = "Hands";
                weaponIcon.mainTexture = null;
                weaponIcon.SetDimensions(100, 50);

                curAmmoDisplay.color = Color.white;
                curAmmoDisplay.text  = "---";
                ammoLeftDisplay.text = "---";

                ammoBar.value = 1f;
            }
        }

        StartCoroutine(WeaponNameTransition());

        ReflectionUpdateGroup foundRUG = currentWeaponTransform.GetComponent <ReflectionUpdateGroup>();

        if (foundRUG != null)
        {
            foreach (Renderer r in foundRUG.allRenderers)
            {
                UpdateReflection(r);
            }
        }

        if (sameWeapon)
        {
            gc2.ammoLeft = gc1.ammoLeft;
            AntiHackSystem.ProtectInt("ammoLeft", gc1.ammoLeft);
        }

        if (curWeaponNum < 3 && curWeaponNum != -2)
        {
            dm.sao = currentWeaponTransform.GetComponent <SprintAnimOverride>();
        }

        grenadeSelectionLabel.alpha = 0.2f;
    }