Exemple #1
0
    // Start is called before the first frame update
    void Start()
    {
        List <InputDevice> devices = new List <InputDevice>();

        InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices);

        foreach (var item in devices)
        {
            Debug.Log(item.name + item.characteristics);
        }

        if (devices.Count > 0)
        {
            targetDevice = devices[0];
            Debug.Log("TARGET DEVICE: " + targetDevice.name + targetDevice.characteristics);

            GameObject prefab = controllerPrefabs.Find(controller => controller.name == targetDevice.name);
            if (prefab)
            {
                //spawnedController = Instantiate(prefab, transform);
            }
            else
            {
                Debug.Log("Could Not Find corresponding controller model");
                //spawnedController = Instantiate(controllerPrefabs[0], transform);
            }

            spawnedHandModel = Instantiate(handModelPrefab, transform);
        }
    }
        /// <summary>
        /// Updates the key pose state based on the provided snapshot.
        /// </summary>
        protected override void Update()
        {
            this.leftHandDevices.Clear();

            #if UNITY_2019_3_OR_NEWER
            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HandTracking | InputDeviceCharacteristics.Left, this.leftHandDevices);
            #else
            InputDevices.GetDevicesAtXRNode(XRNode.LeftHand, this.leftHandDevices);
            #endif

            if (this.leftHandDevices.Count > 0 && this.leftHandDevices[0].isValid)
            {
                this.left.Update(this.leftHandDevices[0]);
            }

            this.rightHandDevices.Clear();

            #if UNITY_2019_3_OR_NEWER
            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HandTracking | InputDeviceCharacteristics.Right, this.rightHandDevices);
            #else
            InputDevices.GetDevicesAtXRNode(XRNode.RightHand, this.rightHandDevices);
            #endif

            if (this.rightHandDevices.Count > 0 && this.rightHandDevices[0].isValid)
            {
                this.right.Update(this.rightHandDevices[0]);
            }
        }
        private static void UpdateHandJoints(InputDeviceCharacteristics flag, Hand hand)
        {
            List <InputDevice> inputDeviceList = new List <InputDevice>();

            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HandTracking | flag, inputDeviceList);
            UnityEngine.XR.Hand xrHand = default;
            foreach (InputDevice device in inputDeviceList)
            {
                if (device.TryGetFeatureValue(CommonUsages.isTracked, out bool isTracked) &&
                    isTracked &&
                    device.TryGetFeatureValue(CommonUsages.handData, out xrHand))
                {
                    break;
                }
            }

            if (xrHand != default)
            {
                hand?.UpdateHandJoints(xrHand);
            }
            else
            {
                // If we get here, we didn't successfully update hand joints for any tracked input device
                hand?.DisableHandJoints();
            }
        }
Exemple #4
0
    // Start is called before the first frame update
    void Start()
    {
        List <InputDevice> devices = new List <InputDevice>();

        //  InputDeviceCharacteristics rightControllerCharacteristics = InputDeviceCharacteristics.Right | InputDeviceCharacteristics.Controller;
        //InputDeviceCharacteristics rightControllerCharacteristics = InputDeviceCharacteristics.Right | InputDeviceCharacteristics.Controller;
        // InputDevices.GetDevices(devices);
        //InputDevices.GetDevicesWithCharacteristics(rightControllerCharacteristics, devices);
        InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices);
        foreach (var item in devices)
        {
            Debug.Log("Hello, world.");
            Debug.Log("Here" + item.name + item.characteristics + item.manufacturer);
        }
        Debug.Log(devices.Count);
        if (devices.Count > 0)
        {
            targetDevice = devices[0];
            GameObject prefab = controllerPrefabs.Find(controller => controller.name == targetDevice.name);
            if (prefab)
            {
                spawnedController = Instantiate(prefab, transform);
            }
            else
            {
                Debug.LogError("Count is " + controllerPrefabs.Count);
                Debug.LogError("Did not find corresponding controller model");
                spawnedController = Instantiate(controllerPrefabs[0], transform);
            }

            spawnedHandModel = Instantiate(handModelPrefab, transform);
            handAnimator     = spawnedHandModel.GetComponent <Animator>();
        }
    }
