コード例 #1
0
        /// <summary>
        /// Gets the type of VR device currently connected. It takes the first VR device which have the higher priority.
        /// </summary>
        /// <returns></returns>
        public VRDeviceType GetVRDevice()
        {
            if (_vrChecked)
            {
                return(activeVRDevice != null ? activeVRDevice.VRDeviceType : VRDeviceType.None);
            }

            if (_headNode == null)
            {
                _headNode = GetComponent <Transform>();
            }

            _originalHeadPosition = _headNode.localPosition;

            // Gets all managers and enable only the first connected device.
            var vrManagers = GetComponents <XRDeviceBase>();
            var count      = vrManagers.Length;
            var deviceType = VRDeviceType.None;

            activeVRDevice = null;

            if (count > 0)
            {
                Array.Sort(vrManagers);

                for (var i = 0; i < count; i++)
                {
                    if (vrManagers[i].IsAvailable && deviceType == VRDeviceType.None)
                    {
                        activeVRDevice = vrManagers[i];
                        activeVRDevice.SetActive(true);
                        deviceType = activeVRDevice.VRDeviceType;

                        var resetHeadPosition = UnityEngine.XR.XRSettings.loadedDeviceName.ToLower() == "openvr";

#if UNITY_WSA
                        resetHeadPosition = true;
#endif

                        if (resetHeadPosition)
                        {
                            _headNode.localPosition = Vector3.zero;
                        }

                        if (deviceType != VRDeviceType.OSVR)
                        {
                            StartCoroutine(RecenterAndFixOffsetCoroutine());
                        }
                    }
                    else
                    {
                        vrManagers[i].Dispose();
                    }
                }
            }

            _vrChecked = true;

            return(deviceType);
        }
コード例 #2
0
 private void OnDestroy()
 {
     activeVRDevice = null;
 }