コード例 #1
0
        private static void PlayerSwitchedWeapon(ItemEquippable item)
        {
            float muzzleDistance = 0;

            if (item.MuzzleAlign)
            {
                muzzleDistance = Vector3.Distance(item.transform.position, item.MuzzleAlign.position);
            }

            Log.Debug($"Item {item.ArchetypeName} - MuzzleDistance {muzzleDistance} - Allows DH? {muzzleDistance > 0.25f}");

            if (weaponArchetypes.TryGetValue(item.ArchetypeName, out VRWeaponData data))
            {
                m_current = data;

                item.transform.localScale = Vector3.one * m_current.scaleMultiplier;
            }
            else
            {
                if (item.ItemDataBlock.inventorySlot.Equals(Player.InventorySlot.GearStandard) || item.ItemDataBlock.inventorySlot.Equals(Player.InventorySlot.GearSpecial))
                {
                    VRWeaponData currentData = new VRWeaponData(Vector3.zero, Quaternion.identity, false);
                    currentData.allowsDoubleHanded = muzzleDistance > 0.25f;
                    weaponArchetypes.Add(item.ArchetypeName, currentData);
                    m_current = currentData;
                    Log.Debug($"Item {item.ArchetypeName} - MuzzleDistance {muzzleDistance} - Allows DH? {currentData.allowsDoubleHanded}");
                }
                else
                {
                    m_current = weaponArchetypes["Default"];
                }
            }
        }
コード例 #2
0
        public static void Setup()
        {
            ItemEquippableEvents.OnPlayerWieldItem += PlayerSwitchedWeapon;
            // WeaponTransform (z+ forward, y+ up, x+ right)
            weaponArchetypes = new Dictionary <string, VRWeaponData>
            {
                { "Default", new VRWeaponData(new Vector3(0f, 0f, 0f), false) },
                { "Melee", new VRWeaponData(new Vector3(0f, -.25f, 0f), Quaternion.Euler(new Vector3(45f - VRConfig.configWeaponRotationOffset.Value, 0, 0)), false, 1.15f) },

                { "Mine deployer", new VRWeaponData(new Vector3(0f, 0f, -.05f), false) },
                { "Bio Tracker", new VRWeaponData(new Vector3(0f, 0f, -.05f), false, 1.3f) },

                { "Pistol", new VRWeaponData(new Vector3(0f, 0f, 0f), false, 1.1f) },
                { "Revolver", new VRWeaponData(new Vector3(0f, -.01f, 0f), false) },
                { "HEL Revolver", new VRWeaponData(new Vector3(.0f, 0f, 0f), false) },
                { "Autorevolver", new VRWeaponData(new Vector3(.0f, 0f, 0f), false) },
                { "Autopistol", new VRWeaponData(new Vector3(.0f, 0f, 0f), false) },
                { "Machinepistol", new VRWeaponData(new Vector3(.0f, 0f, 0f), false) },

                { "Shotgun", new VRWeaponData(new Vector3(0f, 0f, -.05f), true) },
                { "Combat Shotgun", new VRWeaponData(new Vector3(0f, 0f, 0f), true) },
                { "Choke Mod Shotgun", new VRWeaponData(new Vector3(0f, 0f, 0f), true) },


                { "Carbine", new VRWeaponData(new Vector3(.0f, 0f, 0f), true) },
                { "SMG", new VRWeaponData(new Vector3(0f, 0f, -.15f), true) },

                { "Sniper", new VRWeaponData(new Vector3(0f, 0f, -.05f), true) },
                { "DMR", new VRWeaponData(new Vector3(0f, 0f, -.05f), true) },
                { "Long gun", new VRWeaponData(new Vector3(0f, 0f, -.05f), true) },
                { "HEL Gun", new VRWeaponData(new Vector3(.0f, 0f, 0f), true) },

                { "Assault Rifle", new VRWeaponData(new Vector3(.0f, 0f, 0f), true) },
                { "Burst Rifle", new VRWeaponData(new Vector3(0f, 0f, 0f), true) },
                { "Bullpup Rifle", new VRWeaponData(new Vector3(.0f, 0f, -.08f), true) },
                { "Rifle", new VRWeaponData(new Vector3(.0f, 0f, 0f), true) },
                { "HEL Rifle", new VRWeaponData(new Vector3(.0f, 0f, 0f), true) },

                { "Machinegun", new VRWeaponData(new Vector3(0f, 0f, -.07f), true) },
                { "Burst Cannon", new VRWeaponData(new Vector3(.0f, 0f, 0f), true) }
            };

            m_current = weaponArchetypes["Default"];
        }