Exemple #5
0
    void Update()
    {
        InputDevices.GetDevicesWithCharacteristics(deviceCharacteristic, inputDevices);

        for (int i = 0; i < inputDevices.Count; i++)
        {
            if (inputDevices[i].TryGetFeatureValue(inputFeature,
                                                   out inputValue) && inputValue)
            {
                // if start pressing, trigger event
                if (!IsPressed)
                {
                    IsPressed = true;
                    OnPress.Invoke();
                    DilmerGamesLogger.Instance.LogInfo($"Pressed {deviceCharacteristic} Controller {button}");
                }
            }

            // check for button release
            else if (IsPressed)
            {
                IsPressed = false;
                OnRelease.Invoke();
                DilmerGamesLogger.Instance.LogInfo($"Released {deviceCharacteristic} Controller {button}");
            }
            //was logging this to see exactly what was called -- want to try to allow for one instance of the script to allow for both controllers
            //DilmerGamesLogger.Instance.LogInfo($"Device Characteristic is {deviceCharacteristic} and Input Devices are {inputDevices}");
        }
    }
        public static void Recenter()
        {
      #if UNITY_2019_3_OR_NEWER
            var devices = new List <InputDevice>();
            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices);
            if (devices.Count == 0)
            {
                return;
            }
            var hmdDevice = devices[0];
        #if !UNITY_2020_1_OR_NEWER
            if (hmdDevice.subsystem != null)
            {
        #endif
            hmdDevice.subsystem.TryRecenter();
        #if !UNITY_2020_1_OR_NEWER
        }

        else
        {
          #pragma warning disable 0618
            InputTracking.Recenter();
          #pragma warning restore 0618
        }
        #endif
      #else
            InputTracking.Recenter();
      #endif
        }
Exemple #7
0
    // Main Function: Change the visual representation of the left/right controllers
    void Start()
    {
        List <InputDevice> devices = new List <InputDevice>();

        if (controller.Equals(Orientation.Left))
        {
            ControllerCharacteristics = InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.Left;
            InputDevices.GetDevicesWithCharacteristics(ControllerCharacteristics, devices);
            leftController = devices[0];
            GameObject prefab = controllerPrefabs.Find(controller => controller.name.Equals("Oculus Quest Controller - Left"));
            if (prefab)
            {
                targetController_spawn = Instantiate(prefab, transform);
            }
        }
        else if (controller.Equals(Orientation.Right))
        {
            ControllerCharacteristics = InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.Right;
            InputDevices.GetDevicesWithCharacteristics(ControllerCharacteristics, devices);
            rightController = devices[0];
            GameObject prefab = controllerPrefabs.Find(controller => controller.name.Equals("Oculus Quest Controller - Right"));
            if (prefab)
            {
                targetController_spawn = Instantiate(prefab, transform);
            }
        }
    }
Exemple #8
0
    void UpdateHandAnimation() //손 모델의 애니메이션 조정
    {
        List <InputDevice> devices = new List <InputDevice>();

        InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices);

        if (devices.Count > 0) //디바이스가 있는 경우
        {
            targetDevice = devices[0];

            if (targetDevice.TryGetFeatureValue(CommonUsages.trigger, out float triggerValue))
            {
                handAnimator.SetFloat("Trigger", triggerValue);
            }
            else
            {
                handAnimator.SetFloat("Trigger", 0);
            }

            if (targetDevice.TryGetFeatureValue(CommonUsages.grip, out float gripValue))
            {
                handAnimator.SetFloat("Grip", gripValue);
            }
            else
            {
                handAnimator.SetFloat("Grip", 0);
            }
        }
    }
    private void getCurrentDevice()
    {
        if (XRSettings.loadedDeviceName.Length != 0)
        {
            Debug.Log(XRSettings.loadedDeviceName);
            var devices = new List <InputDevice>();
            var rightControllerCharacteristics = InputDeviceCharacteristics.Right | InputDeviceCharacteristics.Controller;
            InputDevices.GetDevicesWithCharacteristics(rightControllerCharacteristics, devices);
            foreach (var item in devices)
            {
                Debug.Log(item.name + item.characteristics);
            }

            if (devices.Count > 0 && devices[0].name.Length > 0)
            {
                targetDevice = devices[0];
                Debug.Log("Succesfully found Device: " + targetDevice.name);
                GameObject prefab = controllerPrefabs.Find(controller => controller.name == targetDevice.name);
                if (prefab)
                {
                    spawnedController = Instantiate(prefab, transform);
                }
                else
                {
                    Debug.Log("Did not find controller {targetDevice.name}");
                    spawnedController = Instantiate(controllerPrefabs[0], transform);
                }
            }
        }
    }
