Exemplo n.º 1
0
        //アナログ軸の状態を取得する(生データ)
        private void GetAnalogActionDataRaw(string ActionPath, out InputAnalogActionData_t data, string RestrictToDevicePath = "")
        {
            ReadyCheck(); //実行可能な状態かチェック

            EVRInputError inputError = EVRInputError.None;

            data = new InputAnalogActionData_t();

            var   size   = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(InputAnalogActionData_t));
            ulong handle = GetActionHandle(ActionPath); //無効なハンドルならthrowされる

            //制約デバイス指定されていれば適用
            ulong DeviceHandle = OpenVR.k_ulInvalidInputValueHandle;

            if (RestrictToDevicePath != "")
            {
                DeviceHandle = GetInputSourceHandle(RestrictToDevicePath); //無効なハンドルならthrowされる
            }

            //取得処理
            inputError = vrinput.GetAnalogActionData(handle, ref data, size, DeviceHandle);
            if (inputError == EVRInputError.WrongType)
            {
                //アナログ軸ではない
                throw new ArgumentException(inputError.ToString());
            }
            if (inputError != EVRInputError.None)
            {
                //致命的エラー
                throw new IOException(inputError.ToString());
            }

            return;
        }
        /// <summary><strong>[Should not be called by user code]</strong>
        /// Updates the data for this action and this input source. Sends related events.
        /// </summary>
        public override void UpdateValue()
        {
            lastActionData = actionData;
            lastActive     = active;

            EVRInputError err = OpenVR.Input.GetAnalogActionData(handle, ref actionData, actionData_size,
                                                                 SteamVR_Input_Source.GetHandle(inputSource));

            if (err != EVRInputError.None)
            {
                Debug.LogError("<b>[SteamVR]</b> GetAnalogActionData error (" + fullPath + "): " + err.ToString() +
                               " handle: " + handle.ToString());
            }

            updateTime = Time.realtimeSinceStartup;

            changed = false;

            if (active)
            {
                if (delta > changeTolerance || delta < -changeTolerance)
                {
                    changed     = true;
                    changedTime =
                        Time.realtimeSinceStartup +
                        actionData
                        .fUpdateTime;     //fUpdateTime is the time from the time the action was called that the action changed

                    if (onChange != null)
                    {
                        onChange.Invoke(singleAction, inputSource, axis, delta);
                    }
                }

                if (axis != 0)
                {
                    if (onAxis != null)
                    {
                        onAxis.Invoke(singleAction, inputSource, axis, delta);
                    }
                }

                if (onUpdate != null)
                {
                    onUpdate.Invoke(singleAction, inputSource, axis, delta);
                }
            }


            if (onActiveBindingChange != null && lastActiveBinding != activeBinding)
            {
                onActiveBindingChange.Invoke(singleAction, inputSource, activeBinding);
            }

            if (onActiveChange != null && lastActive != active)
            {
                onActiveChange.Invoke(singleAction, inputSource, activeBinding);
            }
        }
        /// <summary><strong>[Should not be called by user code]</strong>
        /// Updates the data for this action and this input source. Sends related events.
        /// </summary>
        public override void UpdateValue()
        {
            lastActionData = actionData;
            lastActive     = active;
            lastAxis       = axis;
            lastDelta      = delta;

            EVRInputError err = OpenVR.Input.GetAnalogActionData(handle, ref actionData, actionData_size, SteamVR_Input_Source.GetHandle(inputSource));

            if (err != EVRInputError.None)
            {
                Debug.LogError("<b>[SteamVR_Standalone]</b> GetAnalogActionData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString());
            }

            updateTime = Time.realtimeSinceStartup;
            axis       = new Vector3(actionData.x, actionData.y, actionData.z);
            delta      = new Vector3(actionData.deltaX, actionData.deltaY, actionData.deltaZ);

            changed = false;

            if (active)
            {
                if (delta.magnitude > changeTolerance)
                {
                    changed     = true;
                    changedTime = Time.realtimeSinceStartup + actionData.fUpdateTime; //fUpdateTime is the time from the time the action was called that the action changed

                    if (onChange != null)
                    {
                        onChange.Invoke(vector3Action, inputSource, axis, delta);
                    }
                }

                if (axis != Vector3.zero)
                {
                    if (onAxis != null)
                    {
                        onAxis.Invoke(vector3Action, inputSource, axis, delta);
                    }
                }

                if (onUpdate != null)
                {
                    onUpdate.Invoke(vector3Action, inputSource, axis, delta);
                }
            }


            if (onActiveBindingChange != null && lastActiveBinding != activeBinding)
            {
                onActiveBindingChange.Invoke(vector3Action, inputSource, activeBinding);
            }

            if (onActiveChange != null && lastActive != active)
            {
                onActiveChange.Invoke(vector3Action, inputSource, activeBinding);
            }
        }
Exemplo n.º 4
0
        internal static InputAnalogActionData_t GetAnalogActionData(ulong actionHandle)
        {
            InputAnalogActionData_t actionData = default;

            EVRInputError error = OpenVR.Input.GetAnalogActionData(actionHandle, ref actionData, (uint)Marshal.SizeOf(typeof(InputAnalogActionData_t)), OpenVR.k_ulInvalidInputValueHandle);

            if (error != EVRInputError.None && error != EVRInputError.NoData)
            {
                throw new OpenVRInputException($"Could not get analog data for action with handle {actionHandle}: {error}", error);
            }

            return(actionData);
        }
Exemplo n.º 5
0
        public static void UpdateOrAddAnalogInputActionData(InputAnalogActionData_t data, InputActionInfo info)
        {
            var source = handleToSource[info.sourceHandle];

            if (!analogInputActionData.ContainsKey(source))
            {
                analogInputActionData[source] = new ConcurrentDictionary <string, Vec3>();
            }
            analogInputActionData[source][info.pathEnd] = new Vec3()
            {
                x = data.x, y = data.y, z = data.z
            };
        }
Exemplo n.º 6
0
        private Vector3 GetAnalogState(ulong handle, ulong hand)
        {
            var dataSize = Marshal.SizeOf <InputAnalogActionData_t>();
            var data     = new InputAnalogActionData_t();
            var error    = input.GetAnalogActionData(handle, ref data, (uint)dataSize, hand);

            #if UNITY_EDITOR
            if (error != EVRInputError.None && error != EVRInputError.NoData)
            {
                Debug.LogError("GetAnalogActionData: " + error.ToString());
                return(Vector3.zero);
            }
            #endif
            return(new Vector3(data.x, data.y, data.z));
        }
Exemplo n.º 7
0
            public float UpdateTime = float.NaN; //変化時間

            public AnalogAction(InputAnalogActionData_t Data, OriginSource OriginInfo)
            {
                Available = Data.bActive;
                Origin    = OriginInfo;

                x = Data.x;
                y = Data.y;
                z = Data.z;

                deltaX = Data.deltaX;
                deltaY = Data.deltaY;
                deltaZ = Data.deltaZ;

                UpdateTime = Data.fUpdateTime;
            }
Exemplo n.º 8
0
        private Vector2 GetVector2Input(ulong action, XRNodeState node)
        {
            InputAnalogActionData_t data = new InputAnalogActionData_t();

            var res = OpenVR.Input.GetAnalogActionData(
                action, ref data,
                (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(InputAnalogActionData_t)),
                node.nodeType == XRNode.LeftHand ? leftHand : rightHand
                );

            if (res != EVRInputError.None)
            {
                throw new ApplicationException("Failed to get vector input data " + node.nodeType + ": " + res);
            }

            return(new Vector2(data.x, data.y));
        }
Exemplo n.º 9
0
        public ControllerEvent()
        {
            switch (EventType())
            {
            case EventTypeEmun.Digital:
                Digital = new InputDigitalActionData_t();
                break;

            case EventTypeEmun.Analog:
                Analog = new InputAnalogActionData_t();
                break;

            case EventTypeEmun.Pose:
                Pose     = new InputPoseActionData_t();
                Position = new HmdVector3_t();
                break;
            }
        }
Exemplo n.º 10
0
            public bool TryGetCurrentAnalogData(CVRInput vrInput, out IVRModuleDeviceState prevState, out IVRModuleDeviceStateRW currState, ref InputAnalogActionData_t data)
            {
                ulong originDevicePath;

                if (!TryGetCurrentOriginDataAndDeviceState(vrInput, out prevState, out currState, out originDevicePath))
                {
                    return(false);
                }

                var error = vrInput.GetAnalogActionData(CurrentHandle, ref data, s_moduleInstance.m_analogDataSize, originDevicePath);

                if (error != EVRInputError.None)
                {
                    Debug.LogError("GetAnalogActionData failed! action=" + CurrentPath + " error=" + error);
                    return(false);
                }

                return(true);
            }
Exemplo n.º 11
0
 internal override void UpdateData()
 {
     _actionData = OpenVRWrapper.GetAnalogActionData(handle);
 }
Exemplo n.º 12
0
 internal override void UpdateData()
 {
     _actionData = OpenVRFacade.GetAnalogActionData(handle);
 }