コード例 #3
0
        private void CheckShouldDoubleHand(ItemEquippable item)
        {
            if (!VRConfig.configUseTwoHanded.Value)
            {
                return;
            }
            VRWeaponData itemData = GetVRWeaponData(item);

            if (itemData.allowsDoubleHanded)
            {
                Log.Debug("Item allows double hand!");
                if (VRConfig.configAlwaysDoubleHanded.Value)
                {
                    Log.Debug("Always double hand is on!");
                    aimingTwoHanded = true;
                }
            }
            else
            {
                aimingTwoHanded = false;
            }
        }
コード例 #4
0
        private void HandleDoubleHandedChecks()
        {
            bool isInDoubleHandPos = false;

            if (FocusStateEvents.currentState == eFocusState.FPS)
            {
                VRWeaponData itemData = GetVRWeaponData(ItemEquippableEvents.currentItem);

                if (itemData.allowsDoubleHanded)
                {
                    bool wasAimingTwoHanded = aimingTwoHanded;
                    isInDoubleHandPos = AreControllersWithinDoubleHandStartDistance();

                    if (!aimingTwoHanded && !m_wasInDoubleHandPosLastFrame && isInDoubleHandPos)
                    {
                        SteamVR_InputHandler.TriggerHapticPulse(0.025f, 1 / .025f, 0.3f, GetDeviceFromHandType(offHandControllerType));
                    }

                    if (aimingTwoHanded)
                    {
                        aimingTwoHanded = !AreControllersOutsideOfDoubleHandExitDistance();
                        if (wasAimingTwoHanded && !aimingTwoHanded)
                        {
                            SteamVR_InputHandler.TriggerHapticPulse(0.025f, 1 / .025f, 0.3f, GetDeviceFromHandType(offHandControllerType));
                        }
                    }
                    else
                    {
                        aimingTwoHanded = AreControllersWithinDoubleHandStartDistance();
                    }
                }
                else
                {
                    aimingTwoHanded = false;
                }
                m_wasInDoubleHandPosLastFrame = isInDoubleHandPos;
            }
        }
コード例 #5
0
        void Update()
        {
            bool isInDoubleHandPos = false;

            if (PlayerVR.LoadedAndInGame)
            {
                VRWeaponData itemData = WeaponArchetypeVRData.GetVRWeaponData(ItemEquippableEvents.currentItem);
                if (itemData.allowsDoubleHanded)
                {
                    bool wasAimingTwoHanded = aimingTwoHanded;
                    isInDoubleHandPos = AreControllersInDoubleHandedPosition();

                    if (!aimingTwoHanded && !wasInDoubleHandPosLastFrame && isInDoubleHandPos)
                    {
                        VRInput.TriggerHapticPulse(0.025f, 1 / .025f, 0.3f, GetDeviceFromType(offHandControllerType));
                    }

                    if (aimingTwoHanded)
                    {
                        aimingTwoHanded = !AreControllersOutsideOfDoubleHandedAimingRange();
                        if (wasAimingTwoHanded && !aimingTwoHanded)
                        {
                            VRInput.TriggerHapticPulse(0.025f, 1 / .025f, 0.3f, GetDeviceFromType(offHandControllerType));
                        }
                    }
                    else
                    {
                        aimingTwoHanded = AreControllersInDoubleHandedPosition();
                    }
                }
                else
                {
                    aimingTwoHanded = false;
                }
                wasInDoubleHandPosLastFrame = isInDoubleHandPos;
            }
        }