Exemple #10
0
        /// <summary>
        /// Updates the key pose state based on the provided snapshot.
        /// </summary>
        protected override void Update()
        {
            List <InputDevice> leftHandDevices = new List <InputDevice>();

            #if UNITY_2019_3_OR_NEWER
            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HandTracking | InputDeviceCharacteristics.Left, leftHandDevices);
            #else
            InputDevices.GetDevicesAtXRNode(XRNode.LeftHand, leftHandDevices);
            #endif

            if (leftHandDevices.Count > 0 && leftHandDevices[0].isValid)
            {
                this.left.Update(leftHandDevices[0]);
            }

            List <InputDevice> rightHandDevices = new List <InputDevice>();

            #if UNITY_2019_3_OR_NEWER
            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HandTracking | InputDeviceCharacteristics.Right, rightHandDevices);
            #else
            InputDevices.GetDevicesAtXRNode(XRNode.RightHand, rightHandDevices);
            #endif

            if (rightHandDevices.Count > 0 && rightHandDevices[0].isValid)
            {
                this.right.Update(rightHandDevices[0]);
            }
        }
Exemple #11
0
    void TryInitialize()
    {
        List <InputDevice> devices = new List <InputDevice>();

        InputDevices.GetDevicesWithCharacteristics(controllerCharacterstics, devices);

        foreach (InputDevice device in devices)
        {
            Debug.Log(device.name);
        }

        if (devices.Count > 0)
        {
            targetDevice = devices[0];
            GameObject prefab = controllerPrefabs.Find(controller => controller.name == targetDevice.name);

            if (prefab)
            {
                spawnedController = Instantiate(prefab, transform);
            }

            else
            {
                Debug.Log("didn't find it");
            }

            spawnedHandModel = Instantiate(handModelPrefab, transform);
            handAnimator     = spawnedHandModel.GetComponent <Animator>();
        }
    }
Exemple #12
0
    private void TryInitialize()
    {
        List <InputDevice> devices = new List <InputDevice>();

        InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices);

        if (devices.Count > 0)
        {
            targetDevice = devices[0];
            GameObject prefab = controllerPrefabs.Find(controller => controller.name == targetDevice.name);
            if (prefab)
            {
                spawnedController = Instantiate(prefab, transform);
            }
            else
            {
                Debug.LogError("Did not find corresponding controller model, using default instead");
                spawnedController = Instantiate(controllerPrefabs[0], transform);
            }

            spawnedHandModel = Instantiate(handModelPrefab, transform);
            handAnimator     = spawnedHandModel.GetComponent <Animator>();

            spawnedHandModel.SetActive(!showController);
            spawnedController.SetActive(showController);
        }
    }
    void TryInitialize()
    {
        List <InputDevice> devices = new List <InputDevice>();

        InputDevices.GetDevicesWithCharacteristics(ControllerCharacteristics, devices);

        if (devices.Count == 0)
        {
            return;
        }
        targetDevice = devices[0];

        GameObject prefab = ControllerPrefabs.Find(controller => controller.name == targetDevice.name);

        if (prefab)
        {
            spawnedController = Instantiate(prefab, transform);
        }
        else
        {
            spawnedController = Instantiate(ControllerPrefabs[0], transform);
        }

        spawnedHand = Instantiate(HandModelPrefab, transform);

        spawnedController.SetActive(ShowController);
        spawnedHand.SetActive(!ShowController);
        handAnimator = spawnedHand.GetComponent <Animator>();
    }
Exemple #14
0
    //This function try to initialize the controllers and then display them
    void TryInitialize()
    {
        List <InputDevice> devices = new List <InputDevice>();

        ;
        InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices);

        if (devices.Count > 0)
        {
            targetDevice = devices[0];

            GameObject prefab = controllePrefab.Find(controller => controller.name == targetDevice.name);
            if (prefab)
            {
                spawnedController = Instantiate(prefab, transform);
            }
            else
            {
                Debug.Log("did not fid the correnspondig controller");
                spawnedController = Instantiate(controllePrefab[0], transform);
            }

            spawnedHandModel = Instantiate(handModelPrefab, transform);
            handAnimator     = spawnedHandModel.GetComponent <Animator>();
        }
    }
