//https://stackoverflow.com/questions/36702228/enable-disable-vr-from-code public IEnumerator EnableVR() { Instantiate(XRInputPrefab); if (XRGeneralSettings.Instance.Manager.activeLoader == null) { StartCoroutine(XRGeneralSettings.Instance.Manager.InitializeLoader()); } if (XRGeneralSettings.Instance.Manager.activeLoader != null) { XRGeneralSettings.Instance.Manager.StartSubsystems(); VRDevices.loadedSdk = VRDevices.LoadedSdk.OpenVr; VRDevices.BeginHandlingVRDeviceEvents(); controllerLeft.SetActive(true); controllerRight.SetActive(true); } else { VRDevices.loadedSdk = VRDevices.LoadedSdk.None; controllerLeft.SetActive(false); controllerRight.SetActive(false); } trackedControllerLeft = controllerLeft.GetComponent <Controller>(); trackedControllerRight = controllerRight.GetComponent <Controller>(); yield return(null); }
private IEnumerator EnableVr() { var supportedDevices = XRSettings.supportedDevices; //NOTE(Simon): We start with None as the default in the player settings. But in player we want to load OpenVR first (and in the future other APIs?) so reverse the array Array.Reverse(supportedDevices); XRSettings.LoadDeviceByName(supportedDevices); //NOTE(Kristof): wait one frame to allow the device to be loaded yield return(null); if (XRSettings.loadedDeviceName.Equals("OpenVR")) { VRDevices.loadedSdk = VRDevices.LoadedSdk.OpenVr; XRSettings.enabled = true; SteamVR.Initialize(true); //NOTE(Kristof): Instantiate the projector { projector = Instantiate(projectorPrefab); projector.transform.position = new Vector3(4.5f, 0, 0); projector.transform.eulerAngles = new Vector3(0, 270, 0); projector.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); projector.GetComponent <AnimateProjector>().Subscribe(this); } //NOTE(Kristof): Hide the main and seekbar canvas when in VR (they are toggled back on again after the lobby) SetCanvasesActive(false); Canvass.seekbar.transform.position = new Vector3(1.8f, Camera.main.transform.position.y - 2f, 0); fileLoader.MoveSeekbarToVRPos(); VRDevices.BeginHandlingVRDeviceEvents(); } else if (XRSettings.loadedDeviceName.Equals("")) { VRDevices.loadedSdk = VRDevices.LoadedSdk.None; controllerLeft.SetActive(false); controllerRight.SetActive(false); } }