Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [1.0.0-preview.2] - 2018-12-19
* Fix CI build tooling to correct (new) validation issues.

## [1.0.0-preview.1] - 2018-12-19
* Fix loader helper to support integrated and standlone subsystem loading.
* Tagging build as 1.0.0 preview to note that this should be feature complete for 1.0.
  • Loading branch information
Unity Technologies committed Dec 18, 2018
1 parent b2efca7 commit 26b6c3d
Show file tree
Hide file tree
Showing 35 changed files with 380 additions and 121 deletions.
73 changes: 0 additions & 73 deletions .editorconfig

This file was deleted.

8 changes: 0 additions & 8 deletions .gitattribute

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.0.0-preview.2] - 2018-12-19
* Fix CI build tooling to correct (new) validation issues.

## [1.0.0-preview.1] - 2018-12-19
* Fix loader helper to support integrated and standlone subsystem loading.
* Tagging build as 1.0.0 preview to note that this should be feature complete for 1.0.

## [0.1.0-preview.12] - 2018-07-30
* Update to handle breaking API change in 2019.1 for UIElements
* Update to handle breaking API change in 2018.3 for Unified Settings.
Expand Down
2 changes: 1 addition & 1 deletion Runtime/XRLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public abstract class XRLoader : ScriptableObject
/// <paramref name="T">< Type of the subsystem to get ></paramref>
///
/// <returns>The loaded subsystem or null if not found.</returns>
public abstract T GetLoadedSubsystem<T>() where T : IntegratedSubsystem;
public abstract T GetLoadedSubsystem<T>() where T : class, ISubsystem;
}
}
94 changes: 79 additions & 15 deletions Runtime/XRLoaderHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

using UnityEngine;
using UnityEngine.Experimental.XR;
using UnityEngine.Experimental;
Expand All @@ -18,7 +20,7 @@ public abstract class XRLoaderHelper : XRLoader
/// Map of loaded susbsystems. Used so we don't always have to fo to XRSubsystemManger and do a manual
/// search to find the instance we loaded.
/// </summary>
protected Dictionary<Type, IntegratedSubsystem> m_SubsystemInstanceMap = new Dictionary<Type, IntegratedSubsystem>();
protected Dictionary<Type, ISubsystem> m_SubsystemInstanceMap = new Dictionary<Type, ISubsystem>();

