using System.Collections.Generic;
using UnityEngine.XR.Management;
namespace UnityEngine.XR.ARFoundation
{
///
/// Manages the lifetime of the XRInputSubsystem. Add one of these to any GameObject in your scene
/// if you want device pose information to be available. Read the input by using the TrackedPoseDriver
///
[DefaultExecutionOrder(ARUpdateOrder.k_InputManager)]
[DisallowMultipleComponent]
[AddComponentMenu("XR/AR Foundation/AR Input Manager")]
[HelpURL(typeof(ARInputManager))]
public sealed class ARInputManager : MonoBehaviour
{
///
/// Get the [`XRInputSubsystem`](https://docs.unity3d.com/ScriptReference/XR.XRInputSubsystem.html)
/// whose lifetime this component manages.
///
public XRInputSubsystem subsystem { get; private set; }
void OnEnable()
{
subsystem = GetActiveSubsystemInstance();
if (subsystem != null)
subsystem.Start();
}
void OnDisable()
{
if (subsystem != null && subsystem.running)
subsystem.Stop();
}
void OnDestroy()
{
subsystem = null;
}
XRInputSubsystem GetActiveSubsystemInstance()
{
XRInputSubsystem activeSubsystem = null;
// Query the currently active loader for the created subsystem, if one exists.
if (XRGeneralSettings.Instance != null && XRGeneralSettings.Instance.Manager != null)
{
XRLoader loader = XRGeneralSettings.Instance.Manager.activeLoader;
if (loader != null)
{
activeSubsystem = loader.GetLoadedSubsystem();
}
}
if (activeSubsystem == null)
{
Debug.LogWarning($"No active {typeof(XRInputSubsystem).FullName} is available. Please ensure that a " +
"valid loader configuration exists in the XR project settings.");
}
return activeSubsystem;
}
static List s_SubsystemDescriptors =
new List();
}
}