Exemple #15
0
    InputDevice GetHand(InputDeviceCharacteristics side)
    {
        List <InputDevice>         devices         = new List <InputDevice>();
        InputDeviceCharacteristics characteristics = InputDeviceCharacteristics.Controller | side;

        InputDevices.GetDevicesWithCharacteristics(characteristics, devices);
        return(devices.Count > 0 ? devices[0] : default);
Exemple #16
0
 private void Update()
 {
     if (leftControllerDevice == null)
     {
         List <InputDevice> hands = new List <InputDevice>();
         InputDevices.GetDevicesWithCharacteristics(leftControllerCharacteristics, hands);
         if (hands.Count > 0)
         {
             leftControllerDevice        = hands[0];
             leftControllerInput         = leftHand.gameObject.AddComponent <Controller>();
             controllers[handTypes.left] = leftControllerInput;
             leftControllerInput.device  = leftControllerDevice;
         }
     }
     if (rightControllerDevice == null)
     {
         List <InputDevice> hands = new List <InputDevice>();
         InputDevices.GetDevicesWithCharacteristics(rightControllerCharacteristics, hands);
         if (hands.Count > 0)
         {
             rightControllerDevice        = hands[0];
             rightControllerInput         = rightHand.gameObject.AddComponent <Controller>();
             controllers[handTypes.right] = rightControllerInput;
             rightControllerInput.device  = rightControllerDevice;
         }
     }
 }
    /// <summary>
    /// Function to try and load the initial hand or controller prefabs
    /// based on the controller type you are using or hand tracking
    /// </summary>
    void TryInitialize()
    {
        List <InputDevice> devices = new List <InputDevice>();                          // populate the list of available device types

        InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices); // find the input device being used and assign to references

        foreach (var item in devices)
        {
            Debug.Log(item.name + item.characteristics);             // for each iten log in console the item name and charactistics
        }

        if (devices.Count > 0)                                                                              // if the list count is greater than zero
        {
            targetDevice = devices[0];                                                                      // take the first device from the list
            GameObject prefab = controllerPrefabs.Find(controller => controller.name == targetDevice.name); // match and assign the same prefab to the controller being used
            if (prefab)
            {
                spawnedController = Instantiate(prefab, transform);               // spawn the prefab of the controller
            }
            else                                                                  // otherwise
            {
                Debug.LogError("Error");                                          // debug error log saying Error
                spawnedController = Instantiate(controllerPrefabs[0], transform); // assign the default controller prefab and spawn it
            }

            spawnedHandModel = Instantiate(handModelPrefab, transform);
            handAnimator     = spawnedHandModel.GetComponent <Animator>();        // get the Animator component from the hand prefab we spawned
        }
    }
Exemple #18
0
        void Update()
        {
            switch (controller)
            {
            case Controller.LEFT:
                var desiredCharacteristics = InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.Left | InputDeviceCharacteristics.Controller;
                InputDevices.GetDevicesWithCharacteristics(desiredCharacteristics, devices);

                break;

            case Controller.RIGHT:
                var desiredCharacteristics2 = InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.Right | InputDeviceCharacteristics.Controller;
                InputDevices.GetDevicesWithCharacteristics(desiredCharacteristics2, devices);
                break;
            }

            if (devices.Count > 0)
            {
                InputDevice device = devices[0];
                Vector3     position;
                if (device.TryGetFeatureValue(CommonUsages.devicePosition, out position))
                {
                    this.transform.localPosition = position;
                }
                Quaternion rotation;
                if (device.TryGetFeatureValue(CommonUsages.deviceRotation, out rotation))
                {
                    this.transform.localRotation = rotation;
                }
            }

            speed = Mathf.Lerp(speed, Vector3.Distance(prev, this.transform.position), .6f);
            prev  = this.transform.position;
        }
        /// <summary> Returns whether there's a floor available. </summary>
        public static bool IsRoomScale()
        {
      #if UNITY_2019_3_OR_NEWER
            var devices = new List <InputDevice>();
            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices);
            if (devices.Count == 0)
            {
                return(false);
            }
            var hmdDevice = devices[0];
        #if !UNITY_2020_1_OR_NEWER
            if (hmdDevice.subsystem != null)
            {
        #endif
            return(hmdDevice.subsystem.GetTrackingOriginMode().HasFlag(TrackingOriginModeFlags.Floor));

        #if !UNITY_2020_1_OR_NEWER
        }

        else
        {
          #pragma warning disable 0618
            return(XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale);

          #pragma warning restore 0618
        }
        #endif
      #elif UNITY_2017_2_OR_NEWER
            return(XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale);
      #else
            return(VRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale);
      #endif
        }
    // Start is called before the first frame update
    void Start()
    {
        // InputDevices.GetDevices(devices);
        List <InputDevice>         devices = new List <InputDevice>();
        InputDeviceCharacteristics rcc     = InputDeviceCharacteristics.Right | InputDeviceCharacteristics.Controller;

        InputDevices.GetDevicesWithCharacteristics(rcc, devices);

        foreach (var item in devices)
        {
            Debug.Log(item.name + item.characteristics);
        }


        if (devices.Count > 0)
        {
            targetDevice = devices[0];
            GameObject prefab = controllerPrefabs.Find(controller => controller.name == targetDevice.name);
            if (prefab)
            {
                spawnedController = Instantiate(prefab, transform);
            }
            else
            {
                Debug.Log("Did not find corresponding contorller model");
                spawnedController = Instantiate(controllerPrefabs[0], transform);
            }
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        List <InputDevice> devices = new List <InputDevice>();

        InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices);
        deviceR = InputDevices.GetDeviceAtXRNode(rightController);
    }
Exemple #22
0
    private void Start()
    {
        // Initialise variables upon start
        magSize          = gunClipSize * 4;
        magSizeCapacity  = magSize;
        bulletsRemaining = gunClipSize;

        // Initialise references and prefabs
        player       = GameObject.FindGameObjectWithTag("Player").transform;
        playerCamera = player.GetChild(2).transform;

        // Get Controllers

        List <InputDevice> devices = new List <InputDevice>();

        InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices);

        foreach (var item in devices)
        {
            Debug.Log(item.name + item.characteristics);
        }

        if (devices.Count > 0)
        {
            targetDevice = devices[0];
        }
    }
 private void Start()
 {
     controllers = new List <InputDevice>();
     InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.Controller, controllers);
     mainPauseMenu  = gameObject;
     objectivesMenu = gameObject;
 }
Exemple #24
0
        void OnEnable()
        {
            WebXRManager.OnControllerUpdate += OnControllerUpdate;
            WebXRManager.OnHandUpdate       += OnHandUpdateInternal;
            WebXRManager.OnHeadsetUpdate    += OnHeadsetUpdate;
            SetControllerActive(false);
            SetHandActive(false);
#if UNITY_EDITOR || !UNITY_WEBGL
            switch (hand)
            {
            case WebXRControllerHand.LEFT:
                xrHand = InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.Left;
                break;

            case WebXRControllerHand.RIGHT:
                xrHand = InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.Right;
                break;
            }

            List <InputDevice> allDevices = new List <InputDevice>();
            InputDevices.GetDevicesWithCharacteristics(xrHand, allDevices);
            foreach (InputDevice device in allDevices)
            {
                HandleInputDevicesConnected(device);
            }

            InputDevices.deviceConnected    += HandleInputDevicesConnected;
            InputDevices.deviceDisconnected += HandleInputDevicesDisconnected;
#endif
        }
Exemple #25
0
        // Start Vibration on controller
        public void VibrateController(float frequency, float amplitude, float duration, ControllerHand hand)
        {
            if (InputSource == XRInputSource.XRInput)
            {
                if (hand == ControllerHand.Right)
                {
                    InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.Right, devices);
                }
                else
                {
                    InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.Left, devices);
                }

                for (int x = 0; x < devices.Count; x++)
                {
                    HapticCapabilities capabilities;
                    if (devices[x].TryGetHapticCapabilities(out capabilities))
                    {
                        if (capabilities.supportsImpulse)
                        {
                            uint channel = 0;
                            devices[x].SendHapticImpulse(channel, amplitude, duration);
                        }
                    }
                }
            }
            else if (InputSource == XRInputSource.OVRInput)
            {
                StartCoroutine(Vibrate(frequency, amplitude, duration, hand));
            }
        }
Exemple #26
0
    // Start is called before the first frame update
    void Start()
    {
        UI_Design = UI_Des.GetComponent <UI_Design>();
        Devices   = new List <InputDevice>();
        InputDevices.GetDevicesWithCharacteristics(DeviceCharacter, Devices);
        if (Devices.Count > 0)
        {
            Debug.Log("Device Found");
            TargetDevice = Devices[0];
            Debug.Log(TargetDevice.name);
            if (!isRight)
            {
                CurrentController = ControllerPrefabs[1];
            }
            else if (isRight)
            {
                CurrentController = ControllerPrefabs[2];
            }
        }

        if (CurrentController)
        {
            SpawnedController = Instantiate(CurrentController, transform);
        }
    }
