コード例 #1
0
        // Update input source pose
        private static void UpdateInput(WebXRInputSource inputSource)
        {
            var floatStartId = (int)inputSource.Handedness * 23 + 54;
            var byteStartId  = (int)inputSource.Handedness * 20 + 4;

            inputSource.Position          = ToUnityPosition(_dataArray[floatStartId + 0], _dataArray[floatStartId + 1], _dataArray[floatStartId + 2]);
            inputSource.Rotation          = ToUnityRotation(_dataArray[floatStartId + 3], _dataArray[floatStartId + 4], _dataArray[floatStartId + 5], _dataArray[floatStartId + 6]);
            inputSource.IsPositionTracked = (_byteArray[byteStartId + 0] != 0);

            var eventId = (int)inputSource.Handedness + 1;
            var mask    = _byteArray[eventId];

            if (mask != 0)
            {
                RaiseInputSourceEvent(mask, WebXRInputSourceEventTypes.Select, InputSourceSelect, inputSource.Select, inputSource);
                RaiseInputSourceEvent(mask, WebXRInputSourceEventTypes.SelectEnd, InputSourceSelectEnd, inputSource.SelectEnd, inputSource);
                RaiseInputSourceEvent(mask, WebXRInputSourceEventTypes.SelectStart, InputSourceSelectStart, inputSource.SelectStart, inputSource);
                RaiseInputSourceEvent(mask, WebXRInputSourceEventTypes.Squeeze, InputSourceSqueeze, inputSource.Squeeze, inputSource);
                RaiseInputSourceEvent(mask, WebXRInputSourceEventTypes.SqueezeEnd, InputSourceSqueezeEnd, inputSource.SqueezeEnd, inputSource);
                RaiseInputSourceEvent(mask, WebXRInputSourceEventTypes.SqueezeStart, InputSourceSqueezeStart, inputSource.SqueezeStart, inputSource);

                _byteArray[eventId] = 0;
            }

            inputSource.TargetRayMode = (WebXRTargetRayModes)_byteArray[byteStartId + 1];

            inputSource.AxesCount = _byteArray[byteStartId + 2];
            for (int i = 0; i < WebXRInputSource.AXES_BUTTON_COUNT; i++)
            {
                inputSource.Axes[i] = _dataArray[floatStartId + 7 + i];
            }

            inputSource.ButtonsCount = _byteArray[byteStartId + 3];
            for (int i = 0; i < WebXRInputSource.AXES_BUTTON_COUNT; i++)
            {
                var button = inputSource.Buttons[i];
                button.Value   = _dataArray[floatStartId + 15 + i];
                button.Touched = _byteArray[byteStartId + 4 + i] != 0;
                button.Pressed = _byteArray[byteStartId + 12 + i] != 0;
            }

            var handAvailable = 0 != _byteArray[46 + (int)inputSource.Handedness];

            inputSource.Hand.Available = handAvailable;
            if (handAvailable)
            {
                for (int j = 0; j < 25; j++)
                {
                    var i     = (int)inputSource.Handedness * 200 + j * 8;
                    var joint = inputSource.Hand.Joints[j];
                    joint.Position = ToUnityPosition(_handData[i], _handData[i + 1], _handData[i + 2]);
                    joint.Rotation = ToUnityRotation(_handData[i + 3], _handData[i + 4], _handData[i + 5], _handData[i + 6]);
                    joint.Radius   = _handData[i + 7];
                }
            }
        }
コード例 #2
0
        // Raise input sources select and squeeze events
        private static void RaiseInputSourceEvent(byte mask, WebXRInputSourceEventTypes type, WebXRInputEvent webxrInputEvent, UnityEvent unityEvent, WebXRInputSource inputSource)
        {
            if (((WebXRInputSourceEventTypes)mask & type) == type)
            {
                switch (type)
                {
                case WebXRInputSourceEventTypes.SelectStart:
                    inputSource.Selected = true;
                    break;

                case WebXRInputSourceEventTypes.SelectEnd:
                    inputSource.Selected = false;
                    break;

                case WebXRInputSourceEventTypes.SqueezeStart:
                    inputSource.Squeezed = true;
                    break;

                case WebXRInputSourceEventTypes.SqueezeEnd:
                    inputSource.Squeezed = false;
                    break;
                }

                unityEvent.Invoke();
                webxrInputEvent.Invoke(inputSource);

                Debug.Log($"{inputSource.Handedness} : {type}");
            }
        }