Skip to content

Instantly share code, notes, and snippets.

@demonixis
Created January 13, 2020 13:28
Show Gist options
  • Save demonixis/fc2f9154cd9d87e5f1c6a7a1de2dbb70 to your computer and use it in GitHub Desktop.
Save demonixis/fc2f9154cd9d87e5f1c6a7a1de2dbb70 to your computer and use it in GitHub Desktop.
A demonstration of how to use the all new XRSubsystem with Unity 2019.3+
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.Management;
public class XRSubSystemTest : MonoBehaviour
{
public void Start()
{
var xrSettings = XRGeneralSettings.Instance;
if (xrSettings == null)
{
Debug.Log($"XRGeneralSettings is null.");
return;
}
var xrManager = xrSettings.Manager;
if (xrManager == null)
{
Debug.Log($"XRManagerSettings is null.");
return;
}
var xrLoader = xrManager.activeLoader;
if (xrLoader == null)
{
Debug.Log($"XRLoader is null.");
return;
}
Debug.Log($"Loaded XR Device: {xrLoader.name}");
var xrDisplay = xrLoader.GetLoadedSubsystem<XRDisplaySubsystem>();
Debug.Log($"XRDisplay: {xrDisplay != null}");
if (xrDisplay != null)
{
if (xrDisplay.TryGetDisplayRefreshRate(out float refreshRate))
{
Debug.Log($"Refresh Rate: {refreshRate}hz");
}
}
var xrInput = xrLoader.GetLoadedSubsystem<XRInputSubsystem>();
Debug.Log($"XRInput: {xrInput != null}");
if (xrInput != null)
{
xrInput.TrySetTrackingOriginMode(TrackingOriginModeFlags.Device);
xrInput.TryRecenter();
}
var xrMesh = xrLoader.GetLoadedSubsystem<XRMeshSubsystem>();
Debug.Log($"XRMesh: {xrMesh != null}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment