Example #1
0
        private void HandleDeviceInput(IVRModuleDeviceStateRW deviceState)
        {
            //var leftPressed = Input.GetMouseButton(0);
            //var rightPressed = Input.GetMouseButton(1);
            //var midPressed = Input.GetMouseButton(2);

            bool leftPressed;
            bool rightPressed;
            bool midPressed;

            if ((PlatformType)Enum.Parse(typeof(PlatformType), PlayerPrefs.GetString("CurrentPlateform", "PC")) == PlatformType.PC)
            {
                leftPressed  = Input.GetMouseButton(0);
                rightPressed = Input.GetMouseButton(1);
                midPressed   = Input.GetMouseButton(2);
            }
            else if ((PlatformType)Enum.Parse(typeof(PlatformType), PlayerPrefs.GetString("CurrentPlateform", "PC")) == PlatformType.zSpace)
            {
                ZCore _zCore = GameObject.FindObjectOfType <ZCore>();
                midPressed   = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary, 1);
                leftPressed  = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary, 0);
                rightPressed = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary, 2);
            }
            else
            {
                leftPressed  = Input.GetMouseButton(0);
                rightPressed = Input.GetMouseButton(1);
                midPressed   = Input.GetMouseButton(2);
            }
            //Debug.LogError(leftPressed+"|" + midPressed + "|" + midPressed);
            deviceState.SetButtonPress(VRModuleRawButton.Trigger, leftPressed);
            deviceState.SetButtonTouch(VRModuleRawButton.Trigger, leftPressed);
            deviceState.SetAxisValue(VRModuleRawAxis.Trigger, leftPressed ? 1f : 0f);

            deviceState.SetButtonPress(VRModuleRawButton.Grip, midPressed);
            deviceState.SetButtonTouch(VRModuleRawButton.Grip, midPressed);
            deviceState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, midPressed ? 1f : 0f);

            deviceState.SetButtonPress(VRModuleRawButton.Touchpad, rightPressed);

            deviceState.SetButtonPress(VRModuleRawButton.ApplicationMenu, IsMenuKeyDown());
            deviceState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, IsMenuKeyDown());

            if (VIUSettings.simulateTrackpadTouch && IsShiftKeyPressed())
            {
                deviceState.SetButtonTouch(VRModuleRawButton.Touchpad, true);
                deviceState.SetAxisValue(VRModuleRawAxis.TouchpadX, deviceState.GetAxisValue(VRModuleRawAxis.TouchpadX) + (Input.GetAxisRaw("Mouse X") * 0.1f));
                deviceState.SetAxisValue(VRModuleRawAxis.TouchpadY, deviceState.GetAxisValue(VRModuleRawAxis.TouchpadY) + (Input.GetAxisRaw("Mouse Y") * 0.1f));
            }
            else
            {
                deviceState.SetButtonTouch(VRModuleRawButton.Touchpad, rightPressed);
                deviceState.SetAxisValue(VRModuleRawAxis.TouchpadX, 0f);
                deviceState.SetAxisValue(VRModuleRawAxis.TouchpadY, 0f);
            }
        }
        private static void zSpaceDeviceInput(IVRModuleDeviceStateRW deviceState)
        {
            ZCore _zCore = GameObject.FindObjectOfType <ZCore>();

            if (_zCore == null)
            {
                return;
            }
            var midPressed   = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary, 1);
            var leftPressed  = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary, 0);
            var rightPressed = _zCore.IsTargetButtonPressed(ZCore.TargetType.Primary, 2);

            //Debug.LogError("拖拽VRModuleRawButton.Trigger:"+leftPressed + "      |复位VRModuleRawButton.Grip:" + rightPressed + "         |缩放VRModuleRawButton.Touchpad:" + midPressed);

            deviceState.SetButtonPress(VRModuleRawButton.Trigger, leftPressed);
            deviceState.SetButtonPress(VRModuleRawButton.Grip, rightPressed);
            deviceState.SetButtonPress(VRModuleRawButton.Touchpad, midPressed);
        }
Example #3
0
        void Update()
        {
            ZCore.Pose pose            = _core.GetTargetPose(ZCore.TargetType.Primary, ZCore.CoordinateSpace.World);
            bool       isButtonPressed = _core.IsTargetButtonPressed(ZCore.TargetType.Primary, 0) || _core.IsTargetButtonPressed(ZCore.TargetType.Primary, 1);

            switch (_stylusState)
            {
            case StylusState.Idle:
            {
                _stylusBeamLength           = DEFAULT_STYLUS_BEAM_LENGTH;
                sceneManage.CurrentGrabPart = null;
                //对整个场景进行碰撞检测确定与笔进行碰撞的物体
                RaycastHit hit;
                if (Physics.Raycast(pose.Position, pose.Direction, out hit))
                {
                    // 更新zSpace操作笔的长度
                    _stylusBeamLength = hit.distance / _core.ViewerScale;

                    // 如果zSpace触控笔主按钮按下,开始抓取物体。
                    if (isButtonPressed && !_wasButtonPressed)
                    {
                        // 开始抓取
                        this.BeginGrab(hit.collider.gameObject, hit.distance, pose.Position, pose.Rotation);
                        _stylusState = StylusState.Grab;

                        if (lastHoverPart != null && lastHoverPart.GetComponent <FlashingController>() != null)
                        {
                            Destroy(lastHoverPart.GetComponent <FlashingController>());
                            Destroy(lastHoverPart.GetComponent <Highlighter>());
                            lastHoverPart = null;
                        }
                    }
                    else
                    {
                        currentHoverPart = hit.collider.gameObject;
                        if (lastHoverPart != currentHoverPart)
                        {
                            if (lastHoverPart != null && lastHoverPart.GetComponent <FlashingController>() != null)
                            {
                                Destroy(lastHoverPart.GetComponent <FlashingController>());
                                Destroy(lastHoverPart.GetComponent <Highlighter>());
                            }
                            lastHoverPart = currentHoverPart;
                            FlashingController fla = currentHoverPart.AddComponent <FlashingController>();
                            fla.flashingDelay     = 0;
                            fla.flashingFrequency = 1;
                        }
                    }
                }
                else
                {
                    if (lastHoverPart != null && lastHoverPart.GetComponent <FlashingController>() != null)
                    {
                        Destroy(lastHoverPart.GetComponent <FlashingController>());
                        Destroy(lastHoverPart.GetComponent <Highlighter>());
                        lastHoverPart = null;
                    }
                }
            }
            break;

            case StylusState.Grab:
            {
                // Update the grab.
                this.UpdateGrab(pose.Position, pose.Rotation);

                // End the grab if the front stylus button was released.
                if (!isButtonPressed && _wasButtonPressed)
                {
                    _stylusState = StylusState.Idle;
                }
            }
            break;

            default:
                break;
            }
            // 更新zSpace操作笔的位置以及旋转参数。
            this.UpdateStylusBeam(pose.Position, pose.Direction);

            // 为下一帧缓存点击状态.
            _wasButtonPressed = isButtonPressed;
        }