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);
            switch (this.raycastMode)
            {
            case WaveVR_ControllerInputModule.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);
                    _cim.ChangeBeamLength(_pct.type, this.length);
                }
                break;

            case WaveVR_ControllerInputModule.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);
                    _cim.ChangeBeamLength(_cp.device, this.length);
                }
                break;

            // Do nothing in beam mode
            case WaveVR_ControllerInputModule.ERaycastMode.Beam:
            default:
                break;
            }
        }
    }
예제 #2
0
    void Awake()
    {
        if (TrackPosition == false)
        {
            SimulationOption = WVR_SimulationOption.NoSimulation;
            FollowHead       = false;
        }

        gameObject.SetActive(false);
        PrintDebugLog("Awake() " + this.Type
                      + ", TrackPosition: " + TrackPosition
                      + ", SimulationOption: " + SimulationOption
                      + ", FollowHead: " + FollowHead
                      + ", TrackRotation: " + TrackRotation
                      + ", TrackTiming: " + TrackTiming);

        WaveVR_PointerCameraTracker pcTracker = gameObject.GetComponent <WaveVR_PointerCameraTracker>();

        if (pcTracker == null)
        {
            if (this.Type == WaveVR_Controller.EDeviceType.Head)
            {
                PrintDebugLog("Awake() " + this.Type + ", load WaveVR_DevicePoseTracker.");
                devicePoseTracker = (WaveVR_DevicePoseTracker)gameObject.AddComponent <WaveVR_DevicePoseTracker> ();
                if (null != devicePoseTracker)
                {
                    devicePoseTracker.type            = Type;
                    devicePoseTracker.trackPosition   = TrackPosition;
                    devicePoseTracker.EnableNeckModel = this.EnableNeckModel;
                    devicePoseTracker.trackRotation   = TrackRotation;
                    devicePoseTracker.timing          = TrackTiming;
                }
            }
            else
            {
                PrintDebugLog("Awake() " + this.Type + ", load WaveVR_ControllerPoseTracker.");
                ctrlerPoseTracker = (WaveVR_ControllerPoseTracker)gameObject.AddComponent <WaveVR_ControllerPoseTracker> ();
                if (null != ctrlerPoseTracker)
                {
                    ctrlerPoseTracker.Type             = Type;
                    ctrlerPoseTracker.TrackPosition    = TrackPosition;
                    ctrlerPoseTracker.SimulationOption = SimulationOption;
                    ctrlerPoseTracker.FollowHead       = FollowHead;
                    ctrlerPoseTracker.TrackRotation    = TrackRotation;
                    ctrlerPoseTracker.TrackTiming      = TrackTiming;
                }
            }
        }
        gameObject.SetActive(true);
    }
    void Awake()
    {
        if (TrackPosition == false)
        {
            SimulationOption = WVR_SimulationOption.NoSimulation;
            FollowHead       = false;
        }

        gameObject.SetActive(false);
        PrintDebugLog("Awake() TrackPosition: " + TrackPosition + ", SimulationOption=" + SimulationOption +
                      ", FollowHead: " + FollowHead + ", TrackRotation: " + TrackRotation + ", TrackTiming=" + TrackTiming);

        WaveVR_PointerCameraTracker pcTracker = gameObject.GetComponent <WaveVR_PointerCameraTracker>();

        if (SimulationOption == WVR_SimulationOption.ForceSimulation || SimulationOption == WVR_SimulationOption.WhenNoPosition)
        {
            if (pcTracker == null)
            {
                PrintDebugLog("Awake() load WaveVR_ControllerPoseTracker.");
                WaveVR_ControllerPoseTracker _cpt = (WaveVR_ControllerPoseTracker)gameObject.AddComponent <WaveVR_ControllerPoseTracker> ();
                if (null != _cpt)
                {
                    _cpt.Type             = Type;
                    _cpt.TrackPosition    = TrackPosition;
                    _cpt.SimulationOption = SimulationOption;
                    _cpt.FollowHead       = FollowHead;
                    _cpt.TrackRotation    = TrackRotation;
                    _cpt.TrackTiming      = TrackTiming;
                }
            }
        }
        else
        {
            if (pcTracker == null)
            {
                PrintDebugLog("Awake() load WaveVR_DevicePoseTracker.");
                WaveVR_DevicePoseTracker _dpt = (WaveVR_DevicePoseTracker)gameObject.AddComponent <WaveVR_DevicePoseTracker> ();
                if (null != _dpt)
                {
                    _dpt.type          = Type;
                    _dpt.trackPosition = TrackPosition;
                    _dpt.trackRotation = TrackRotation;
                    _dpt.timing        = TrackTiming;
                }
            }
        }
        gameObject.SetActive(true);
    }