Exemple #27
0
    void TryInitialize()
    {
        List <InputDevice> devices = new List <InputDevice>();

        InputDevices.GetDevicesWithCharacteristics(controllerCharacteristics, devices);


        foreach (var item in devices)
        {
            Debug.Log(item.name + " : " + item.characteristics);
        }

        if (devices.Count > 0)
        {
            targetDevice = devices[0];
            GameObject prefab = controllerPrefabs.Find(controller => controller.name == targetDevice.name);
            if (prefab)
            {
                spawnedController = Instantiate(prefab, transform);
            }
            else
            {
                Debug.LogError("Did not find corresponding controller model");
                spawnedController = Instantiate(controllerPrefabs[0], transform);
            }

            spawnedHandModel = Instantiate(handModelPrefab, transform);
            handAnimator     = spawnedHandModel.GetComponent <Animator>();
        }
    }
Exemple #28
0
        void OnEnable()
        {
            if (inputMap == null)
            {
                Debug.LogError("A Input Map must be assigned to WebXRController!");
                return;
            }
            WebXRManager.OnControllerUpdate += OnControllerUpdate;
            WebXRManager.OnHandUpdate       += OnHandUpdate;
            WebXRManager.OnHeadsetUpdate    += onHeadsetUpdate;
            SetVisible(false);
#if UNITY_EDITOR
            switch (hand)
            {
            case WebXRControllerHand.LEFT:
                xrHand = InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.Left;
                break;

            case WebXRControllerHand.RIGHT:
                xrHand = InputDeviceCharacteristics.Controller | InputDeviceCharacteristics.Right;
                break;
            }

            List <InputDevice> allDevices = new List <InputDevice>();
            InputDevices.GetDevicesWithCharacteristics(xrHand, allDevices);
            foreach (InputDevice device in allDevices)
            {
                HandleInputDevicesConnected(device);
            }

            InputDevices.deviceConnected    += HandleInputDevicesConnected;
            InputDevices.deviceDisconnected += HandleInputDevicesDisconnected;
#endif
        }
Exemple #29
0
        /// <summary> Returns whether the playspace is larger than 1m on its shortest side. </summary>
        public static bool IsLargePlayspace()
        {
#if SVR
            if (SvrManager.Instance != null)
            {
                // The current SVR support for reading the playspace dimensions is crude. Likely to be improved on by 3rd parties
                // By default, we should consider the current playspace as 'large'
                return(true);
            }
#endif

#if UNITY_2020_1_OR_NEWER // Oculus reports a floor centered space now...
            var devices = new List <InputDevice>();
            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices);

            if (devices.Count == 0)
            {
                return(false);
            }

            var hmdDevice = devices[0];
            hmdDevice.subsystem.TryGetBoundaryPoints(_boundaryPoints);
            Bounds playspaceSize = new Bounds();
            foreach (Vector3 boundaryPoint in _boundaryPoints)
            {
                playspaceSize.Encapsulate(boundaryPoint);
            }

            return(playspaceSize.size.magnitude > 1f); // Playspace is greater than 1m on its shortest axis
#else
            return(IsRoomScale());
#endif
        }
        //Update Camera position according to Unity XR, if not using WebGL
        private void Update()
        {
            List <InputDevice> devices = new List <InputDevice>();

            InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices);
            bool XRisPresent = devices.Count > 0;

            if (XRisPresent)
            {
                List <XRNodeState> mNodeStates = new List <XRNodeState>();
                InputTracking.GetNodeStates(mNodeStates);

                Vector3    mHeadPos = Vector3.zero;
                Quaternion mHeadRot = Quaternion.identity;
                foreach (XRNodeState nodeState in mNodeStates)
                {
                    switch (nodeState.nodeType)
                    {
                    case XRNode.Head:
                        nodeState.TryGetPosition(out mHeadPos);
                        nodeState.TryGetRotation(out mHeadRot);
                        break;
                    }
                }
                cameraMain.transform.localPosition = mHeadPos;
                cameraMain.transform.localRotation = mHeadRot.normalized;
            }
        }