ARInputManager.cs
2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System.Collections.Generic;
using UnityEngine.XR.Management;
namespace UnityEngine.XR.ARFoundation
{
/// <summary>
/// Manages the lifetime of the <c>XRInputSubsystem</c>. Add one of these to any <c>GameObject</c> in your scene
/// if you want device pose information to be available. Read the input by using the <c>TrackedPoseDriver</c>
/// </summary>
[DefaultExecutionOrder(ARUpdateOrder.k_InputManager)]
[DisallowMultipleComponent]
[HelpURL(HelpUrls.ApiWithNamespace + nameof(ARInputManager) + ".html")]
public sealed class ARInputManager : MonoBehaviour
{
/// <summary>
/// Get the [`XRInputSubsystem`](https://docs.unity3d.com/ScriptReference/XR.XRInputSubsystem.html)
/// whose lifetime this component manages.
/// </summary>
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<XRInputSubsystem>();
}
}
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<XRInputSubsystemDescriptor> s_SubsystemDescriptors =
new List<XRInputSubsystemDescriptor>();
}
}