using System.Collections.Generic;
using UnityEngine.XR;
using UnityEngine.XR.Management;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.XR.Management;
#endif
namespace Samples
{
///
/// 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.
///
#if UNITY_EDITOR
[XRSupportedBuildTarget(BuildTargetGroup.Standalone, new BuildTarget[]{ BuildTarget.StandaloneWindows, BuildTarget.StandaloneWindows64})]
[XRSupportedBuildTarget(BuildTargetGroup.Android)]
#endif
public class SampleLoader : XRLoaderHelper
{
static List s_InputSubsystemDescriptors =
new List();
/// Return the currently active Input Subsystem intance, if any.
public XRInputSubsystem inputSubsystem
{
get { return GetLoadedSubsystem(); }
}
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
/// Implementaion of
/// True if successful, false otherwise
public override bool Initialize()
{
SampleSettings settings = GetSettings();
if (settings != null)
{
// TODO: Pass settings off to plugin prior to subsystem init.
}
CreateSubsystem(s_InputSubsystemDescriptors, "InputSubsystemDescriptor");
return false;
}
/// Implementaion of
/// True if successful, false otherwise
public override bool Start()
{
StartSubsystem();
return true;
}
/// Implementaion of
/// True if successful, false otherwise
public override bool Stop()
{
StopSubsystem();
return true;
}
/// Implementaion of
/// True if successful, false otherwise
public override bool Deinitialize()
{
DestroySubsystem();
return base.Deinitialize();
}
#endregion
}
}