public void OnPointerClick(PointerEventData eventData)
    {
        if (EventSystem.current == null)
        {
            EventSystem _es = FindObjectOfType <EventSystem> ();
            if (_es != null)
            {
                this.eventSystem = _es.gameObject;
            }
        }
        else
        {
            this.eventSystem = EventSystem.current.gameObject;
        }

        WaveVR_ControllerInputModule _cim = null;

        if (this.eventSystem != null)
        {
            _cim = this.eventSystem.GetComponent <WaveVR_ControllerInputModule> ();
            if (_cim != null)
            {
                this.raycastMode = _cim.RaycastMode;
            }
        }

        GameObject _go = eventData.enterEventCamera.gameObject;

        if (_go != null)
        {
            Log.d(LOG_TAG, "OnPointerClick() " + _go.name, true);
            switch (this.raycastMode)
            {
            case ERaycastMode.Mouse:
                WaveVR_PointerCameraTracker _pct = _go.GetComponent <WaveVR_PointerCameraTracker> ();
                if (_pct != null && _cim != null)
                {
                    Log.d(LOG_TAG, "OnPointerClick() set beam length of " + _pct.type + " to " + this.length, true);
                    _cim.ChangeBeamLength(_pct.type, this.length);
                }
                break;

            case ERaycastMode.Fixed:
                WaveVR_ControllerPointer _cp = _go.GetComponent <WaveVR_ControllerPointer> ();
                if (_cp != null && _cim != null)
                {
                    Log.d(LOG_TAG, "OnPointerClick() set beam length of " + _cp.device + " to " + this.length, true);
                    _cim.ChangeBeamLength(_cp.device, this.length);
                }
                break;

            // Do nothing in beam mode
            case ERaycastMode.Beam:
            default:
                break;
            }
        }
    }
 public void setRaycastMode(ERaycastMode mode)
 {
     RaycastMode = mode;
 }
Esempio n. 3
0
    public override void Process()
    {
        if (!enableControllerInputModule)
        {
            return;
        }

        SetControllerModel();
        SetPointerCameraTracker();

        foreach (WVR_DeviceType _dt in Enum.GetValues(typeof(WVR_DeviceType)))
        {
            // HMD uses Gaze, not controller input module.
            if (_dt == WVR_DeviceType.WVR_DeviceType_HMD)
            {
                continue;
            }

            EventController _eventController = (EventController)EventControllers [_dt];
            if (_eventController == null)
            {
                continue;
            }

            GameObject _controller = _eventController.controller;
            if (_controller == null)
            {
                continue;
            }

            if (WaveVR.Instance != null)
            {
                if (WaveVR.Instance.FocusCapturedBySystem)
                {
                    HandlePointerExitAndEnter(_eventController.event_data, null);
                    continue;
                }
            }

            bool _connected = false;
            #if UNITY_EDITOR
            if (Application.isEditor)
            {
                // "connected" from WaveVR_Controller means the real connection status of controller.
                _connected = WaveVR_Controller.Input(_dt).connected;
            }
            else
            #endif
            {
                // "connected" from WaveVR means the "pose" is valid or not.
                WaveVR.Device _device = WaveVR.Instance.getDeviceByType(_dt);
                _connected = _device.connected;
            }
            if (!_connected)
            {
                continue;
            }

            if (_eventController.pointer == null)
            {
                _eventController.pointer = _eventController.controller.GetComponentInChildren <WaveVR_ControllerPointer> ();
            }

            if (_connected)
            {
                if ((_dt == WVR_DeviceType.WVR_DeviceType_Controller_Left && pointCameraL == null) || (_dt == WVR_DeviceType.WVR_DeviceType_Controller_Right && pointCameraR == null))
                {
                    SetupPointerCamera(_dt);
                }
            }

            Camera _event_camera;

            // Mouse mode: raycasting from HMD after direct raycasting from controller
            if (RaycastMode == ERaycastMode.Mouse)
            {
                _event_camera = _dt == WVR_DeviceType.WVR_DeviceType_Controller_Left ? pointCameraL.GetComponent <Camera>() : pointCameraR.GetComponent <Camera>();
                _eventController.prevRaycastedObject = GetRaycastedObject(_dt);
                if (_eventController.pointer != null)
                {
                    _eventController.pointer.setRaycastMode(RaycastMode);
                }
                if (_eventController.beam != null)
                {
                    if (!isBeamMeshChanged)
                    {
                        _eventController.beam.setRaycastMode(RaycastMode);
                        _eventController.beam.enabled         = false;
                        _eventController.beam.EndColor        = OtherBeamColor;
                        _eventController.beam.endOffset       = userBeamLength;
                        _eventController.beam.useSystemConfig = original_useSystemConfig;
                        _eventController.beam.enabled         = true;
                        isBeamMeshChanged = true;
                    }
                }
                // 1. Get graphic raycast object.
                ResetPointerEventData_Hybrid(_dt, _event_camera);
            }
            else
            {
                _event_camera = (Camera)_controller.GetComponent(typeof(Camera));
                if (_event_camera == null)
                {
                    continue;
                }

                if (_eventController.pointer != null)
                {
                    _eventController.pointer.setRaycastMode(RaycastMode);
                }

                if (_eventController.beam != null)
                {
                    _eventController.beam.setRaycastMode(RaycastMode);
                    if (RaycastMode == ERaycastMode.Fixed)
                    {
                        if (!isBeamMeshChanged)
                        {
                            _eventController.beam.enabled         = false;
                            _eventController.beam.EndColor        = FixedBeamColor;
                            _eventController.beam.endOffset       = FixedBeamLength;
                            _eventController.beam.useSystemConfig = false;
                            _eventController.beam.enabled         = true;
                            isBeamMeshChanged = true;
                        }
                    }
                    else
                    {
                        if (!isBeamMeshChanged)
                        {
                            _eventController.beam.enabled         = false;
                            _eventController.beam.EndColor        = OtherBeamColor;
                            _eventController.beam.endOffset       = userBeamLength;
                            _eventController.beam.useSystemConfig = original_useSystemConfig;
                            _eventController.beam.enabled         = true;
                            isBeamMeshChanged = true;
                        }
                    }
                }

                _eventController.prevRaycastedObject = GetRaycastedObject(_dt);
                // 1. Get graphic raycast object.
                ResetPointerEventData(_dt);
            }
            GraphicRaycast(_eventController, _event_camera);

            if (GetRaycastedObject(_dt) == null)
            {
                // 2. Get physic raycast object.
                PhysicsRaycaster _raycaster = null;
                if (RaycastMode == ERaycastMode.Mouse)
                {
                    _raycaster = _event_camera.GetComponent <PhysicsRaycaster>();
                }
                else
                {
                    _raycaster = _controller.GetComponent <PhysicsRaycaster>();
                }
                if (_raycaster == null)
                {
                    continue;
                }

                if (RaycastMode == ERaycastMode.Mouse)
                {
                    ResetPointerEventData_Hybrid(_dt, _event_camera);
                }
                else
                {
                    ResetPointerEventData(_dt);
                }

                PhysicRaycast(_eventController, _raycaster);
            }

            // 3. Exit previous object, enter new object.
            OnTriggerEnterAndExit(_dt, _eventController.event_data);

            // 4. Hover object.
            GameObject _curRaycastedObject = GetRaycastedObject(_dt);
            if (_curRaycastedObject != null && _curRaycastedObject == _eventController.prevRaycastedObject)
            {
                OnTriggerHover(_dt, _eventController.event_data);
            }

            // 5. Get button state.
            bool btnPressDown = false, btnPressed = false, btnPressUp = false;
            if (_dt == WVR_DeviceType.WVR_DeviceType_Controller_Left || _dt == WVR_DeviceType.WVR_DeviceType_Controller_Right)
            {
                int _mousekey = _dt == WVR_DeviceType.WVR_DeviceType_Controller_Left ? 0 : 1;
                btnPressDown = Input.GetMouseButtonDown(_mousekey);
                btnPressed   = Input.GetMouseButton(_mousekey);
                btnPressUp   = Input.GetMouseButtonUp(_mousekey);
            }
            btnPressDown |= WaveVR_Controller.Input(_dt).GetPressDown((WVR_InputId)ButtonToTrigger);
            btnPressed   |= WaveVR_Controller.Input(_dt).GetPress((WVR_InputId)ButtonToTrigger);
            btnPressUp   |= WaveVR_Controller.Input(_dt).GetPressUp((WVR_InputId)ButtonToTrigger);

            if (btnPressDown)
            {
                _eventController.eligibleForButtonClick = true;
            }
            // Pointer Click equals to Button.onClick, we sent Pointer Click in OnTriggerUp()
            //if (btnPressUp && _eventController.eligibleForButtonClick)
            //onButtonClick (_eventController);

            if (!btnPressDown && btnPressed)
            {
                // button hold means to drag.
                OnDrag(_dt, _eventController.event_data);
            }
            else if (Time.unscaledTime - _eventController.event_data.clickTime < CLICK_TIME)
            {
                // Delay new events until CLICK_TIME has passed.
            }
            else if (btnPressDown && !_eventController.event_data.eligibleForClick)
            {
                // 1. button not pressed -> pressed.
                // 2. no pending Click should be procced.
                OnTriggerDown(_dt, _eventController.event_data);
            }
            else if (!btnPressed)
            {
                // 1. If Down before, send Up event and clear Down state.
                // 2. If Dragging, send Drop & EndDrag event and clear Dragging state.
                // 3. If no Down or Dragging state, do NOTHING.
                OnTriggerUp(_dt, _eventController.event_data);
            }

            if (RaycastMode != ERaycastMode.Mouse)
            {
                UpdateReticlePointer(_eventController);
            }
            if (preRaycastMode != RaycastMode)
            {
                if (isBeamMeshChanged)
                {
                    isBeamMeshChanged = false;
                }
            }
            preRaycastMode = RaycastMode;
        }
    }