/// <summary>
/// Gets the loaded subsystem of the specified type. Implementation dependent as only implemetnations
Expand All @@ -31,7 +33,7 @@ public abstract class XRLoaderHelper : XRLoader
public override T GetLoadedSubsystem<T>()
{
Type subsystemType = typeof(T);
IntegratedSubsystem subsystem;
ISubsystem subsystem;
m_SubsystemInstanceMap.TryGetValue(subsystemType, out subsystem);
return subsystem as T;
}
Expand All @@ -41,8 +43,8 @@ public override T GetLoadedSubsystem<T>()
/// a previous call to CreateSubsystem
/// </summary>
///
/// <paramref name="T">A subclass of <see cref="IntegratedSubsystem">IntegratedSubsystem</see></paramref>
protected void StartSubsystem<T>() where T : IntegratedSubsystem
/// <paramref name="T">A subclass of <see cref="ISubsystem">ISubsystem</see></paramref>
protected void StartSubsystem<T>() where T : class, ISubsystem
{
T subsystem = GetLoadedSubsystem<T>();
if (subsystem != null)
Expand All @@ -54,8 +56,8 @@ protected void StartSubsystem<T>() where T : IntegratedSubsystem
/// a previous call to CreateSubsystem
/// </summary>
///
/// <paramref name="T">A subclass of <see cref="IntegratedSubsystem">IntegratedSubsystem</see></paramref>
protected void StopSubsystem<T>() where T : IntegratedSubsystem
/// <paramref name="T">A subclass of <see cref="ISubsystem">ISubsystem</see></paramref>
protected void StopSubsystem<T>() where T : class, ISubsystem
{
T subsystem = GetLoadedSubsystem<T>();
if (subsystem != null)
Expand All @@ -67,25 +69,82 @@ protected void StopSubsystem<T>() where T : IntegratedSubsystem
/// a previous call to CreateSubsystem
/// </summary>
///
/// <paramref name="T">A subclass of <see cref="IntegratedSubsystem">IntegratedSubsystem</see></paramref>
protected void DestroySubsystem<T>() where T : IntegratedSubsystem
/// <paramref name="T">A subclass of <see cref="ISubsystem">ISubsystem</see></paramref>
protected void DestroySubsystem<T>() where T : class, ISubsystem
{
T subsystem = GetLoadedSubsystem<T>();
if (subsystem != null)
subsystem.Destroy();
}

protected ISubsystem CreateIntegratedSubsystemHelper<TSubsystem>(IntegratedSubsystemDescriptor<TSubsystem> descriptor, string id)
where TSubsystem : IntegratedSubsystem
{
ISubsystem ret = null;
if (descriptor != null && String.Compare(descriptor.id, id, true) == 0)
{
ret = descriptor.Create();
}
return ret;
}

protected ISubsystem CreateSubsystemHelper<TSubsystem>(SubsystemDescriptor<TSubsystem> descriptor, string id)
where TSubsystem : Subsystem
{
ISubsystem ret = null;
if (descriptor != null && String.Compare(descriptor.id, id, true) == 0)
{
ret = descriptor.Create();
}
return ret;
}

/// <summary>
/// Creates a native, integrated subsystem given a list of descriptors and a specific subsystem id.
/// </summary>
///
/// <paramref name="TDescriptor">The descriptor type being passed in.</paramref>
/// <paramref name="TSubsystem">The subsystem type being requested</paramref>
/// <param name="descriptors">List of TDescriptor instances to use for subsystem matching.</param>
/// <param name="id">The identifier key of the particualr subsystem implementation being requested.</param>
protected void CreateIntegratedSubsystem<TDescriptor, TSubsystem>(List<TDescriptor> descriptors, string id)
where TDescriptor : IntegratedSubsystemDescriptor
where TSubsystem : IntegratedSubsystem
{
if (descriptors == null)
throw new ArgumentNullException("descriptors");

SubsystemManager.GetSubsystemDescriptors<TDescriptor>(descriptors);

if (descriptors.Count > 0)
{
foreach (var descriptor in descriptors)
{
IntegratedSubsystemDescriptor<TSubsystem> desc = descriptor as IntegratedSubsystemDescriptor<TSubsystem>;
if (desc != null && String.Compare(desc.id, id) == 0)
{
ISubsystem subsys = desc.Create();
if (subsys != null)
{
m_SubsystemInstanceMap[typeof(TSubsystem)] = subsys;
break;
}
}
}
}
}

/// <summary>
/// Creates a subsystem given a list of descriptors and a specific subsystem id.
/// Creates a managed, standalone subsystem given a list of descriptors and a specific subsystem id.
/// </summary>
///
/// <paramref name="TDescriptor">The descriptor type being passed in.</paramref>
/// <paramref name="TSubsystem">The subsystem type being requested</paramref>
/// <param name="descriptors">List of TDescriptor instances to use for subsystem matching.</param>
/// <param name="id">The identifier key of the particualr subsystem implementation being requested.</param>
protected void CreateSubsystem<TDescriptor, TSubsystem>(List<TDescriptor> descriptors, string id)
where TDescriptor : IntegratedSubsystemDescriptor<TSubsystem>
where TSubsystem : IntegratedSubsystem<TDescriptor>
protected void CreateStandaloneSubsystem<TDescriptor, TSubsystem>(List<TDescriptor> descriptors, string id)
where TDescriptor : SubsystemDescriptor
where TSubsystem : Subsystem
{
if (descriptors == null)
throw new ArgumentNullException("descriptors");
Expand All @@ -96,10 +155,15 @@ protected void CreateSubsystem<TDescriptor, TSubsystem>(List<TDescriptor> descri
{
foreach (var descriptor in descriptors)
{
if (descriptor.id == id)
SubsystemDescriptor<TSubsystem> desc = descriptor as SubsystemDescriptor<TSubsystem>;
if (desc != null && String.Compare(desc.id, id) == 0)
{
IntegratedSubsystem s = descriptor.Create();
m_SubsystemInstanceMap[typeof(TSubsystem)] = s;
ISubsystem subsys = desc.Create();
if (subsys != null)
{
m_SubsystemInstanceMap[typeof(TSubsystem)] = subsys;
break;
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Samples~/.sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

{
"displayName":"Example XR Management implementation",
"description": "Example code showing how to implement various portions of the XR Management API.",
"createSeparatePackage": false
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion Samples/SampleLoader.cs → Samples~/SampleLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public override bool Initialize()
// TODO: Pass settings off to plugin prior to subsystem init.
}

CreateSubsystem<XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "InputSubsystemDescriptor");
CreateIntegratedSubsystem<XRInputSubsystemDescriptor, XRInputSubsystem>(s_InputSubsystemDescriptors, "InputSubsystemDescriptor");

return false;
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions Tests/.tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"createSeparatePackage": false
}
61 changes: 52 additions & 9 deletions Tests/Editor/EditorTests.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,70 @@
using UnityEngine;
using System;
using System.Collections;

using NUnit.Framework;

using UnityEditor;

using UnityEngine;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;

namespace ManagmentTests.Editor
using Unity.XR.Management.Tests.Standalone;
using Unity.XR.Management.Tests.Standalone.Providing;

namespace Unity.XR.Management.EditorTests
{
class EditorTests
{
[OneTimeSetUp]
public void OneTimeSetUp()
{
StandaloneSubsystemParams parms = new StandaloneSubsystemParams("Standalone Subsystem", typeof(StandaloneSubsystem));
StandaloneSubsystemDescriptor.Create(parms);
}

StandaloneLoader loader;

[SetUp]
public void SetUp()
{
loader = ScriptableObject.CreateInstance<StandaloneLoader>() as StandaloneLoader;
}

[TearDown]
public void TearDown()
{
UnityEngine.Object.DestroyImmediate(loader);
loader = null;
}

[Test]
public void EditorSampleTestSimplePasses()
public void StandaloneLoaderCreateTest()
{
// Use the Assert class to test conditions.
Assert.IsTrue(loader.Initialize());
}

// A UnityTest behaves like a coroutine in PlayMode
// and allows you to yield null to skip a frame in EditMode
[UnityTest]
public IEnumerator EditorSampleTestWithEnumeratorPasses()
public IEnumerator StandaloneLoaderLifecycleTest()
{
// Use the Assert class to test conditions.
// yield to skip a frame
Assert.IsTrue(loader.Initialize());
yield return null;

Assert.IsTrue(loader.Start());
Assert.IsTrue(loader.started);
yield return null;


Assert.IsTrue(loader.Stop());
Assert.IsTrue(loader.stopped);
yield return null;


Assert.IsTrue(loader.Deinitialize());
Assert.IsTrue(loader.deInitialized);
yield return null;

}
}
}
3 changes: 2 additions & 1 deletion Tests/Editor/Unity.XR.Management.EditorTests.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "Unity.XR.Management.EditorTests",
"references": [
"Unity.XR.Management.Editor",
"Unity.XR.Management"
"Unity.XR.Management",
"Unity.XR.Management.Tests.Standalone"
],
"optionalUnityReferences": [
"TestAssemblies"
Expand Down
3 changes: 2 additions & 1 deletion Tests/Runtime/Unity.XR.Management.Tests.asmdef
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"name": "Unity.XR.Management.Tests",
"references": [
"Unity.XR.Management"
"Unity.XR.Management",
"Unity.XR.Management.Tests.Standalone"
],
"optionalUnityReferences": [
"TestAssemblies"
Expand Down
2 changes: 1 addition & 1 deletion Samples.meta → Tests/StandaloneSubsystem.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 26b6c3d

Please sign in to comment.