//Desligar VR IEnumerator SwitchOutOfVr() { VRSettings.LoadDeviceByName(""); // Empty string loads the "None" device. // Wait one frame! yield return(null); // Resetar cameras Camera.main.ResetAspect(); Camera.main.fieldOfView = 80.0f; }
IEnumerator LoadDevice(string newDevice, bool enable) { VRSettings.LoadDeviceByName(newDevice); yield return(null); VRSettings.enabled = enable; Debug.Log("Vr disable"); // String a = clipBoard[get]; String aa = GUIUtility.systemCopyBuffer; Debug.Log("Vr disable: Str " + aa); }
// XMLSerializerは配列にデフォルト値をつけると、指定値とデフォルト値の両方を含む配列にしてしまうので public static HS2VRSettings Load(string path) { HS2VRSettings settings = VRSettings.Load <HS2VRSettings>(path); if (settings.KeySets.Count == 0) { settings.KeySets = new List <KeySet> { new KeySet() }; } return(settings); }
public AGHContext() { _Materials = new DefaultMaterialPalette(); _Materials.StandardShader = _Materials.Unlit.shader; bool isNew = !System.IO.File.Exists("vr_settings.xml"); _Settings = VRSettings.Load <AGHSettings>("vr_settings.xml"); if (isNew) { _Settings.IPDScale = 5f; _Settings.Save(); } }
IEnumerator SwitchToVR() { print("Switching to VR"); // Device names are lowercase, as returned by `XRSettings.supportedDevices`. string desiredDevice = "cardboard"; // Or "daydream". VRSettings.LoadDeviceByName(desiredDevice); // Must wait one frame after calling `XRSettings.LoadDeviceByName()`. yield return(null); // Now it's ok to enable VR mode. VRSettings.enabled = true; }
public void OnEnable() { EditorApplication.playmodeStateChanged += OnPlaymodeStateChanged; Assert.IsNull(s_ActiveView, "Only one EditorVR should be active"); autoRepaintOnSceneChange = true; s_ActiveView = this; GameObject cameraGO = EditorUtility.CreateGameObjectWithHideFlags("EditorVRCamera", EditorVR.kDefaultHideFlags, typeof(Camera)); m_Camera = cameraGO.GetComponent <Camera>(); m_Camera.enabled = false; m_Camera.cameraType = CameraType.VR; GameObject pivotGO = EditorUtility.CreateGameObjectWithHideFlags("EditorVRCameraPivot", EditorVR.kDefaultHideFlags, typeof(EditorMonoBehaviour)); m_CameraPivot = pivotGO.transform; m_Camera.transform.parent = m_CameraPivot; m_Camera.nearClipPlane = 0.01f; m_Camera.farClipPlane = 1000f; // Generally, we want to be at a standing height, so default to that const float kHeadHeight = 1.7f; Vector3 position = m_CameraPivot.position; position.y = kHeadHeight; m_CameraPivot.position = position; m_CameraPivot.rotation = Quaternion.identity; m_ShowDeviceView = EditorPrefs.GetBool(kShowDeviceView, false); m_UseCustomPreviewCamera = EditorPrefs.GetBool(kUseCustomPreviewCamera, false); // Disable other views to increase rendering performance for EditorVR SetOtherViewsEnabled(false); VRSettings.StartRenderingToDevice(); InputTracking.Recenter(); // HACK: Fix VRSettings.enabled or some other API to check for missing HMD m_VRInitialized = false; #if ENABLE_OVR_INPUT m_VRInitialized |= OVRPlugin.initialized; #endif #if ENABLE_STEAMVR_INPUT m_VRInitialized |= (OpenVR.IsHmdPresent() && OpenVR.Compositor != null); #endif onEnable(); }
void toggle() { if (vrMode == VRMode.VROn) { Debug.Log("Starting Non-VR"); VRSettings.LoadDeviceByName("None"); vrMode = VRMode.VROff; } else { Debug.Log("Starting VR"); VRSettings.LoadDeviceByName("daydream"); vrMode = VRMode.VROn; } }
// Call via `StartCoroutine(SwitchTo2D())` from your code. Or, use // `yield SwitchTo2D()` if calling from inside another coroutine. IEnumerator SwitchTo2D() { print("Switching to 2D"); // Empty string loads the "None" device. VRSettings.LoadDeviceByName(""); // Must wait one frame after calling `XRSettings.LoadDeviceByName()`. yield return(null); // Not needed, since loading the None (`""`) device takes care of this. // XRSettings.enabled = false; // Restore 2D camera settings. //ResetCameras(); }
private void SetupVR() { //Gear VR does not currently support renderScale #if !UNITY_ANDROID VRSettings.renderScale = m_RenderScale; #endif #if UNITY_STANDALONE VRSettings.LoadDeviceByName("Oculus"); #endif #if UNITY_PS4 && !UNITY_EDITOR VRSettings.loadedDevice = VRDeviceType.Morpheus; #endif VRSettings.enabled = true; }
public void OnDisable() { onDisable(); EditorApplication.playmodeStateChanged -= OnPlaymodeStateChanged; VRSettings.StopRenderingToDevice(); SetOtherViewsEnabled(true); if (m_CameraPivot) { DestroyImmediate(m_CameraPivot.gameObject, true); } Assert.IsNotNull(s_ActiveView, "EditorVR should have an active view"); s_ActiveView = null; }
IEnumerator SwitchToNone() { SteamVR_Render steamVR_RenderInstance = SteamVR_Render.instance; if (VRSettings.loadedDeviceName != "") { Debug.Log("******* LoadDeviceByName(\"None\")..."); VRSettings.LoadDeviceByName("None"); yield return(new WaitForEndOfFrame()); // required to load device Debug.Log("SwitchToNone(): " + state); } if (VRSettings.enabled) { Debug.Log("******* VRSettings.enabled = false"); VRSettings.enabled = false; yield return(new WaitForEndOfFrame()); // required for None device to become active Debug.Log("SwitchToNone(): " + state); } if (steamVR_RenderInstance != null) { Debug.Log("******* Destroy (steamVR_RenderInstance.gameObject)"); Destroy(steamVR_RenderInstance.gameObject); } if (SteamVR.active) { Debug.LogError("SteamVR.active"); Debug.Log("******* SteamVR.SafeDispose()"); SteamVR.SafeDispose(); } Debug.Log("******* Camera.main.ResetFieldOfView()"); Camera.main.ResetFieldOfView(); // Debug.Log ("******* SteamVR.enabled = false"); // SteamVR.enabled = false; Debug.Log("SwitchToNone(): " + state); }
IEnumerator SetupVR() { #if UNITY_PS4 Debug.Log("SetupVR"); // Register the callbacks needed to detect resetting the HMD Utility.onSystemServiceEvent += OnSystemServiceEvent; PlayStationVR.onDeviceEvent += onDeviceEvent; // Post-reproject for camera locked items, in this case the reticle. Must be // set before we change the VR Device. See VRPostReprojection.cs for more info if (Camera.main.actualRenderingPath == RenderingPath.Forward) { if (FindObjectOfType <VRPostReprojection>()) { PlayStationVRSettings.postReprojectionType = PlayStationVRPostReprojectionType.PerEye; } else { Debug.LogError("You are trying to enable support for post-reprojection, but no post-reprojection script was found!"); } } else { Debug.LogError("Post reprojection is not yet fully supported in non-Forward Rendering Paths."); } #endif VRSettings.LoadDeviceByName(VRDeviceNames.PlayStationVR); // WORKAROUND: At the moment the device is created at the end of the frame so // changing almost any VR settings needs to be delayed until the next frame yield return(null); Debug.Log("------------->>> Loaded Device Name <<< --------------" + VRSettings.loadedDeviceName.ToString()); VRSettings.enabled = true; VRSettings.renderScale = renderScale; VRSettings.showDeviceView = showHmdViewOnMonitor; InputTracking.Recenter(); GameFadeManager.Instance.SetupVRMode(Camera.main.name); }
IEnumerator SwitchToOpenVR() { if (VRSettings.loadedDeviceName != "OpenVR") { Debug.Log("******* LoadDeviceByName(\"OpenVR\")..."); VRSettings.LoadDeviceByName("OpenVR"); yield return(new WaitForEndOfFrame()); // required to load device Debug.Log("SwitchToOpenVR(): " + state); yield return(new WaitForEndOfFrame()); // second wait needed if Coroutine() started from Update() Debug.Log("SwitchToOpenVR(): " + state); } if (!VRSettings.enabled) { Debug.Log("******* VRSettings.enabled = true"); VRSettings.enabled = true; ////////////////////////////////yield return new WaitForEndOfFrame (); // required for OpenVR device to become active Debug.Log("SwitchToOpenVR(): " + state); } Debug.Log("******* SteamVR.enabled = true"); SteamVR.enabled = true; //required on second enable Debug.Log("******* SteamVR.instance"); if (SteamVR.instance == null) { Debug.LogError("SteamVR.instance == null"); yield return(null); } Debug.Log("******* steamVR_Render.instance"); if (SteamVR_Render.instance == null) { Debug.LogError("steamVR_Render.instance == null"); yield return(null); } Debug.Log("SwitchToOpenVR(): " + state); RegisterListeners(); }
private void SetupVR() { //Gear VR does not currently support renderScale #if !UNITY_ANDROID VRSettings.renderScale = m_RenderScale; #endif #if UNITY_STANDALONE if (VRSettings.supportedDevices.Where(s => s.CompareTo("Oculus") == 0).Count() > 0) { VRSettings.LoadDeviceByName("Oculus"); } #endif #if UNITY_PS4 && !UNITY_EDITOR VRSettings.loadedDevice = VRDeviceType.Morpheus; #endif VRSettings.enabled = true; }
/// <summary> /// Unloads the currently loaded <see cref="VRTK_SDKSetup"/>, if there is one. /// </summary> /// <param name="disableVR">Whether to disable VR altogether after unloading the SDK Setup.</param> public void UnloadSDKSetup(bool disableVR = false) { if (loadedSetup != null) { ToggleBehaviours(false); } VRTK_SDKSetup previousLoadedSetup = loadedSetup; loadedSetup = null; if (previousLoadedSetup != null) { previousLoadedSetup.OnUnloaded(this); } if (disableVR) { VRSettings.LoadDeviceByName("None"); VRSettings.enabled = false; } if (previousLoadedSetup != null) { OnLoadedSetupChanged(new LoadedSetupChangeEventArgs(previousLoadedSetup, null, null)); } _previouslyUsedSetupInfos.Clear(); if (previousLoadedSetup != null) { _previouslyUsedSetupInfos.UnionWith( new[] { previousLoadedSetup.systemSDKInfo, previousLoadedSetup.boundariesSDKInfo, previousLoadedSetup.headsetSDKInfo, previousLoadedSetup.controllerSDKInfo } ); } }
private const float kHMDActivityTimeout = 3f; // in seconds public void OnEnable() { EditorApplication.playmodeStateChanged += OnPlaymodeStateChanged; Assert.IsNull(s_ActiveView, "Only one EditorVR should be active"); autoRepaintOnSceneChange = true; wantsMouseMove = true; s_ActiveView = this; GameObject cameraGO = EditorUtility.CreateGameObjectWithHideFlags("EditorVRCamera", EditorVR.kDefaultHideFlags, typeof(Camera)); m_Camera = cameraGO.GetComponent <Camera>(); m_Camera.enabled = false; m_Camera.cameraType = CameraType.VR; GameObject pivotGO = EditorUtility.CreateGameObjectWithHideFlags("EditorVRCameraPivot", EditorVR.kDefaultHideFlags, typeof(EditorMonoBehaviour)); m_CameraPivot = pivotGO.transform; m_Camera.transform.parent = m_CameraPivot; m_Camera.nearClipPlane = 0.01f; m_Camera.farClipPlane = 1000f; // Generally, we want to be at a standing height, so default to that const float kHeadHeight = 1.7f; Vector3 position = m_CameraPivot.position; position.y = kHeadHeight; m_CameraPivot.position = position; m_CameraPivot.rotation = Quaternion.identity; // Disable other views to increase rendering performance for EditorVR SetOtherViewsEnabled(false); VRSettings.StartRenderingToDevice(); InputTracking.Recenter(); onEnable(); }
public ConfigurableContext() { // We'll keep those always the same _Materials = new DefaultMaterialPalette(); _Settings = HS2VRSettings.Load("VRSettings.xml"); // Set defaults ConfineMouse = true; EnforceDefaultGUIMaterials = false; GUIAlternativeSortingMode = false; GuiLayer = "Default"; GuiFarClipPlane = 1000f; GuiNearClipPlane = -1000f; IgnoreMask = 0; InvisibleLayer = "Ignore Raycast"; PrimaryColor = Color.cyan; SimulateCursor = true; UILayer = "UI"; UILayerMask = LayerMask.GetMask(UILayer); UnitToMeter = 1f; NearClipPlane = 0.1f; PreferredGUI = GUIType.uGUI; }
IEnumerator ShutdownVR() { VRSettings.LoadDeviceByName(VRDeviceNames.None); // WORKAROUND: At the moment the device is created at the end of the frame so // we need to wait a frame until the VR device is changed back to 'None', and // then reset the Main Camera's FOV and Aspect yield return(null); VRSettings.enabled = false; VRSettings.showDeviceView = false; #if UNITY_PS4 // Unregister the callbacks needed to detect resetting the HMD Utility.onSystemServiceEvent -= OnSystemServiceEvent; PlayStationVR.onDeviceEvent -= onDeviceEvent; // PlayStationVR.setOutputModeHMD(false, false); PlayStationVR.SetOutputModeHMD(false); #endif Camera.main.ResetFieldOfView(); Camera.main.ResetAspect(); GameFadeManager.Instance.ResetVRMode(); }
IEnumerator SetupVR() { #if UNITY_PS4 // Register the callbacks needed to detect resetting the HMD Utility.onSystemServiceEvent += OnSystemServiceEvent; PlayStationVR.onDeviceEvent += onDeviceEvent; #endif #if UNITY_5_3 VRSettings.loadedDevice = VRDeviceType.PlayStationVR; #elif UNITY_5_4 // VRSettings.LoadDeviceByName(VRDeviceNames.PlayStationVR); // VRSettings.loadedDevice = VRDeviceType.PlayStationVR; VRSettings.LoadDeviceByName(VRSettings.supportedDevices[0]); #endif // WORKAROUND: At the moment the device is created at the end of the frame so // changing almost any VR settings needs to be delayed until the next frame yield return(null); VRSettings.enabled = true; VRSettings.renderScale = renderScale; VRSettings.showDeviceView = showHmdViewOnMonitor; }
public void OnDisable() { if (viewDisabled != null) { viewDisabled(); } EditorApplication.playmodeStateChanged -= OnPlaymodeStateChanged; VRSettings.StopRenderingToDevice(); EditorPrefs.SetBool(k_ShowDeviceView, m_ShowDeviceView); EditorPrefs.SetBool(k_UseCustomPreviewCamera, m_UseCustomPreviewCamera); SetOtherViewsEnabled(true); if (m_CameraRig) { DestroyImmediate(m_CameraRig.gameObject, true); } Assert.IsNotNull(s_ActiveView, "EditorVR should have an active view"); s_ActiveView = null; }
public VookaContext() { _Materials = new DefaultMaterialPalette(); _Settings = VRSettings.Load <RayleeSettings>("vr_settings.xml"); }
/// <summary> /// Handles SDK selection during startup. Must be called before setupping any SDK specific stuff. /// </summary> private void SetupSDK() { // Check if we even have to do any SDK selection bool needsSDKSetup = automaticSDKSelection || (actualBoundaries == null && actualHeadset == null && actualLeftController == null && actualRightController == null); if (!needsSDKSetup) { return; } string selectedSDK = "Fallback"; // Heuristic SDK detection if (automaticSDKSelection) { if (!VRDevice.isPresent) { selectedSDK = "Simulator"; } else { if (VRDevice.model.Contains("Oculus") || VRDevice.model.Contains("Rift")) { selectedSDK = "OculusVR"; } else { // Assume everyone else except Oculus uses SteamVR selectedSDK = "SteamVR"; } } // Check for command line SDKs. These override all the previous selections. var args = System.Environment.GetCommandLineArgs(); foreach (var arg in args) { if (arg.Equals("--vr-none")) { selectedSDK = "Fallback"; } if (arg.Equals("--vr-oculus")) { selectedSDK = "OculusVR"; } if (arg.Equals("--vr-steam")) { selectedSDK = "SteamVR"; } if (arg.Equals("--vr-simulator")) { selectedSDK = "Simulator"; } } Debug.Log("Selected VR SDK: " + selectedSDK); // Set correct individual SDKs systemSDKInfo = GetSDK(selectedSDK, AvailableSystemSDKInfos); boundariesSDKInfo = GetSDK(selectedSDK, AvailableBoundariesSDKInfos); headsetSDKInfo = GetSDK(selectedSDK, AvailableHeadsetSDKInfos); controllerSDKInfo = GetSDK(selectedSDK, AvailableControllerSDKInfos); // Load the SDK camera rig if one has been assigned int sdkIndex = AvailableSystemSDKInfos.IndexOf(GetSDK(selectedSDK)); var sdkPrefab = automaticSDKPrefabList[sdkIndex]; if (sdkPrefab != null) { var go = Instantiate(sdkPrefab) as GameObject; if (go != null) { // Remove (Clone) from the name of the instantiated game object, otherwise SDKs don't work properly // as they find the gameobjects by their name. go.name = go.name.Replace("(Clone)", ""); } } // Disable VR if we don't have a true VR SDK if (selectedSDK == "Fallback" || selectedSDK == "Simulator") { VRSettings.enabled = false; VRSettings.LoadDeviceByName("None"); } // Assign VRTK components to the newly instantiated rig var playareaTransform = GetBoundariesSDK().GetPlayArea(); actualBoundaries = (playareaTransform ? playareaTransform.gameObject : null); var headsetTransform = GetHeadsetSDK().GetHeadset(); actualHeadset = (headsetTransform ? headsetTransform.gameObject : null); var controllerLeft = GetControllerSDK().GetControllerLeftHand(true); actualLeftController = controllerLeft; var controllerRight = GetControllerSDK().GetControllerRightHand(true); actualRightController = controllerRight; var controllerAliasLeft = GetControllerSDK().GetControllerModel(SDK_BaseController.ControllerHand.Left); modelAliasLeftController = controllerAliasLeft; var controllerAliasRight = GetControllerSDK().GetControllerModel(SDK_BaseController.ControllerHand.Right); modelAliasRightController = controllerAliasRight; } }
void Start() { VRSettings.LoadDeviceByName(""); VRSettings.enabled = false; }
public DefaultContext() { _Materials = CreateMaterialPalette(); _Settings = CreateSettings(); }
/// <summary> /// Tries to load a valid <see cref="VRTK_SDKSetup"/> from a list. /// </summary> /// <remarks> /// The first loadable <see cref="VRTK_SDKSetup"/> in the list will be loaded. Will fall back to disable VR if none of the provided Setups is useable. /// </remarks> /// <param name="startIndex">The index of the <see cref="VRTK_SDKSetup"/> to start the loading with.</param> /// <param name="tryToReinitialize">Whether or not to retry initializing and using the currently set but unusable VR Device.</param> /// <param name="sdkSetups">The list to try to load a <see cref="VRTK_SDKSetup"/> from.</param> public void TryLoadSDKSetup(int startIndex, bool tryToReinitialize, params VRTK_SDKSetup[] sdkSetups) { if (sdkSetups.Length == 0) { return; } if (startIndex < 0 || startIndex >= sdkSetups.Length) { VRTK_Logger.Fatal(new ArgumentOutOfRangeException("startIndex")); return; } sdkSetups = sdkSetups.ToList() .GetRange(startIndex, sdkSetups.Length - startIndex) .ToArray(); foreach (VRTK_SDKSetup invalidSetup in sdkSetups.Where(setup => !setup.isValid)) { string setupErrorDescriptions = string.Join("\n- ", invalidSetup.GetSimplifiedErrorDescriptions()); if (!string.IsNullOrEmpty(setupErrorDescriptions)) { setupErrorDescriptions = "- " + setupErrorDescriptions; VRTK_Logger.Warn(string.Format("Ignoring SDK Setup '{0}' because there are some errors with it:\n{1}", invalidSetup.name, setupErrorDescriptions)); } } sdkSetups = sdkSetups.Where(setup => setup.isValid).ToArray(); VRTK_SDKSetup previousLoadedSetup = loadedSetup; ToggleBehaviours(false); loadedSetup = null; if (previousLoadedSetup != null) { previousLoadedSetup.OnUnloaded(this); } string loadedDeviceName = string.IsNullOrEmpty(VRSettings.loadedDeviceName) ? "None" : VRSettings.loadedDeviceName; bool isDeviceAlreadyLoaded = sdkSetups[0].usedVRDeviceNames.Contains(loadedDeviceName); if (!isDeviceAlreadyLoaded) { if (!tryToReinitialize && !VRSettings.enabled && loadedDeviceName != "None") { sdkSetups = sdkSetups.Where(setup => !setup.usedVRDeviceNames.Contains(loadedDeviceName)) .ToArray(); } VRTK_SDKSetup[] missingVRDeviceSetups = sdkSetups .Where(setup => setup.usedVRDeviceNames.Except(VRSettings.supportedDevices.Concat(new[] { "None" })).Any()) .ToArray(); foreach (VRTK_SDKSetup missingVRDeviceSetup in missingVRDeviceSetups) { string missingVRDevicesText = string.Join( ", ", missingVRDeviceSetup.usedVRDeviceNames .Except(VRSettings.supportedDevices) .ToArray() ); VRTK_Logger.Warn(string.Format("Ignoring SDK Setup '{0}' because the following VR device names are missing from the PlayerSettings:\n{1}", missingVRDeviceSetup.name, missingVRDevicesText)); } sdkSetups = sdkSetups.Except(missingVRDeviceSetups).ToArray(); string[] vrDeviceNames = sdkSetups .SelectMany(setup => setup.usedVRDeviceNames) .Distinct() .Concat(new[] { "None" }) // Add "None" to the end to fall back to .ToArray(); VRSettings.LoadDeviceByName(vrDeviceNames); } StartCoroutine(FinishSDKSetupLoading(sdkSetups, previousLoadedSetup)); }
protected virtual VRSettings CreateSettings() { return(VRSettings.Load <VRSettings>("VRSettings.xml")); }
public void Start() { string[] supportedDevices = VRSettings.supportedDevices.Where(deviceName => deviceName != "None").ToArray(); Debug.Log("Using VR Device: " + string.Join(", ", supportedDevices)); VRSettings.LoadDeviceByName(supportedDevices); }