using UnityEngine.XR.Management;
namespace UnityEngine.XR.ARFoundation
{
///
/// A utility for interacting with an `XRLoader` from
/// [XR Management](https://docs.unity3d.com/Packages/com.unity.xr.management@4.0/manual/index.html).
///
///
/// XR Management controls the lifecycle of subsystems. Components in AR Foundation, such as `ARSession` or
/// `ARPlaneManager`, turn subsystems on and off, but do not create or destroy them. Therefore, subsystems
/// can persist across many scenes. They are automatically created on app startup, but are not destroyed
/// during a scene switch. This allows you to keep the same session alive between scenes, for example.
///
public static class LoaderUtility
{
///
/// Get the 'active' loader from XR Management.
///
/// Returns the currently active `XRLoader`.
public static XRLoader GetActiveLoader()
{
if (XRGeneralSettings.Instance != null && XRGeneralSettings.Instance.Manager != null)
{
return XRGeneralSettings.Instance.Manager.activeLoader;
}
return null;
}
///
/// Initializes the currently active `XR Loader`, if one exists. This creates all subsystems.
///
/// Returns `true` if there is an active loader and its `Initialize` method returns `true`.
/// Returns `false` otherwise.
public static bool Initialize()
{
var loader = GetActiveLoader();
return loader && loader.Initialize();
}
///
/// Deinitializes the currently active `XR Loader`, if one exists. This destroys all subsystems.
///
/// Returns `true` if there is an active loader and its `Deinitialize` method returns `true`.
/// Returns `false` otherwise.
public static bool Deinitialize()
{
var loader = GetActiveLoader();
return loader && loader.Deinitialize();
}
}
}