예제 #4
0
    private void 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;
            }

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

            if (_dt == WVR_DeviceType.WVR_DeviceType_Controller_Left && pointCameraL != null)
            {
                WaveVR_PointerCameraTracker pcTracker = pointCameraL.GetComponent <WaveVR_PointerCameraTracker>();
                if (pcTracker != null && pcTracker.reticleObject == null)
                {
                    EventController _eventController = (EventController)EventControllers[_dt];
                    bool            isConnected      = true;
                    #if UNITY_EDITOR
                    if (Application.isEditor)
                    {
                        isConnected = true;
                    }
                    else
                    #endif
                    {
                        WaveVR.Device _device = WaveVR.Instance.getDeviceByType(_dt);
                        isConnected = _device.connected;
                    }
                    if (_eventController != null && isConnected)
                    {
                        if (_eventController.pointer == null && _eventController.controller != null)
                        {
                            _eventController.pointer = _eventController.controller.GetComponentInChildren <WaveVR_ControllerPointer> ();
                        }
                        if (_eventController.pointer != null)
                        {
                            pcTracker.reticleObject = _eventController.pointer.gameObject;
                        }
                    }
                }
            }

            if (_dt == WVR_DeviceType.WVR_DeviceType_Controller_Right && pointCameraR != null)
            {
                WaveVR_PointerCameraTracker pcTracker = pointCameraR.GetComponent <WaveVR_PointerCameraTracker>();
                if (pcTracker != null && pcTracker.reticleObject == null)
                {
                    EventController _eventController = (EventController)EventControllers[_dt];
                    bool            isConnected      = true;

                    #if UNITY_EDITOR
                    if (Application.isEditor)
                    {
                        isConnected = true;
                    }
                    else
                    #endif
                    {
                        WaveVR.Device _device = WaveVR.Instance.getDeviceByType(_dt);
                        isConnected = _device.connected;
                    }
                    if (_eventController != null && isConnected)
                    {
                        if (_eventController.pointer == null && _eventController.controller != null)
                        {
                            _eventController.pointer = _eventController.controller.GetComponentInChildren <WaveVR_ControllerPointer>();
                        }
                        if (_eventController.pointer != null)
                        {
                            pcTracker.reticleObject = _eventController.pointer.gameObject;
                        }
                    }
                }
            }
        }
    }
예제 #5
0
 private void SetupPointerCamera(WVR_DeviceType type)
 {
     if (type == WVR_DeviceType.WVR_DeviceType_Controller_Right)
     {
         GameObject head = GameObject.Find("head");
         pointCameraR = new GameObject("PointerCameraR");
         pointCameraR.AddComponent <WaveVR_PointerCameraTracker>();
         pointCameraR.AddComponent <WaveVR_PoseTrackerManager>();
         pointCameraR.AddComponent <PhysicsRaycaster>();
         pointCameraR.transform.SetParent(head.transform, true);
         if (RaycastStartPoint == ERaycastStartPoint.LeftEye)
         {
             pointCameraR.transform.localPosition = new Vector3(-raycastStartPointOffset, 0f, 0.15f);
         }
         else if (RaycastStartPoint == ERaycastStartPoint.RightEye)
         {
             pointCameraR.transform.localPosition = new Vector3(raycastStartPointOffset, 0f, 0.15f);
         }
         else
         {
             pointCameraR.transform.localPosition = new Vector3(0f, 0f, 0.15f);
         }
         Camera pc = pointCameraR.GetComponent <Camera>();
         if (pc != null)
         {
             pc.enabled       = false;
             pc.fieldOfView   = 1f;
             pc.nearClipPlane = 0.01f;
         }
         WaveVR_PointerCameraTracker pcTracker = pointCameraR.GetComponent <WaveVR_PointerCameraTracker>();
         if (pcTracker != null)
         {
             pcTracker.setDeviceType(type);
         }
         WaveVR_PoseTrackerManager poseTracker = pointCameraR.GetComponent <WaveVR_PoseTrackerManager>();
         if (poseTracker != null)
         {
             poseTracker.Type          = type;
             poseTracker.TrackPosition = false;
             poseTracker.TrackRotation = false;
             poseTracker.enabled       = false;
         }
     }
     else if (type == WVR_DeviceType.WVR_DeviceType_Controller_Left)
     {
         GameObject head = GameObject.Find("head");
         pointCameraL = new GameObject("PointerCameraL");
         pointCameraL.AddComponent <WaveVR_PointerCameraTracker>();
         pointCameraL.AddComponent <WaveVR_PoseTrackerManager>();
         pointCameraL.AddComponent <PhysicsRaycaster>();
         pointCameraL.transform.SetParent(head.transform, true);
         if (RaycastStartPoint == ERaycastStartPoint.LeftEye)
         {
             pointCameraL.transform.localPosition = new Vector3(-raycastStartPointOffset, 0f, 0.15f);
         }
         else if (RaycastStartPoint == ERaycastStartPoint.RightEye)
         {
             pointCameraL.transform.localPosition = new Vector3(raycastStartPointOffset, 0f, 0.15f);
         }
         else
         {
             pointCameraL.transform.localPosition = new Vector3(0f, 0f, 0.15f);
         }
         Camera pc = pointCameraL.GetComponent <Camera>();
         if (pc != null)
         {
             pc.enabled       = false;
             pc.fieldOfView   = 1f;
             pc.nearClipPlane = 0.01f;
         }
         WaveVR_PointerCameraTracker pcTracker = pointCameraL.GetComponent <WaveVR_PointerCameraTracker>();
         if (pcTracker != null)
         {
             pcTracker.setDeviceType(type);
         }
         WaveVR_PoseTrackerManager poseTracker = pointCameraL.GetComponent <WaveVR_PoseTrackerManager>();
         if (poseTracker != null)
         {
             poseTracker.Type          = type;
             poseTracker.TrackPosition = false;
             poseTracker.TrackRotation = false;
             poseTracker.enabled       = false;
         }
     }
 }