SampleLoader.cs
2.99 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System.Collections.Generic;
using UnityEngine.XR;
using UnityEngine.XR.Management;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.XR.Management;
#endif
namespace Samples
{
/// <summary>
/// Sample loader implentation showing how to create simple loader.
/// NOTE: You have to rename this class to make it appear in the loader list for
/// XRManager.
/// </summary>
#if UNITY_EDITOR
[XRSupportedBuildTarget(BuildTargetGroup.Standalone, new BuildTarget[]{ BuildTarget.StandaloneWindows, BuildTarget.StandaloneWindows64})]
[XRSupportedBuildTarget(BuildTargetGroup.Android)]
#endif
public class SampleLoader : XRLoaderHelper
{
static List<XRInputSubsystemDescriptor> s_InputSubsystemDescriptors =
new List<XRInputSubsystemDescriptor>();
/// <summary>Return the currently active Input Subsystem intance, if any.</summary>
public XRInputSubsystem inputSubsystem
{
get { return GetLoadedSubsystem<XRInputSubsystem>(); }
}
SampleSettings GetSettings()
{
SampleSettings settings = null;
// When running in the Unity Editor, we have to load user's customization of configuration data directly from
// EditorBuildSettings. At runtime, we need to grab it from the static instance field instead.
#if UNITY_EDITOR
UnityEditor.EditorBuildSettings.TryGetConfigObject(SampleConstants.k_SettingsKey, out settings);
#else
settings = SampleSettings.s_RuntimeInstance;
#endif
return settings;
}
#region XRLoader API Implementation
/// <summary>Implementaion of <see cref="XRLoader.Initialize"/></summary>
/// <returns>True if successful, false otherwise</returns>
public override bool Initialize()
{
SampleSettings settings = GetSettings();
if (settings != null)
{
// TODO: Pass settings off to plugin prior to subsystem init.
}
CreateSubsystem<XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "InputSubsystemDescriptor");
return false;
}
/// <summary>Implementaion of <see cref="XRLoader.Start"/></summary>
/// <returns>True if successful, false otherwise</returns>
public override bool Start()
{
StartSubsystem<XRInputSubsystem>();
return true;
}
/// <summary>Implementaion of <see cref="XRLoader.Stop"/></summary>
/// <returns>True if successful, false otherwise</returns>
public override bool Stop()
{
StopSubsystem<XRInputSubsystem>();
return true;
}
/// <summary>Implementaion of <see cref="XRLoader.Deinitialize"/></summary>
/// <returns>True if successful, false otherwise</returns>
public override bool Deinitialize()
{
DestroySubsystem<XRInputSubsystem>();
return base.Deinitialize();
}
#endregion
}
}