Enable/Disable VR from code
Include using UnityEngine.XR;
at the top.
Call XRSettings.LoadDeviceByName("")
with empty string followed by XRSettings.enabled = false;
to disable VR in the start function to disable VR.
When you want to enable it later on, call XRSettings.LoadDeviceByName("daydream")
with the VR name followed by XRSettings.enabled = true;
.
You should wait for a frame between each function call. That requires this to be done a corutine function.
Also, On some VR devices, you must go to Edit->Project Settings->Player and make sure that Virtual Reality Supported check-box is checked(true) before this will work. Then you can disable it in the Start function and enable it whenever you want.
EDIT:
This is known to work on some VR devices and not all VR devices. Although, it should work on Daydream VR. Complete code sample:
IEnumerator LoadDevice(string newDevice, bool enable)
{
XRSettings.LoadDeviceByName(newDevice);
yield return null;
XRSettings.enabled = enable;
}
void EnableVR()
{
StartCoroutine(LoadDevice("daydream", true));
}
void DisableVR()
{
StartCoroutine(LoadDevice("", false));
}
Call EnableVR()
to enable vr and DisableVR()
to disable it. If you are using anything other than daydream, pass the name of that VR device to the LoadDevice
function in the EnableVR()
function.
Daydream Non-VR Mode in Unity 5.4.2f-GVR13
Change your minimum api level in build setting to Android 7.0 'Nougat'.
Toggle A-Frame's vr-mode-ui dynamically
Currently the component doesn't support enabling/disabling much of the button. More of a one-time thing. This can be fixed but will file an issue.
In the meantime, it would be easier to simply toggle the visibility of the button using CSS:
document.querySelector('.a-enter-vr-button').style.visible = 'none';
Daydream Hybrid (NonVR/VR) App does not switch VR mode
So, I finally found the issue and will leave this answer for future reference.
I started over from scratch a few times. In the end, it was stupidity as I was just missing the two lines marked below
UnityEngine.VR.VRSettings.LoadDeviceByName("daydream");
// wait one frame //<--
UnityEngine.VR.VRSettings.enabled = true; //<--
LoadDeviceByName does initialize the Daydream GvrViewer as determined by logcat output, but it does not implicitly activate the StereoController.
I also uploaded the changes to github. Thus, you can find a bare, working Scene (starting in NonVR) and switching every 10 seconds for Unity 5.4.2f2-GVR13 on github: tag=StackoverflowAnswer
How can I enable the Virtual Reality Supported project setting from a Unity editor script?
Please try
PlayerSettings.virtualRealitySupported = true;
(While I didn't see this in Unity's PlayerSettings docs, I remembered the Oculus VR plugin did similar, so I dug there.)
Unity ARCore XR settings and Vuforia enable(or switch) at Runtime in Android UnityPlayer
No. You can't currently do this now but this might change in the future. The reason is because there is no way to disable ARCore at this moment. You can probably suggest that as a feature on their Github page and explain you need it.
For Vuforia, you can disable it with VuforiaBehaviour.Instance.enabled = false;
and enable
it by setting it to true again.
The problem is that you can't do the-same with ARCore. You might be able to do the-same thing by finding all ARCore components in the scene and disabling them but I am not sure if that will release the camera or even work at-all.
Stop, Disable or Pause head tracking google cardboard
Use OnHeadUpdated
event
Following this code.
CardboardHead head;
void Start () {
head = GameObject.Find("Head").GetComponent<CardboardHead>();
head.OnHeadUpdated += Test_OnHeadUpdated;
}
private void Test_OnHeadUpdated(GameObject head_obj)
{
head_obj.transform.rotation = Quaternion.identity;
head_obj.transform.position = //the position when you stop cardboard;
}
Related Topics
Entity Framework 6 Code First Custom Functions
Loop Through All Controls of a Form, Even Those in Groupboxes
Autonumber with Entity Framework
How to Clear All Controls on a Form C#
How to Hide Desktop Icons Programmatically
C# - Set Directory Permissions for All Users in Windows 7
Gmail Smtp via C# .Net Errors on All Ports
Popup's in Selenium Webdrivers
Using Mediaelement to Play Video from Stream
System.Net.Http: Missing from Namespace? (Using .Net 4.5)
Resolve Type from Class Name in a Different Assembly
The Type Arguments for Method Cannot Be Inferred from the Usage
Convert Datetime to Date Format Dd/Mm/Yyyy
Split String into String Array of Single Characters
Iis Server & ASP.NET Core - 500.19 with Error Code 0X8007000D on Httpplatformhandler Tag
Nullable Reference Types: How to Specify "T" Type Without Constraining to Class or Struct
How to Prevent Flickering in Listview When Updating a Single Listviewitem's Text