コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (!WaveVR.Instance.Initialized)
        {
            return;
        }
        if (WaveVR.Instance.FocusCapturedBySystem)
        {
            return;
        }

#if UNITY_EDITOR
        if (Application.isEditor)
        {
            return;
        }
#endif
        if (!WaveVR_Controller.Input(this.device).connected)
        {
            return;
        }

        WVR_DeviceType _type = WaveVR_Controller.Input(this.device).DeviceType;
        uint           buttons = 0, touches = 0;

        uint analogArrayCount           = (uint)Interop.WVR_GetInputTypeCount(_type, WVR_InputType.WVR_InputType_Analog);
        WVR_AnalogState_t[] analogArray = new WVR_AnalogState_t[analogArrayCount];
        if (Interop.WVR_GetInputDeviceState(_type, inputMask, ref buttons, ref touches, analogArray, analogArrayCount))
        {
            ClickedEventArgs e;
            e.device = _type;
            e.flags  = buttons;
            e.axis   = Vector2.zero;

            /**
             * for Button
             **/
            if (buttons != 0)
            {
                ulong btnState = (ulong)buttons;

                //if (Log.FLAG_BUTTON)
                //	Log.d (LOG_TAG, "_type: " + _type + " btnState: " + btnState);

                if ((btnState & Input_Mask_Trigger) != 0)
                {
                    if (triggerPressed == false)                        // trigger false -> true
                    {
                        triggerPressed = true;
                        e.axis         = GetAxis(
                            analogArray,
                            WVR_InputId.WVR_InputId_Alias1_Trigger,
                            WVR_AnalogType.WVR_AnalogType_1D,
                            (int)analogArrayCount);
                        OnTriggerClicked(e);
                    }
                }

                if ((btnState & Input_Mask_Grip) != 0)
                {
                    if (gripPressed == false)                       // grep false -> true
                    {
                        gripPressed = true;
                        OnGripped(e);
                    }
                }

                if ((btnState & Input_Mask_Touchpad) != 0)
                {
                    if (padPressed == false)                            // touchpad false -> true
                    {
                        e.axis = GetAxis(
                            analogArray,
                            WVR_InputId.WVR_InputId_Alias1_Touchpad,
                            WVR_AnalogType.WVR_AnalogType_2D,
                            (int)analogArrayCount);
                        padPressed = true;
                        OnPadClicked(e);
                    }
                }

                if ((btnState & Input_Mask_Menu) != 0)
                {
                    if (menuPressed == false)                       // menu false -> true
                    {
                        menuPressed = true;
                        OnMenuClicked(e);
                    }
                }

                if ((btnState & Input_Mask_Hmd_Enter) != 0)
                {
                    if (hmdEnterPressed == false)
                    {
                        hmdEnterPressed = true;
                        OnHmdEnterClicked(e);
                    }
                }
            }
            else
            {
                if (triggerPressed == true)
                {
                    triggerPressed = false;
                    OnTriggerUnclicked(e);
                }
                if (gripPressed == true)
                {
                    gripPressed = false;
                    OnUngripped(e);
                }
                if (padPressed == true)
                {
                    padPressed = false;
                    OnPadUnclicked(e);
                }
                if (menuPressed == true)
                {
                    menuPressed = false;
                    OnMenuUnclicked(e);
                }
                if (hmdEnterPressed == true)
                {
                    hmdEnterPressed = false;
                    OnHmdEnterUnclicked(e);
                }
            }               // if (buttons != 0)

            /**
             *  for Touch
             **/
            e.flags = touches;
            if (touches != 0)
            {
                ulong touchState = (ulong)touches;

                //if (Log.FLAG_BUTTON)
                //	Log.d (LOG_TAG, "_type: " + _type + " touchState: " + touchState);

                if ((touchState & Input_Mask_Touchpad) != 0)
                {
                    if (padTouched == false)                            // touchpad false -> true
                    {
                        padTouched = true;
                        e.axis     = GetAxis(
                            analogArray,
                            WVR_InputId.WVR_InputId_Alias1_Touchpad,
                            WVR_AnalogType.WVR_AnalogType_2D,
                            (int)analogArrayCount);
                        OnPadTouched(e);
                    }
                }
            }
            else
            {
                if (padTouched == true)
                {
                    padTouched = false;
                    OnPadUntouched(e);
                }
            }               // if (touches != 0)
        }
        else
        {
            Log.e(LOG_TAG, "_type: " + _type + " WVR_GetInputDeviceState failed!");
        }   // WVR_GetInputDeviceState
    }       // Update
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (WaveVR.Instance == null)
        {
            return;
        }

        if (!WaveVR_Controller.Input(device).connected)
        {
            return;
        }

        uint buttons = 0, touches = 0;

        int analogArrayCount = Interop.WVR_GetInputTypeCount(device, WVR_InputType.WVR_InputType_Analog);

        WVR_AnalogState_t[] analogArray = new WVR_AnalogState_t[analogArrayCount];
        if (Interop.WVR_GetInputDeviceState(device, inputMask, ref buttons, ref touches, analogArray, analogArrayCount))
        {
            ClickedEventArgs e;
            e.device = device;
            e.flags  = buttons;
            e.axis   = Vector2.zero;

            /**
             * for Button
             **/
            if (buttons != 0)
            {
                ulong btnState = (ulong)buttons;

                //if (Log.FLAG_BUTTON)
                //    Log.d (LOG_TAG, "device: " + device + " btnState: " + btnState);

                if ((btnState & WaveVR_Controller.Device.Input_Mask_Trigger) != 0)
                {
                    if (triggerPressed == false)    // trigger false -> true
                    {
                        triggerPressed = true;
                        e.axis         = GetAxis(
                            analogArray,
                            WVR_InputId.WVR_InputId_Alias1_Trigger,
                            WVR_AnalogType.WVR_AnalogType_Trigger,
                            analogArrayCount);
                        OnTriggerClicked(e);
                    }
                }

                if ((btnState & WaveVR_Controller.Device.Input_Mask_Grip) != 0)
                {
                    if (gripPressed == false)   // grep false -> true
                    {
                        gripPressed = true;
                        OnGripped(e);
                    }
                }

                if ((btnState & WaveVR_Controller.Device.Input_Mask_Touchpad) != 0)
                {
                    if (padPressed == false)    // touchpad false -> true
                    {
                        e.axis = GetAxis(
                            analogArray,
                            WVR_InputId.WVR_InputId_Alias1_Touchpad,
                            WVR_AnalogType.WVR_AnalogType_TouchPad,
                            analogArrayCount);
                        padPressed = true;
                        OnPadClicked(e);
                    }
                }

                if ((btnState & WaveVR_Controller.Device.Input_Mask_Menu) != 0)
                {
                    if (menuPressed == false)   // menu false -> true
                    {
                        menuPressed = true;
                        OnMenuClicked(e);
                    }
                }
            }
            else
            {
                if (triggerPressed == true)
                {
                    triggerPressed = false;
                    OnTriggerUnclicked(e);
                }
                if (gripPressed == true)
                {
                    gripPressed = false;
                    OnUngripped(e);
                }
                if (padPressed == true)
                {
                    padPressed = false;
                    OnPadUnclicked(e);
                }
                if (menuPressed == true)
                {
                    menuPressed = false;
                    OnMenuUnclicked(e);
                }
            }   // if (buttons != 0)

            /**
             *  for Touch
             **/
            e.flags = touches;
            if (touches != 0)
            {
                ulong touchState = (ulong)touches;

                //if (Log.FLAG_BUTTON)
                //    Log.d (LOG_TAG, "device: " + device + " touchState: " + touchState);

                if ((touchState & WaveVR_Controller.Device.Input_Mask_Touchpad) != 0)
                {
                    if (padTouched == false)    // touchpad false -> true
                    {
                        padTouched = true;
                        e.axis     = GetAxis(
                            analogArray,
                            WVR_InputId.WVR_InputId_Alias1_Touchpad,
                            WVR_AnalogType.WVR_AnalogType_TouchPad,
                            analogArrayCount);
                        OnPadTouched(e);
                    }
                }
                else
                {
                }
            }
            else
            {
                if (padTouched == true)
                {
                    padTouched = false;
                    OnPadUntouched(e);
                }
            }   // if (touches != 0)
        }
        else
        {
            Log.e(LOG_TAG, "device: " + device + " WVR_GetInputDeviceState failed!");
        } // WVR_GetInputDeviceState
    }     // Update