IsValidIndex() приватный Метод

private IsValidIndex ( uint index ) : bool
index uint
Результат bool
            // return true if  frame skipped
            public override bool Update()
            {
                if (Time.frameCount == updatedFrameCount)
                {
                    return(true);
                }
                updatedFrameCount = Time.frameCount;

                var deviceIndex = m_map.GetMappedDeviceByRoleValue(m_roleValue);

                if (deviceIndex == updatedDeviceIndex && !ViveRole.IsValidIndex(deviceIndex))
                {
                    return(false);
                }
                updatedDeviceIndex = deviceIndex;

                previousState = currentState;
                currentState  = ViveRole.IsValidIndex(deviceIndex) ? s_controllerStats[deviceIndex] : default(VRControllerState_t);

                this.UpdateHairTrigger();

                if (GetPressDown(ControllerButton.Pad))
                {
                    padDownAxis = GetAxis();
                }
                if (GetPressDown(ControllerButton.PadTouch))
                {
                    padTouchDownAxis = GetAxis();
                }

                for (int i = 0; i < CONTROLLER_BUTTON_COUNT; ++i)
                {
                    UpdateClickCount((ControllerButton)i);
                }

                for (int i = 0; i < CONTROLLER_BUTTON_COUNT; ++i)
                {
                    InvokeEvent((ControllerButton)i);
                }

                return(false);
            }
Пример #2
0
            public void Update()
            {
                if (Time.frameCount != prevFrameCount)
                {
                    prevFrameCount = Time.frameCount;
                    previousState  = currentState;

                    CVRSystem system;
                    index = ViveRole.GetDeviceIndex(role);
                    if (!ViveRole.IsValidIndex(index) || (system = OpenVR.System) == null || !system.GetControllerState(index, ref currentState))
                    {
                        currentState = default(VRControllerState_t);
                    }

                    UpdateHairTrigger();

                    if (GetPressDown(ControllerButton.Pad))
                    {
                        padDownAxis = GetAxis();
                    }
                    if (GetPressDown(ControllerButton.PadTouch))
                    {
                        padTouchDownAxis = GetAxis();
                    }

                    for (int i = 0; i < ViveInput.CONTROLLER_BUTTON_COUNT; ++i)
                    {
                        UpdateClickCount((ControllerButton)i);
                    }

                    for (int i = 0; i < ViveInput.CONTROLLER_BUTTON_COUNT; ++i)
                    {
                        InvokeEvent((ControllerButton)i);
                    }
                }
            }
Пример #3
0
        // unmapping all and mapping only right/left hands
        private void MappingHandsAndOthers()
        {
            UnmappingAll();

            var system     = OpenVR.System;
            var rightIndex = ViveRole.INVALID_DEVICE_INDEX;
            var leftIndex  = ViveRole.INVALID_DEVICE_INDEX;

            var trackedControllerCount = 0;

            if (system != null)
            {
                leftIndex  = system.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand);
                rightIndex = system.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.RightHand);

                if (RoleMap.IsDeviceMapped(leftIndex))
                {
                    leftIndex = ViveRole.INVALID_DEVICE_INDEX;
                }
                if (RoleMap.IsDeviceMapped(rightIndex))
                {
                    rightIndex = ViveRole.INVALID_DEVICE_INDEX;
                }

                trackedControllerCount = (int)system.GetSortedTrackedDeviceIndicesOfClass(ETrackedDeviceClass.Controller, m_sortedDevices, 0);
            }

            if (ViveRole.IsValidIndex(rightIndex))
            {
                MappingRoleIfUnbound(HandRole.RightHand, rightIndex);
            }

            if (ViveRole.IsValidIndex(leftIndex) && leftIndex != rightIndex)
            {
                MappingRoleIfUnbound(HandRole.LeftHand, leftIndex);
            }

            if (!RoleMap.IsRoleMapped(HandRole.RightHand) && !RoleMap.IsRoleBound(HandRole.RightHand))
            {
                // find most right side controller
                for (var i = 0; i < trackedControllerCount; ++i)
                {
                    if (RoleMap.IsDeviceMapped(m_sortedDevices[i]))
                    {
                        continue;
                    }
                    MappingRole(HandRole.RightHand, m_sortedDevices[i]);
                    break;
                }
            }

            if (!RoleMap.IsRoleMapped(HandRole.LeftHand) && !RoleMap.IsRoleBound(HandRole.LeftHand))
            {
                // find most left side controller
                for (var i = trackedControllerCount - 1; i >= 0; --i)
                {
                    if (RoleMap.IsDeviceMapped(m_sortedDevices[i]))
                    {
                        continue;
                    }
                    MappingRole(HandRole.LeftHand, m_sortedDevices[i]);
                    break;
                }
            }

            MappingOthers();
        }