diff --git a/CHANGELOG.md b/CHANGELOG.md index bd81f8f..7d31f70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). +## [3.2.12] - 2020-06-05 +* Fix testing definitions to allows us to remove tests as separate packages. + +## [3.2.11] - 2020-06-04 +* Documentation updates for clarity and correctness. +* Block use of deprecated APIs on 2020.2 and later. + ## [3.2.11-preview.1] - 2020-05-15 * Fix FB 1242581 : Fix a number of issue around cache rebuilding and persistent UI display of cache rebuilding even though nothing was happening. * Fix FB 1245181 : Fix nullderef access of settings manager instance. diff --git a/Documentation~/EndUser.md b/Documentation~/EndUser.md index 13fb357..30759c2 100644 --- a/Documentation~/EndUser.md +++ b/Documentation~/EndUser.md @@ -24,6 +24,46 @@ If you want to start XR on a per-Scene basis (for example, to start in 2D and tr To handle pause state changes in the Editor, subscribe to the [`EditorApplication.pauseStateChanged`](https://docs.unity3d.com/ScriptReference/EditorApplication-pauseStateChanged.html) API, then stop and start the subsystems according to the new pause state that the `pauseStateChange` delegate method returns. +The following code shows an example of how to manually control XR using XR Plug-in Management: + +``` +using System.Collections; +using UnityEngine; + +using UnityEngine.XR.Management; + +public class ManualXRControl +{ + public IEnumerator StartXR() + { + Debug.Log("Initializing XR..."); + yield return XRGeneralSettings.Instance.Manager.InitializeLoader(); + + if (XRGeneralSettings.Instance.Manager.activeLoader == null) + { + Debug.LogError("Initializing XR Failed. Check Editor or Player log for details."); + } + else + { + Debug.Log("Starting XR..."); + XRGeneralSettings.Instance.Manager.activeLoader.Start(); + } + } + + void StopXR() + { + Debug.Log("Stopping XR..."); + + if (XRGeneralSettings.Instance.Manager.activeLoader != null) + { + XRGeneralSettings.Instance.Manager.activeLoader.Stop(); + XRGeneralSettings.Instance.Manager.activeLoader.Deinitialize(); + Debug.Log("XR stopped completely."); + } + } +} +``` + ## Customizing build and runtime settings Any package that needs build or runtime settings should provide a settings data type for use. This data type appears in the **Project Settings** window, underneath a top level **XR** node. @@ -107,8 +147,4 @@ You would most likely place this script in a custom build script, but that isn't ## Installing the XR Plug-in Management package -Most XR Plug-in provider packages typically include XR Plug-in Management, so you shouldn't need to install it. If you do need to install it, follow the instructions in the [Package Manager documentation](https://docs.unity3d.com/Packages/com.unity.package-manager-ui@latest/index.html). - -## Installing the Legacy Input Helpers package - -Unity requires the Legacy Input Helpers package to operate XR devices correctly. To check if the Legacy Input Helpers package is installed, open the **Project Settings** window and navigate to **XR Plug-in Management** > **Input Helpers**. If Unity can't locate the package, click the **Install Legacy Helpers Package** button to install it. +Please see related Unity documentation for [Configuring XR](https://docs.unity3d.com/Manual/configuring-project-for-xr.html ). diff --git a/Documentation~/com.unity.xr.management.md b/Documentation~/com.unity.xr.management.md index 4636683..7685deb 100644 --- a/Documentation~/com.unity.xr.management.md +++ b/Documentation~/com.unity.xr.management.md @@ -43,7 +43,7 @@ There are two target audiences for XR Plug-in Management: the end user and the p This version of XR Plug-in Management is compatible with the following versions of the Unity Editor: -* 2019.1 and later (recommended) +* 2019.3 and later (recommended) ### Known limitations diff --git a/Editor/Legacy/XRLegacyUninstaller.cs b/Editor/Legacy/XRLegacyUninstaller.cs index 564745c..587bccd 100644 --- a/Editor/Legacy/XRLegacyUninstaller.cs +++ b/Editor/Legacy/XRLegacyUninstaller.cs @@ -177,6 +177,7 @@ static XRLegacyUninstaller() packSettings.SaveSettings(); } +#if !UNITY_2020_2_OR_NEWER bool virtualRealityEnabled = false; foreach (var buildTargetGroup in (BuildTargetGroup[])Enum.GetValues(typeof(BuildTargetGroup))) { @@ -201,7 +202,8 @@ static XRLegacyUninstaller() } } } - } +#endif //!UNITY_2020_2_OR_NEWER +} } }; diff --git a/Editor/XRSettingsManager.cs b/Editor/XRSettingsManager.cs index 391bfbb..602cf34 100644 --- a/Editor/XRSettingsManager.cs +++ b/Editor/XRSettingsManager.cs @@ -35,12 +35,9 @@ static class Styles struct Content { public static readonly GUIContent k_InitializeOnStart = new GUIContent("Initialize XR on Startup"); - public static readonly GUIContent k_DocText = new GUIContent("View documentation"); - public static readonly Uri k_DocUri = new Uri("https://docs.unity3d.com/Manual/XRPluginArchitecture.html"); - public static readonly GUIContent k_ExplanatoryText = new GUIContent("Selecting an XR plug-in provider below enables that provider for the corresponding build target. The appropriate plug-in package will be installed if it is not already present. Disabling plug-ins will not automatically uninstall already installed packages. To uninstall a provider plug-in use the Package Manager."); - public static readonly GUIContent k_XRTrackingText = new GUIContent("To set up tracking in your XR project, please follow the steps outlined using the link below."); - public static readonly GUIContent k_XRTrackingDocsText = new GUIContent("View XR Tracking Migration Guide"); - public static readonly Uri k_XRTrackingDocsUri = new Uri("https://docs.unity3d.com/Packages/com.unity.xr.legacyinputhelpers@latest"); + public static readonly GUIContent k_XRConfigurationText = new GUIContent("Information about configuration, tracking and migration can be found below."); + public static readonly GUIContent k_XRConfigurationDocUriText = new GUIContent("View Documentation"); + public static readonly Uri k_XRConfigurationUri = new Uri(" https://docs.unity3d.com/Manual/configuring-project-for-xr.html"); } @@ -272,18 +269,12 @@ private void DisplayLink(GUIContent text, Uri link, int leftMargin, int width) EditorGUI.DrawRect(new Rect(uriRect.x, uriRect.y + uriRect.height - 1, uriRect.width, 1), labelStyle.normal.textColor); } - private void DisplayDocumentationLink() - { - DisplayLink(Content.k_DocText, Content.k_DocUri, 5, 120); - EditorGUILayout.Space(); - } - private void DisplayXRTrackingDocumentationLink() { GUILayout.BeginVertical(EditorStyles.helpBox); { - EditorGUILayout.LabelField(Content.k_XRTrackingText, Styles.k_LabelWordWrap); - DisplayLink(Content.k_XRTrackingDocsText, Content.k_XRTrackingDocsUri, 2, 200); + EditorGUILayout.LabelField(Content.k_XRConfigurationText, Styles.k_LabelWordWrap); + DisplayLink(Content.k_XRConfigurationDocUriText, Content.k_XRConfigurationUri, 2, 200); } GUILayout.EndVertical(); EditorGUILayout.Space(); @@ -291,11 +282,6 @@ private void DisplayXRTrackingDocumentationLink() private void DisplayLoadOrderUi() { - GUILayout.BeginVertical(EditorStyles.helpBox); - { - EditorGUILayout.LabelField(Content.k_ExplanatoryText, Styles.k_LabelWordWrap); - } - GUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUI.BeginDisabledGroup(XRPackageMetadataStore.isDoingQueueProcessing || EditorApplication.isPlaying || EditorApplication.isPaused); @@ -319,7 +305,6 @@ public override void OnGUI(string searchContext) { EditorGUILayout.Space(); - DisplayDocumentationLink(); DisplayLoadOrderUi(); DisplayXRTrackingDocumentationLink(); diff --git a/Samples~/Unity.XR.Management.Samples.asmdef b/Samples~/Unity.XR.Management.Samples.asmdef index dae7db5..0e59b52 100644 --- a/Samples~/Unity.XR.Management.Samples.asmdef +++ b/Samples~/Unity.XR.Management.Samples.asmdef @@ -4,8 +4,7 @@ "Unity.XR.Management.Editor", "Unity.XR.Management" ], - "optionalUnityReferences": [ - ], + "optionalUnityReferences": [], "includePlatforms": [ "Editor" ], diff --git a/Tests.meta b/Tests.meta new file mode 100644 index 0000000..339bf02 --- /dev/null +++ b/Tests.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4fadb9d2c47be4b2587eec5da859310c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Editor.meta b/Tests/Editor.meta new file mode 100644 index 0000000..471c32c --- /dev/null +++ b/Tests/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3642aed4b4ade4a759cfa78a5a493012 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Editor/BuildTests.cs b/Tests/Editor/BuildTests.cs new file mode 100644 index 0000000..245eae1 --- /dev/null +++ b/Tests/Editor/BuildTests.cs @@ -0,0 +1,91 @@ +using System.Collections.Generic; +using NUnit.Framework; +using UnityEditor.Build; +using UnityEngine; +using UnityEngine.Rendering; +using UnityEngine.XR.Management; +using UnityEngine.XR.Management.Tests; +using Object = UnityEngine.Object; + +#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX + +namespace UnityEditor.XR.Management.Tests.BuildTests +{ +#if UNITY_EDITOR_WIN + [TestFixture(GraphicsDeviceType.Direct3D11, false, new [] { GraphicsDeviceType.Direct3D11})] + [TestFixture(GraphicsDeviceType.Direct3D11, false, new [] { GraphicsDeviceType.Direct3D12, GraphicsDeviceType.Direct3D11})] + [TestFixture(GraphicsDeviceType.Direct3D11, true, new [] { GraphicsDeviceType.Direct3D12, GraphicsDeviceType.Vulkan})] + [TestFixture(GraphicsDeviceType.Direct3D11, false, new [] { GraphicsDeviceType.Null, GraphicsDeviceType.Vulkan})] + [TestFixture(GraphicsDeviceType.Direct3D11, false, new [] { GraphicsDeviceType.Vulkan, GraphicsDeviceType.Null})] +#elif UNITY_EDITOR_OSX + [TestFixture(GraphicsDeviceType.Metal, false, new [] { GraphicsDeviceType.Metal})] + [TestFixture(GraphicsDeviceType.Metal, false, new [] { GraphicsDeviceType.Direct3D12, GraphicsDeviceType.Metal})] + [TestFixture(GraphicsDeviceType.Metal, true, new [] { GraphicsDeviceType.OpenGLES3, GraphicsDeviceType.Vulkan})] + [TestFixture(GraphicsDeviceType.Metal, false, new [] { GraphicsDeviceType.Null, GraphicsDeviceType.Vulkan})] + [TestFixture(GraphicsDeviceType.Metal, false, new [] { GraphicsDeviceType.Vulkan, GraphicsDeviceType.Null})] +#endif + class GraphicsAPICompatibilityTests + { + XRManagerSettings m_Manager; + List m_Loaders = new List(); + + private GraphicsDeviceType m_PlayerSettingsDeviceType; + private GraphicsDeviceType[] m_LoadersSupporteDeviceTypes; + bool m_BuildFails; + + public GraphicsAPICompatibilityTests(GraphicsDeviceType playerSettingsDeviceType, bool fails, GraphicsDeviceType[] loaders) + { + m_BuildFails = fails; + m_PlayerSettingsDeviceType = playerSettingsDeviceType; + m_LoadersSupporteDeviceTypes = loaders; + } + + [SetUp] + public void SetupPlayerSettings() + { +#if UNITY_EDITOR_WIN + PlayerSettings.SetGraphicsAPIs(BuildTarget.StandaloneWindows64, new[] { m_PlayerSettingsDeviceType }); +#elif UNITY_EDITOR_OSX + PlayerSettings.SetGraphicsAPIs(BuildTarget.StandaloneOSX, new[] { m_PlayerSettingsDeviceType }); +#endif + m_Manager = ScriptableObject.CreateInstance(); + m_Manager.automaticLoading = false; + + m_Loaders = new List(); + + for (int i = 0; i < m_LoadersSupporteDeviceTypes.Length; i++) + { + DummyLoader dl = ScriptableObject.CreateInstance(typeof(DummyLoader)) as DummyLoader; + dl.id = i; + dl.supportedDeviceType = m_LoadersSupporteDeviceTypes[i]; + m_Loaders.Add(dl); + m_Manager.loaders.Add(dl); + } + } + + [TearDown] + public void TeadDown() + { + Object.DestroyImmediate(m_Manager); + m_Manager = null; + + } + + [Test] + public void CheckGraphicsAPICompatibilityOnBuild() + { + try + { + XRGeneralBuildProcessor.VerifyGraphicsAPICompatibility(m_Manager, m_PlayerSettingsDeviceType); + } + catch (BuildFailedException) + { + Assert.True(m_BuildFails); + return; + } + + Assert.False(m_BuildFails); + } + } +} +#endif //UNITY_EDITOR_WIN || UNITY_EDITOR_OSX \ No newline at end of file diff --git a/Tests/Editor/BuildTests.cs.meta b/Tests/Editor/BuildTests.cs.meta new file mode 100644 index 0000000..faddaef --- /dev/null +++ b/Tests/Editor/BuildTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 199b1132f38d3f441aa719318365d5e9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Editor/EditorTests.cs b/Tests/Editor/EditorTests.cs new file mode 100644 index 0000000..0174bd0 --- /dev/null +++ b/Tests/Editor/EditorTests.cs @@ -0,0 +1,54 @@ +using NUnit.Framework; + +using System; +using System.IO; + +using UnityEngine; +using UnityEngine.XR.Management; + +using Unity.XR.TestTooling; + +namespace UnityEditor.XR.Management.Tests +{ + + class XRGeneralSettingsTests : ManagementTestSetup + { + protected override bool TestManagerUpgradePath => true; + BuildTargetGroup previousBuildTargetSelection { get; set; } + + [SetUp] + public override void SetupTest() + { + + base.SetupTest(); + + previousBuildTargetSelection = EditorUserBuildSettings.selectedBuildTargetGroup; + EditorUserBuildSettings.selectedBuildTargetGroup = BuildTargetGroup.Standalone; + } + + [TearDown] + public override void TearDownTest() + { + EditorUserBuildSettings.selectedBuildTargetGroup = previousBuildTargetSelection; + base.TearDownTest(); + } + + + [Test] + public void UpdateGeneralSettings_ToPerBuildTargetSettings() + { + bool success = XRGeneralSettingsUpgrade.UpgradeSettingsToPerBuildTarget(testPathToSettings); + Assert.IsTrue(success); + + XRGeneralSettingsPerBuildTarget pbtgs = null; + + pbtgs = AssetDatabase.LoadAssetAtPath(testPathToSettings, typeof(XRGeneralSettingsPerBuildTarget)) as XRGeneralSettingsPerBuildTarget; + Assert.IsNotNull(pbtgs); + + var settings = pbtgs.SettingsForBuildTarget(EditorUserBuildSettings.selectedBuildTargetGroup); + Assert.IsNotNull(settings); + Assert.IsNotNull(settings.Manager); + Assert.AreEqual(testManager, settings.Manager); + } + } +} diff --git a/Tests/Editor/EditorTests.cs.meta b/Tests/Editor/EditorTests.cs.meta new file mode 100644 index 0000000..ab2e918 --- /dev/null +++ b/Tests/Editor/EditorTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 731806369f8c24ec3bfee6ac9f820f6a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Editor/MetadataTests.cs b/Tests/Editor/MetadataTests.cs new file mode 100644 index 0000000..5cea188 --- /dev/null +++ b/Tests/Editor/MetadataTests.cs @@ -0,0 +1,104 @@ +using NUnit.Framework; + +using System; +using System.Collections; +using System.Linq; + +using UnityEngine.TestTools; +using UnityEditor.XR.Management.Metadata; + +using Unity.XR.Management.TestPackage; +using Unity.XR.Management.TestPackage.Editor; + +namespace UnityEditor.XR.Management.Tests +{ + class MetadataTests + { + [SetUp] + public void Setup() + { + AssetDatabase.DeleteAsset("Assets/XR"); + XRPackageInitializationBootstrap.BeginPackageInitialization(); + + TestPackage pkg = new TestPackage(); + XRPackageMetadataStore.AddPackage(pkg); + XRPackageInitializationBootstrap.InitPackage(pkg); + } + + [TearDown] + public void Teardown() + { + AssetDatabase.DeleteAsset("Assets/XR"); + } + + [UnityTest] + public IEnumerator CreateSettingsAndLoaders() + { + int frameCount = 0; + string[] assets = new string[0]{}; + + + while (frameCount < 60) + { + yield return null; + frameCount++; + } + + yield return null; + + string[] assetTypes = new string[]{"TestLoaderOne", "TestLoaderTwo", "TestLoaderThree","TestSettings"}; + foreach (var assetType in assetTypes) + { + assets = AssetDatabase.FindAssets($"t:{assetType}"); + Assert.IsTrue(assets.Length == 1); + } + } + + [Test, Sequential] + public void FilteringMetadataByBuildTargetGroup( + [Values(BuildTargetGroup.Standalone, BuildTargetGroup.Android, BuildTargetGroup.Unknown, BuildTargetGroup.WebGL)]BuildTargetGroup buildTargetGroup, + [Values("Test Loader One", "Test Loader Two", "Test Loader Three", "")]string expectedType) + { + var loaders = XRPackageMetadataStore.GetLoadersForBuildTarget(buildTargetGroup); + Assert.IsTrue((loaders.Count > 0 && !String.IsNullOrEmpty(expectedType)) || + (loaders.Count <= 0 && String.IsNullOrEmpty(expectedType))); + + if (!String.IsNullOrEmpty(expectedType)) + { + var loaderNames = from lm in loaders where String.Compare(lm.loaderName, expectedType, false) == 0 select lm.loaderName; + Assert.IsTrue(loaderNames.Any()); + Assert.IsTrue(loaderNames.Count() == 1); + } + } + + [UnityTest] + public IEnumerator AccessSettings() + { + int frameCount = 0; + string[] assets = new string[0] { }; + + TestPackage pkg = new TestPackage(); + XRPackageMetadataStore.AddPackage(pkg); + XRPackageInitializationBootstrap.InitPackage(pkg); + + while (frameCount < 60) + { + yield return null; + frameCount++; + } + + yield return null; + + var metadata = XRPackageMetadataStore.GetMetadataForPackage("com.unity.xr.testpackage"); + Assert.IsNotNull(metadata); + + assets = AssetDatabase.FindAssets($"t:{metadata.settingsType}"); + Assert.IsTrue(assets.Length == 1); + var assetPath = AssetDatabase.GUIDToAssetPath(assets[0]); + + var instance = AssetDatabase.LoadAssetAtPath(assetPath, typeof(TestSettings)); + Assert.IsNotNull(instance); + } + + } +} diff --git a/Tests/Editor/MetadataTests.cs.meta b/Tests/Editor/MetadataTests.cs.meta new file mode 100644 index 0000000..25a9c62 --- /dev/null +++ b/Tests/Editor/MetadataTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 67c6b20ab8216514ba5aedd7898dc1ac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Editor/PackageManagementTests.cs b/Tests/Editor/PackageManagementTests.cs new file mode 100644 index 0000000..1857985 --- /dev/null +++ b/Tests/Editor/PackageManagementTests.cs @@ -0,0 +1,175 @@ +using NUnit.Framework; + +using System; +using System.Collections; +using System.IO; +using System.Linq; + +using UnityEngine; +using UnityEngine.TestTools; +using UnityEngine.XR.Management; +using UnityEditor.XR.Management.Metadata; + +using Unity.XR.Management.TestPackage; +using Unity.XR.Management.TestPackage.Editor; + +namespace UnityEditor.XR.Management.Tests +{ + class PackageManagementTests + { + internal static readonly string[] s_TempSettingsPath = { "Temp", "Test" }; + + XRGeneralSettingsPerBuildTarget m_TestSettingsPerBuildTarget = null; + XRGeneralSettings m_TestSettings = null; + XRManagerSettings m_Settings = null; + + [SetUp] + public void SetUp() + { + AssetDatabase.DeleteAsset("Assets/XR"); + + AssetDatabase.CreateFolder("Assets", "XR"); + + m_Settings = ScriptableObject.CreateInstance() as XRManagerSettings; + m_Settings.name = "Actual testable settings."; + + m_TestSettings = ScriptableObject.CreateInstance() as XRGeneralSettings; + m_TestSettings.Manager = m_Settings; + m_TestSettings.name = "Standalone Settings Container."; + + m_TestSettingsPerBuildTarget = ScriptableObject.CreateInstance() as XRGeneralSettingsPerBuildTarget; + m_TestSettingsPerBuildTarget.SetSettingsForBuildTarget(BuildTargetGroup.Standalone, m_TestSettings); + + var testPath = XRGeneralSettingsTests.GetAssetPathForComponents(s_TempSettingsPath); + if (!string.IsNullOrEmpty(testPath)) + { + AssetDatabase.CreateAsset(m_TestSettingsPerBuildTarget, Path.Combine(testPath, "Test_XRGeneralSettings.asset")); + + AssetDatabase.AddObjectToAsset(m_TestSettings, AssetDatabase.GetAssetOrScenePath(m_TestSettingsPerBuildTarget)); + + AssetDatabase.CreateFolder(testPath, "Settings"); + testPath = Path.Combine(testPath, "Settings"); + AssetDatabase.CreateAsset(m_Settings, Path.Combine(testPath, "Test_XRSettingsManager.asset")); + + m_TestSettings.AssignedSettings = m_Settings; + AssetDatabase.SaveAssets(); + } + + EditorBuildSettings.AddConfigObject(XRGeneralSettings.k_SettingsKey, m_TestSettingsPerBuildTarget, true); + + XRPackageInitializationBootstrap.BeginPackageInitialization(); + + TestPackage pkg = new TestPackage(); + XRPackageMetadataStore.AddPackage(pkg); + XRPackageInitializationBootstrap.InitPackage(pkg); + + TestLoaderBase.WasAssigned = false; + TestLoaderBase.WasUnassigned = false; + } + + [TearDown] + public void Teardown() + { + AssetDatabase.DeleteAsset("Assets/Temp"); + AssetDatabase.DeleteAsset("Assets/XR"); + } + + private string LoaderTypeNameForBuildTarget(BuildTargetGroup buildTargetGroup) + { + var loaders = XRPackageMetadataStore.GetLoadersForBuildTarget(buildTargetGroup); + var filteredLoaders = from l in loaders where String.Compare(l.loaderType, typeof(TestLoaderOne).FullName) == 0 select l; + + if (filteredLoaders.Any()) + { + var loaderInfo = filteredLoaders.First(); + return loaderInfo.loaderType; + } + + return ""; + } + + private bool AssignLoaderToSettings(XRManagerSettings settings, string loaderTypeName, BuildTargetGroup buildTargetGroup = BuildTargetGroup.Standalone) + { + if (String.IsNullOrEmpty(loaderTypeName)) + return false; + + return XRPackageMetadataStore.AssignLoader(m_Settings, loaderTypeName, buildTargetGroup); + } + + private bool SettingsHasLoaderOfType(XRManagerSettings settings, string loaderTypeName) + { + bool wasFound = false; + foreach (var l in m_Settings.loaders) + { + if (String.Compare(l.GetType().FullName, loaderTypeName) == 0) + wasFound = true; + } + return wasFound; + } + + + [UnityTest] + public IEnumerator TestLoaderAssignment() + { + Assert.IsNotNull(m_Settings); + + string loaderTypeName = LoaderTypeNameForBuildTarget(BuildTargetGroup.Standalone); + Assert.IsFalse(String.IsNullOrEmpty(loaderTypeName)); + + bool wasFound = false; + foreach (var l in m_Settings.loaders) + { + if (String.Compare(l.GetType().FullName, loaderTypeName) == 0) + wasFound = true; + } + Assert.IsFalse(wasFound); + + Assert.IsTrue(XRPackageMetadataStore.AssignLoader(m_Settings, loaderTypeName, BuildTargetGroup.Standalone)); + + yield return null; + + Assert.IsTrue(SettingsHasLoaderOfType(m_Settings, loaderTypeName)); + Assert.IsTrue(TestLoaderBase.WasAssigned); + + } + + [Test] + public void TestLoaderAssignmentSerializes() + { + Assert.IsNotNull(m_Settings); + string loaderTypeName = LoaderTypeNameForBuildTarget(BuildTargetGroup.Standalone); + Assert.IsFalse(String.IsNullOrEmpty(loaderTypeName)); + AssignLoaderToSettings(m_Settings, loaderTypeName); + Assert.IsTrue(SettingsHasLoaderOfType(m_Settings, loaderTypeName)); + + m_Settings = null; + var settings = EditorUtilities.GetInstanceOfTypeFromAssetDatabase(); + m_Settings = settings as XRManagerSettings; + Assert.IsNotNull(m_Settings); + + Assert.IsTrue(SettingsHasLoaderOfType(m_Settings, loaderTypeName)); + Assert.IsTrue(TestLoaderBase.WasAssigned); + } + + + [Test] + public void TestLoaderRemoval() + { + Assert.IsNotNull(m_Settings); + string loaderTypeName = LoaderTypeNameForBuildTarget(BuildTargetGroup.Standalone); + Assert.IsFalse(String.IsNullOrEmpty(loaderTypeName)); + AssignLoaderToSettings(m_Settings, loaderTypeName); + Assert.IsTrue(SettingsHasLoaderOfType(m_Settings, loaderTypeName)); + + Assert.IsTrue(XRPackageMetadataStore.RemoveLoader(m_Settings, loaderTypeName, BuildTargetGroup.Standalone)); + + m_Settings = null; + var settings = EditorUtilities.GetInstanceOfTypeFromAssetDatabase(); + m_Settings = settings as XRManagerSettings; + Assert.IsNotNull(m_Settings); + Assert.IsFalse(SettingsHasLoaderOfType(m_Settings, loaderTypeName)); + + Assert.IsTrue(TestLoaderBase.WasUnassigned); + } + } +} diff --git a/Tests/Editor/PackageManagementTests.cs.meta b/Tests/Editor/PackageManagementTests.cs.meta new file mode 100644 index 0000000..3c5179e --- /dev/null +++ b/Tests/Editor/PackageManagementTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f054bb8325ac45040b14bf8bd85066f2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Editor/StandaloneSubsystemTests.cs b/Tests/Editor/StandaloneSubsystemTests.cs new file mode 100644 index 0000000..f454077 --- /dev/null +++ b/Tests/Editor/StandaloneSubsystemTests.cs @@ -0,0 +1,67 @@ +using System.Collections; + +using NUnit.Framework; + +using UnityEngine; +using UnityEngine.TestTools; + +using UnityEngine.XR.Management.Tests.Standalone; +using UnityEngine.XR.Management.Tests.Standalone.Providing; + +namespace UnityEditor.XR.Management.Tests +{ + 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() as StandaloneLoader; + } + + [TearDown] + public void TearDown() + { + UnityEngine.Object.DestroyImmediate(loader); + loader = null; + } + + [Test] + public void StandaloneLoaderCreateTest() + { + 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 StandaloneLoaderLifecycleTest() + { + 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; + + } + } +} diff --git a/Tests/Editor/StandaloneSubsystemTests.cs.meta b/Tests/Editor/StandaloneSubsystemTests.cs.meta new file mode 100644 index 0000000..e5a877e --- /dev/null +++ b/Tests/Editor/StandaloneSubsystemTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8227b7d99b019a14e9c7252c25cfcdc2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Editor/Unity.XR.Management.EditorTests.asmdef b/Tests/Editor/Unity.XR.Management.EditorTests.asmdef new file mode 100644 index 0000000..339217a --- /dev/null +++ b/Tests/Editor/Unity.XR.Management.EditorTests.asmdef @@ -0,0 +1,30 @@ +{ + "name": "Unity.XR.Management.EditorTests", + "references": [ + "Unity.XR.Management.Editor", + "Unity.XR.Management", + "Unity.XR.Management.Tests.Standalone", + "Unity.XR.Management.Tests", + "Unity.XR.Management.TestPackage", + "Unity.XR.Management.TestPackage.Editor", + "Unity.XR.TestSupport" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "nunit.framework.dll" + ], + "autoReferenced": false, + "optionalUnityReferences": [ + "TestAssemblies" + ], + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" + ], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Tests/Editor/Unity.XR.Management.EditorTests.asmdef.meta b/Tests/Editor/Unity.XR.Management.EditorTests.asmdef.meta new file mode 100644 index 0000000..46bb499 --- /dev/null +++ b/Tests/Editor/Unity.XR.Management.EditorTests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f46fc3751c3e84133af5527f7c1abae5 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Runtime.meta b/Tests/Runtime.meta new file mode 100644 index 0000000..2ff6e58 --- /dev/null +++ b/Tests/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 05bccdb13ab63410bb91245419b1b4e8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Runtime/DummyLoader.cs b/Tests/Runtime/DummyLoader.cs new file mode 100644 index 0000000..bab6c8d --- /dev/null +++ b/Tests/Runtime/DummyLoader.cs @@ -0,0 +1,61 @@ +using UnityEngine.Rendering; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Unity.XR.Management.EditorTests")] +namespace UnityEngine.XR.Management.Tests +{ + internal class DummyLoader : XRLoader + { + public bool shouldFail = false; + public int id; + public GraphicsDeviceType supportedDeviceType = GraphicsDeviceType.Null; + + public DummyLoader() + { + } + + public override bool Initialize() + { + return !shouldFail; + } + + public override T GetLoadedSubsystem() + { + return default(T); + } + + public override List GetSupportedGraphicsDeviceTypes(bool buildingPlayer) + { + if (supportedDeviceType == GraphicsDeviceType.Null) + { + return new List(); + } + return new List() { supportedDeviceType }; + } + + protected bool Equals(DummyLoader other) + { + return base.Equals(other) && shouldFail == other.shouldFail && id == other.id; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return Equals((DummyLoader)obj); + } + + public override int GetHashCode() + { + unchecked + { + int hashCode = base.GetHashCode(); + hashCode = (hashCode * 397) ^ shouldFail.GetHashCode(); + hashCode = (hashCode * 397) ^ id; + return hashCode; + } + } + } +} diff --git a/Tests/Runtime/DummyLoader.cs.meta b/Tests/Runtime/DummyLoader.cs.meta new file mode 100644 index 0000000..85ff08c --- /dev/null +++ b/Tests/Runtime/DummyLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 53934dfb266064225a96fe928fdcd3b3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Runtime/RuntimeLoaderTests.cs b/Tests/Runtime/RuntimeLoaderTests.cs new file mode 100644 index 0000000..22c01b8 --- /dev/null +++ b/Tests/Runtime/RuntimeLoaderTests.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections; +using System.Collections.Generic; + +using NUnit.Framework; + +using Unity.XR.TestTooling; +using UnityEngine.XR.Management.Tests.Standalone; +using UnityEngine.XR.Management.Tests.Standalone.Providing; + +namespace UnityEngine.XR.Management.Tests +{ + class RuntimeLoaderTests : LoaderTestSetup + { + protected override string settingsKey => "RuntimeTestSettings"; + + [OneTimeSetUp] + public void OneTimeSetUp() + { + StandaloneSubsystemParams parms = new StandaloneSubsystemParams("Standalone Subsystem", typeof(StandaloneSubsystem)); + StandaloneSubsystemDescriptor.Create(parms); + } + + [SetUp] + public override void SetupTest() + { + base.SetupTest(); + } + + [TearDown] + public override void TearDownTest() + { + base.TearDownTest(); + } + + [Test] + public void DoesItWork() + { + Assert.NotNull(loader); + Assert.NotNull(settings); + } + + [Test] + public void StartsAndStops() + { + Assert.IsNull(loader.standaloneSubsystem); + Assert.IsFalse(loader.started); + Assert.IsFalse(loader.stopped); + Assert.IsFalse(loader.deInitialized); + + InitializeAndStart(); + + Assert.IsNotNull(loader.standaloneSubsystem); + Assert.IsTrue(loader.started); + Assert.IsFalse(loader.stopped); + Assert.IsFalse(loader.deInitialized); + + StopAndShutdown(); + + Assert.IsTrue(loader.started); + Assert.IsTrue(loader.stopped); + Assert.IsTrue(loader.deInitialized); + } + } +} diff --git a/Tests/Runtime/RuntimeLoaderTests.cs.meta b/Tests/Runtime/RuntimeLoaderTests.cs.meta new file mode 100644 index 0000000..65b31fb --- /dev/null +++ b/Tests/Runtime/RuntimeLoaderTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f5020ebb9f8898c40a3b02af96a06b0a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Runtime/RuntimeTestSettings.cs b/Tests/Runtime/RuntimeTestSettings.cs new file mode 100644 index 0000000..bf7ff1e --- /dev/null +++ b/Tests/Runtime/RuntimeTestSettings.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace UnityEngine.XR.Management.Tests +{ + public class RuntimeTestSettings : ScriptableObject + { + + } +} diff --git a/Tests/Runtime/RuntimeTestSettings.cs.meta b/Tests/Runtime/RuntimeTestSettings.cs.meta new file mode 100644 index 0000000..527d4aa --- /dev/null +++ b/Tests/Runtime/RuntimeTestSettings.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 69dd6727f817cfd42a88eb2b632c436d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Runtime/RuntimeTests.cs b/Tests/Runtime/RuntimeTests.cs new file mode 100644 index 0000000..961d086 --- /dev/null +++ b/Tests/Runtime/RuntimeTests.cs @@ -0,0 +1,200 @@ +using System.Collections; +using System.Collections.Generic; +using NUnit.Framework; +using UnityEngine.TestTools; + +using UnityEditor; +using UnityEngine.Rendering; + +namespace UnityEngine.XR.Management.Tests +{ + [TestFixture(0, -1)] // No loaders, should never have any results + [TestFixture(1, -1)] // 1 loader, fails so no active loaders + [TestFixture(1, 0)] // All others, make sure the active loader is expected loader. + [TestFixture(2, 0)] + [TestFixture(2, 1)] + [TestFixture(3, 2)] + class ManualLifetimeTests + { + XRManagerSettings m_Manager; + List m_Loaders = new List(); + int m_LoaderCount; + int m_LoaderIndexToWin; + + public ManualLifetimeTests(int loaderCount, int loaderIndexToWin) + { + m_LoaderCount = loaderCount; + m_LoaderIndexToWin = loaderIndexToWin; + } + + [SetUp] + public void SetupXRManagerTest() + { + m_Manager = ScriptableObject.CreateInstance(); + m_Manager.automaticLoading = false; + + m_Loaders = new List(); + + for (int i = 0; i < m_LoaderCount; i++) + { + DummyLoader dl = ScriptableObject.CreateInstance(typeof(DummyLoader)) as DummyLoader; + dl.id = i; + dl.shouldFail = (i != m_LoaderIndexToWin); + m_Loaders.Add(dl); + m_Manager.loaders.Add(dl); + } + } + + [TearDown] + public void TeardownXRManagerTest() + { + Object.Destroy(m_Manager); + m_Manager = null; + } + + [UnityTest] + public IEnumerator CheckActivatedLoader() + { + Assert.IsNotNull(m_Manager); + + yield return m_Manager.InitializeLoader(); + + if (m_LoaderIndexToWin < 0 || m_LoaderIndexToWin >= m_Loaders.Count) + { + Assert.IsNull(m_Manager.activeLoader); + } + else + { + Assert.IsNotNull(m_Manager.activeLoader); + Assert.AreEqual(m_Loaders[m_LoaderIndexToWin], m_Manager.activeLoader); + } + + m_Manager.DeinitializeLoader(); + + Assert.IsNull(m_Manager.activeLoader); + + m_Manager.loaders.Clear(); + } + } + +#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX + +#if UNITY_EDITOR_WIN + [TestFixture(GraphicsDeviceType.Direct3D11, 0, new [] { GraphicsDeviceType.Direct3D11})] + [TestFixture(GraphicsDeviceType.Direct3D11, 1, new [] { GraphicsDeviceType.Direct3D12, GraphicsDeviceType.Direct3D11})] + [TestFixture(GraphicsDeviceType.Direct3D11, -1, new [] { GraphicsDeviceType.Direct3D12, GraphicsDeviceType.Vulkan})] + [TestFixture(GraphicsDeviceType.Direct3D11, 0, new [] { GraphicsDeviceType.Null, GraphicsDeviceType.Vulkan})] + [TestFixture(GraphicsDeviceType.Direct3D11, 1, new [] { GraphicsDeviceType.Vulkan, GraphicsDeviceType.Null})] +#elif UNITY_EDITOR_OSX + [TestFixture(GraphicsDeviceType.Metal, 0, new [] { GraphicsDeviceType.Metal})] + [TestFixture(GraphicsDeviceType.Metal, 1, new [] { GraphicsDeviceType.Direct3D12, GraphicsDeviceType.Metal})] + [TestFixture(GraphicsDeviceType.Metal, -1, new [] { GraphicsDeviceType.OpenGLES3, GraphicsDeviceType.Vulkan})] + [TestFixture(GraphicsDeviceType.Metal, 0, new [] { GraphicsDeviceType.Null, GraphicsDeviceType.Vulkan})] + [TestFixture(GraphicsDeviceType.Metal, 1, new [] { GraphicsDeviceType.Vulkan, GraphicsDeviceType.Null})] +#endif + class GraphicsAPICompatibilityTests + { + XRManagerSettings m_Manager; + List m_Loaders = new List(); + + private GraphicsDeviceType m_PlayerSettingsDeviceType; + private GraphicsDeviceType[] m_LoadersSupporteDeviceTypes; + int m_LoaderIndexToWin; + public GraphicsAPICompatibilityTests(GraphicsDeviceType playerSettingsDeviceType, int indexToWin, GraphicsDeviceType[] loaders) + { + m_LoaderIndexToWin = indexToWin; + m_PlayerSettingsDeviceType = playerSettingsDeviceType; + m_LoadersSupporteDeviceTypes = loaders; + } + + [SetUp] + public void SetupPlayerSettings() + { + GraphicsDeviceType[] deviceTypes = PlayerSettings.GetGraphicsAPIs(BuildTarget.StandaloneOSX); + var oldGfxType = m_PlayerSettingsDeviceType; + + // If the type we want to check isn't the supported graphics type, then substitute it out + // so we can still pass the tests. Semantics are the same regardless of actual devices. + if (SystemInfo.graphicsDeviceType != m_PlayerSettingsDeviceType) + { + m_PlayerSettingsDeviceType = SystemInfo.graphicsDeviceType; + + for (int i = 0; i < m_LoadersSupporteDeviceTypes.Length; i++) + { + if (oldGfxType == m_LoadersSupporteDeviceTypes[i]) + { + m_LoadersSupporteDeviceTypes[i] = m_PlayerSettingsDeviceType; + } + } + } + +#if UNITY_EDITOR_WIN + PlayerSettings.SetGraphicsAPIs(BuildTarget.StandaloneWindows64, new[] { m_PlayerSettingsDeviceType }); +#elif UNITY_EDITOR_OSX + PlayerSettings.SetGraphicsAPIs(BuildTarget.StandaloneOSX, new[] { m_PlayerSettingsDeviceType }); +#endif + + m_Manager = ScriptableObject.CreateInstance(); + m_Manager.automaticLoading = false; + + m_Loaders = new List(); + + for (int i = 0; i < m_LoadersSupporteDeviceTypes.Length; i++) + { + DummyLoader dl = ScriptableObject.CreateInstance(typeof(DummyLoader)) as DummyLoader; + dl.id = i; + dl.supportedDeviceType = m_LoadersSupporteDeviceTypes[i]; + dl.shouldFail = (i != m_LoaderIndexToWin); + m_Loaders.Add(dl); + m_Manager.loaders.Add(dl); + } + } + + [TearDown] + public void TeadDown() + { + Object.Destroy(m_Manager); + m_Manager = null; + } + + [Test] + public void CheckGraphicsAPICompatibilitySync() + { + m_Manager.InitializeLoaderSync(); + + if (m_LoaderIndexToWin < 0 || m_LoaderIndexToWin >= m_Loaders.Count) + { + Assert.IsNull(m_Manager.activeLoader); + } + else + { + Assert.IsNotNull(m_Manager.activeLoader); + Assert.AreEqual(m_Loaders[m_LoaderIndexToWin], m_Manager.activeLoader); + m_Manager.DeinitializeLoader(); + } + + m_Manager.loaders.Clear(); + } + + [UnityTest] + public IEnumerator CheckGraphicsAPICompatibility() + { + yield return m_Manager.InitializeLoader(); + + if (m_LoaderIndexToWin < 0 || m_LoaderIndexToWin >= m_Loaders.Count) + { + Assert.IsNull(m_Manager.activeLoader); + } + else + { + Assert.IsNotNull(m_Manager.activeLoader); + Assert.AreEqual(m_Loaders[m_LoaderIndexToWin], m_Manager.activeLoader); + m_Manager.DeinitializeLoader(); + } + + m_Manager.loaders.Clear(); + } + } +#endif // UNITY_EDITOR_WIN || UNITY_EDITOR_OSX + +} diff --git a/Tests/Runtime/RuntimeTests.cs.meta b/Tests/Runtime/RuntimeTests.cs.meta new file mode 100644 index 0000000..14add29 --- /dev/null +++ b/Tests/Runtime/RuntimeTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4125b72fb8d964ddd9e2d704725a7cbc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/Runtime/Unity.XR.Management.Tests.asmdef b/Tests/Runtime/Unity.XR.Management.Tests.asmdef new file mode 100644 index 0000000..17dfa91 --- /dev/null +++ b/Tests/Runtime/Unity.XR.Management.Tests.asmdef @@ -0,0 +1,16 @@ +{ + "name": "Unity.XR.Management.Tests", + "references": [ + "Unity.XR.Management", + "Unity.XR.Management.Tests.Standalone", + "Unity.XR.TestSupport" + ], + "optionalUnityReferences": [ + "TestAssemblies" + ], + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" + ], + "includePlatforms": [], + "excludePlatforms": [] +} diff --git a/Tests/Runtime/Unity.XR.Management.Tests.asmdef.meta b/Tests/Runtime/Unity.XR.Management.Tests.asmdef.meta new file mode 100644 index 0000000..666aa6f --- /dev/null +++ b/Tests/Runtime/Unity.XR.Management.Tests.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0a731f4d44d04439bb291bdbaa8cb9fc +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/StandaloneSubsystem.meta b/Tests/StandaloneSubsystem.meta new file mode 100644 index 0000000..cf1dd31 --- /dev/null +++ b/Tests/StandaloneSubsystem.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7c10d3b41bac78a469f53bbd88046bdb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/StandaloneSubsystem/StandaloneLoader.cs b/Tests/StandaloneSubsystem/StandaloneLoader.cs new file mode 100644 index 0000000..f4e0dee --- /dev/null +++ b/Tests/StandaloneSubsystem/StandaloneLoader.cs @@ -0,0 +1,79 @@ +using System.Collections.Generic; + +namespace UnityEngine.XR.Management.Tests.Standalone +{ + public class StandaloneLoader : XRLoaderHelper + { + static List s_StandaloneSubsystemDescriptors = new List(); + + public StandaloneSubsystem standaloneSubsystem + { + get + { + return GetLoadedSubsystem(); + } + } + + public bool started { get; protected set; } + public bool stopped { get; protected set; } + public bool deInitialized { get; protected set; } + + void OnStartCalled() + { + started = true; + } + + void OnStopCalled() + { + stopped = true; + } + + void OnDestroyCalled() + { + deInitialized = true; + } + + public override bool Initialize() + { + started = false; + stopped = false; + deInitialized = false; + + CreateSubsystem(s_StandaloneSubsystemDescriptors, "Standalone Subsystem"); + if (standaloneSubsystem == null) + return false; + + standaloneSubsystem.startCalled += OnStartCalled; + standaloneSubsystem.stopCalled += OnStopCalled; + standaloneSubsystem.destroyCalled += OnDestroyCalled; + return true; + } + + public override bool Start() + { + if (standaloneSubsystem != null) + StartSubsystem(); + return true; + } + + public override bool Stop() + { + if (standaloneSubsystem != null) + StopSubsystem(); + return true; + } + + public override bool Deinitialize() + { + DestroySubsystem(); + if (standaloneSubsystem != null) + { + standaloneSubsystem.startCalled -= OnStartCalled; + standaloneSubsystem.stopCalled -= OnStopCalled; + standaloneSubsystem.destroyCalled -= OnDestroyCalled; + } + return true; + } + + } +} diff --git a/Tests/StandaloneSubsystem/StandaloneLoader.cs.meta b/Tests/StandaloneSubsystem/StandaloneLoader.cs.meta new file mode 100644 index 0000000..23fe903 --- /dev/null +++ b/Tests/StandaloneSubsystem/StandaloneLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 98f5e129a3cd69847bae7685c22fd39b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/StandaloneSubsystem/StandaloneSubsystem.cs b/Tests/StandaloneSubsystem/StandaloneSubsystem.cs new file mode 100644 index 0000000..19804f0 --- /dev/null +++ b/Tests/StandaloneSubsystem/StandaloneSubsystem.cs @@ -0,0 +1,42 @@ +using System; + +namespace UnityEngine.XR.Management.Tests.Standalone +{ + public class StandaloneSubsystem : Subsystem + { + private bool isRunning = false; + public override bool running + { + get + { + return isRunning; + } + } + + public event Action startCalled; + public event Action stopCalled; + public event Action destroyCalled; + + + public override void Start() + { + isRunning = true; + if (startCalled != null) + startCalled.Invoke(); + } + + public override void Stop() + { + isRunning = false; + if (stopCalled != null) + stopCalled.Invoke(); + } + + protected override void OnDestroy() + { + isRunning = false; + if (destroyCalled != null) + destroyCalled.Invoke(); + } + } +} diff --git a/Tests/StandaloneSubsystem/StandaloneSubsystem.cs.meta b/Tests/StandaloneSubsystem/StandaloneSubsystem.cs.meta new file mode 100644 index 0000000..b67be60 --- /dev/null +++ b/Tests/StandaloneSubsystem/StandaloneSubsystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 24f65cd604fa73e4e9dbaa12d1b335e9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/StandaloneSubsystem/StandaloneSubsystemDescriptor.cs b/Tests/StandaloneSubsystem/StandaloneSubsystemDescriptor.cs new file mode 100644 index 0000000..8764c55 --- /dev/null +++ b/Tests/StandaloneSubsystem/StandaloneSubsystemDescriptor.cs @@ -0,0 +1,32 @@ + +namespace UnityEngine.XR.Management.Tests.Standalone +{ + namespace Providing + { + public class StandaloneSubsystemParams + { + public string id { get; set;} + public System.Type subsystemImplementationType { get; set; } + + public StandaloneSubsystemParams(string id, System.Type subsystemImplType) + { + this.id = id; + this.subsystemImplementationType = subsystemImplType; + } + } + } + + public class StandaloneSubsystemDescriptor : SubsystemDescriptor + { + public static void Create(Providing.StandaloneSubsystemParams parms) + { + SubsystemRegistration.CreateDescriptor(new StandaloneSubsystemDescriptor(parms.id, parms.subsystemImplementationType)); + } + + public StandaloneSubsystemDescriptor(string id, System.Type subsystemImplType) + { + this.id = id; + this.subsystemImplementationType = subsystemImplType; + } + } +} diff --git a/Tests/StandaloneSubsystem/StandaloneSubsystemDescriptor.cs.meta b/Tests/StandaloneSubsystem/StandaloneSubsystemDescriptor.cs.meta new file mode 100644 index 0000000..f989eb2 --- /dev/null +++ b/Tests/StandaloneSubsystem/StandaloneSubsystemDescriptor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 013b7dbbc8ec54c4182940c05c060ee9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/StandaloneSubsystem/Unity.XR.Management.Tests.Standalone.asmdef b/Tests/StandaloneSubsystem/Unity.XR.Management.Tests.Standalone.asmdef new file mode 100644 index 0000000..0cedadd --- /dev/null +++ b/Tests/StandaloneSubsystem/Unity.XR.Management.Tests.Standalone.asmdef @@ -0,0 +1,15 @@ +{ + "name": "Unity.XR.Management.Tests.Standalone", + "references": [ + "Unity.Subsystem.Registration", + "Unity.XR.Management" + ], + "optionalUnityReferences": [ + "TestAssemblies" + ], + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" + ], + "includePlatforms": [], + "excludePlatforms": [] +} diff --git a/Tests/StandaloneSubsystem/Unity.XR.Management.Tests.Standalone.asmdef.meta b/Tests/StandaloneSubsystem/Unity.XR.Management.Tests.Standalone.asmdef.meta new file mode 100644 index 0000000..6dffa51 --- /dev/null +++ b/Tests/StandaloneSubsystem/Unity.XR.Management.Tests.Standalone.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 575f7633d101095488b014272f40d6f7 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage.meta b/Tests/TestPackage.meta new file mode 100644 index 0000000..d40aa81 --- /dev/null +++ b/Tests/TestPackage.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3ff8e099033239542a4d9e3d3b4d21ab +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Editor.meta b/Tests/TestPackage/Editor.meta new file mode 100644 index 0000000..8bb2b11 --- /dev/null +++ b/Tests/TestPackage/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 730faf1c9a6ee8845a923cd20b8c4521 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Editor/TestPackage.cs b/Tests/TestPackage/Editor/TestPackage.cs new file mode 100644 index 0000000..16655c9 --- /dev/null +++ b/Tests/TestPackage/Editor/TestPackage.cs @@ -0,0 +1,34 @@ +using System.Runtime.CompilerServices; + +using UnityEngine; + +using UnityEditor.XR.Management.Metadata; + +[assembly:InternalsVisibleTo("Unity.XR.Management.EditorTests")] +[assembly:InternalsVisibleTo("Unity.XR.Management.Tests.Standalone")] +namespace Unity.XR.Management.TestPackage.Editor +{ + internal class TestPackage : IXRPackage + { + public TestPackage() {} + + public IXRPackageMetadata metadata + { + get + { + return TestMetadata.CreateAndGetMetadata(); + } + } + + public bool PopulateNewSettingsInstance(ScriptableObject obj) + { + TestSettings packageSettings = obj as TestSettings; + if (packageSettings != null) + { + return true; + } + return false; + } + + } +} diff --git a/Tests/TestPackage/Editor/TestPackage.cs.meta b/Tests/TestPackage/Editor/TestPackage.cs.meta new file mode 100644 index 0000000..09847ba --- /dev/null +++ b/Tests/TestPackage/Editor/TestPackage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ab121e37ba25f5549b3f70723f0587a2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Editor/TestPackageMetadata.cs b/Tests/TestPackage/Editor/TestPackageMetadata.cs new file mode 100644 index 0000000..a68823a --- /dev/null +++ b/Tests/TestPackage/Editor/TestPackageMetadata.cs @@ -0,0 +1,69 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +using UnityEditor; +using UnityEditor.XR.Management.Metadata; + +[assembly:InternalsVisibleTo("UnityEditor.XR.Management.Tests")] +namespace Unity.XR.Management.TestPackage.Editor +{ + class TestLoaderMetadata : IXRLoaderMetadata + { + public string loaderName { get; set; } + public string loaderType { get; set; } + public List supportedBuildTargets { get; set; } + } + + class TestPackageMetadata : IXRPackageMetadata + { + public string packageName { get; set; } + public string packageId { get; set; } + public string settingsType { get; set; } + public List loaderMetadata { get; set; } + } + + static class TestMetadata + { + static TestPackageMetadata s_Metadata = null; + + internal static TestPackageMetadata CreateAndGetMetadata() + { + if (s_Metadata == null) + { + s_Metadata = new TestPackageMetadata(); + s_Metadata.packageName = "Test Package"; + s_Metadata.packageId = "com.unity.xr.testpackage"; + s_Metadata.settingsType = typeof(TestSettings).FullName; + + s_Metadata.loaderMetadata = new List() { + new TestLoaderMetadata() { + loaderName = "Test Loader One", + loaderType = typeof(TestLoaderOne).FullName, + supportedBuildTargets = new List() { + BuildTargetGroup.Standalone, + BuildTargetGroup.WSA + } + }, + new TestLoaderMetadata() { + loaderName = "Test Loader Two", + loaderType = typeof(TestLoaderTwo).FullName, + supportedBuildTargets = new List() { + BuildTargetGroup.Android, + BuildTargetGroup.iOS, + BuildTargetGroup.Lumin + } + }, + new TestLoaderMetadata() { + loaderName = "Test Loader Three", + loaderType = typeof(TestLoaderThree).FullName, + supportedBuildTargets = new List() { + BuildTargetGroup.Unknown + } + }, + }; + } + + return s_Metadata; + } + } +} diff --git a/Tests/TestPackage/Editor/TestPackageMetadata.cs.meta b/Tests/TestPackage/Editor/TestPackageMetadata.cs.meta new file mode 100644 index 0000000..9e023b7 --- /dev/null +++ b/Tests/TestPackage/Editor/TestPackageMetadata.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 38ca4053ebf8da44daa4736081117489 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Editor/TestSettingsEditor.cs b/Tests/TestPackage/Editor/TestSettingsEditor.cs new file mode 100644 index 0000000..eb79743 --- /dev/null +++ b/Tests/TestPackage/Editor/TestSettingsEditor.cs @@ -0,0 +1,13 @@ +using UnityEditor; + +namespace Unity.XR.Management.TestPackage.Editor +{ + [CustomEditor(typeof(TestSettings))] + public class TestSettingsEditor : UnityEditor.Editor + { + public override void OnInspectorGUI() + { + EditorGUILayout.LabelField("Test only..."); + } + } +} diff --git a/Tests/TestPackage/Editor/TestSettingsEditor.cs.meta b/Tests/TestPackage/Editor/TestSettingsEditor.cs.meta new file mode 100644 index 0000000..fe8e85d --- /dev/null +++ b/Tests/TestPackage/Editor/TestSettingsEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 42e3aee306e61d04e86b1f31768ef309 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Editor/Uniyt.XR.Management.TestPackage.Editor.asmdef b/Tests/TestPackage/Editor/Uniyt.XR.Management.TestPackage.Editor.asmdef new file mode 100644 index 0000000..87b33ac --- /dev/null +++ b/Tests/TestPackage/Editor/Uniyt.XR.Management.TestPackage.Editor.asmdef @@ -0,0 +1,18 @@ +{ + "name": "Unity.XR.Management.TestPackage.Editor", + "references": [ + "Unity.XR.Management.Editor", + "Unity.XR.Management", + "Unity.XR.Management.TestPackage" + ], + "optionalUnityReferences": [ + "TestAssemblies" + ], + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [] +} diff --git a/Tests/TestPackage/Editor/Uniyt.XR.Management.TestPackage.Editor.asmdef.meta b/Tests/TestPackage/Editor/Uniyt.XR.Management.TestPackage.Editor.asmdef.meta new file mode 100644 index 0000000..fdbfbb9 --- /dev/null +++ b/Tests/TestPackage/Editor/Uniyt.XR.Management.TestPackage.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c536cb714a8a9e84cb16ecf0330eea40 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Runtime.meta b/Tests/TestPackage/Runtime.meta new file mode 100644 index 0000000..51cf21d --- /dev/null +++ b/Tests/TestPackage/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3103627535e89f24bba53cdf46fd3c03 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Runtime/Constants.cs b/Tests/TestPackage/Runtime/Constants.cs new file mode 100644 index 0000000..ff4857d --- /dev/null +++ b/Tests/TestPackage/Runtime/Constants.cs @@ -0,0 +1,9 @@ +using System; + +namespace Unity.XR.Management.TestPackage +{ + public struct Constants + { + public const string k_SettingsKey = "TestPackageSettings"; + } +} \ No newline at end of file diff --git a/Tests/TestPackage/Runtime/Constants.cs.meta b/Tests/TestPackage/Runtime/Constants.cs.meta new file mode 100644 index 0000000..2a090d7 --- /dev/null +++ b/Tests/TestPackage/Runtime/Constants.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 15419879c32f35149b150d58e2d47a6f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Runtime/TestLoaderBase.cs b/Tests/TestPackage/Runtime/TestLoaderBase.cs new file mode 100644 index 0000000..cf834a6 --- /dev/null +++ b/Tests/TestPackage/Runtime/TestLoaderBase.cs @@ -0,0 +1,101 @@ +using System.Collections.Generic; + +using UnityEngine.XR.Management; + +#if UNITY_EDITOR +using UnityEditor; +using UnityEditor.XR.Management; +#endif + +using UnityEngine.XR.Management.Tests.Standalone; + +namespace Unity.XR.Management.TestPackage +{ + public class TestLoaderBase : XRLoaderHelper + { +#if UNITY_EDITOR + public TestLoaderBase() + { + WasAssigned = false; + WasUnassigned = false; + } + + public static bool WasAssigned { get; set; } + public static bool WasUnassigned { get; set; } +#endif + static List s_StandaloneSubsystemDescriptors = + new List(); + + public StandaloneSubsystem inputSubsystem + { + get { return GetLoadedSubsystem(); } + } + + TestSettings GetSettings() + { + TestSettings 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(Constants.k_SettingsKey, out settings); +#else + settings = TestSettings.s_RuntimeInstance; +#endif + return settings; + } + +#region XRLoader API Implementation + + /// Implementaion of + /// True if successful, false otherwise + public override bool Initialize() + { + TestSettings settings = GetSettings(); + if (settings != null) + { + // TODO: Pass settings off to plugin prior to subsystem init. + } + + CreateSubsystem(s_StandaloneSubsystemDescriptors, "Standalone Subsystem"); + + 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 true; + } + +#if UNITY_EDITOR + public override void WasAssignedToBuildTarget(BuildTargetGroup buildTargetGroup) + { + WasAssigned = true; + } + + public override void WasUnassignedFromBuildTarget(BuildTargetGroup buildTargetGroup) + { + WasUnassigned = true; + } +#endif +#endregion + } +} diff --git a/Tests/TestPackage/Runtime/TestLoaderBase.cs.meta b/Tests/TestPackage/Runtime/TestLoaderBase.cs.meta new file mode 100644 index 0000000..e9d4500 --- /dev/null +++ b/Tests/TestPackage/Runtime/TestLoaderBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dda6a4ae198ab2643bd0c72cb8b3f51c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Runtime/TestLoaderOne.cs b/Tests/TestPackage/Runtime/TestLoaderOne.cs new file mode 100644 index 0000000..081e186 --- /dev/null +++ b/Tests/TestPackage/Runtime/TestLoaderOne.cs @@ -0,0 +1,8 @@ + +namespace Unity.XR.Management.TestPackage +{ + public class TestLoaderOne : TestLoaderBase + { + + } +} diff --git a/Tests/TestPackage/Runtime/TestLoaderOne.cs.meta b/Tests/TestPackage/Runtime/TestLoaderOne.cs.meta new file mode 100644 index 0000000..7da7d5d --- /dev/null +++ b/Tests/TestPackage/Runtime/TestLoaderOne.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9827676ef5f18a44e878c6754e9ea67a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Runtime/TestLoaderThree.cs b/Tests/TestPackage/Runtime/TestLoaderThree.cs new file mode 100644 index 0000000..a22aa39 --- /dev/null +++ b/Tests/TestPackage/Runtime/TestLoaderThree.cs @@ -0,0 +1,8 @@ + +namespace Unity.XR.Management.TestPackage +{ + public class TestLoaderThree : TestLoaderBase + { + + } +} diff --git a/Tests/TestPackage/Runtime/TestLoaderThree.cs.meta b/Tests/TestPackage/Runtime/TestLoaderThree.cs.meta new file mode 100644 index 0000000..1f37436 --- /dev/null +++ b/Tests/TestPackage/Runtime/TestLoaderThree.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7cbb6fca93034d44a8826718d09db887 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Runtime/TestLoaderTwo.cs b/Tests/TestPackage/Runtime/TestLoaderTwo.cs new file mode 100644 index 0000000..3865cd4 --- /dev/null +++ b/Tests/TestPackage/Runtime/TestLoaderTwo.cs @@ -0,0 +1,8 @@ + +namespace Unity.XR.Management.TestPackage +{ + public class TestLoaderTwo : TestLoaderBase + { + + } +} diff --git a/Tests/TestPackage/Runtime/TestLoaderTwo.cs.meta b/Tests/TestPackage/Runtime/TestLoaderTwo.cs.meta new file mode 100644 index 0000000..fc3d2de --- /dev/null +++ b/Tests/TestPackage/Runtime/TestLoaderTwo.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 80ce73850af91a64db881df56edfb826 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Runtime/TestSettings.cs b/Tests/TestPackage/Runtime/TestSettings.cs new file mode 100644 index 0000000..fa359e5 --- /dev/null +++ b/Tests/TestPackage/Runtime/TestSettings.cs @@ -0,0 +1,19 @@ +using UnityEngine; +using UnityEngine.XR.Management; + +namespace Unity.XR.Management.TestPackage +{ + [XRConfigurationData("Test Settings", Constants.k_SettingsKey)] + public class TestSettings : ScriptableObject + { + +#if !UNITY_EDITOR + internal static TestSettings s_Settings; + + public void Awake() + { + s_Settings = this; + } +#endif + } +} diff --git a/Tests/TestPackage/Runtime/TestSettings.cs.meta b/Tests/TestPackage/Runtime/TestSettings.cs.meta new file mode 100644 index 0000000..6ced0db --- /dev/null +++ b/Tests/TestPackage/Runtime/TestSettings.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bdda55d4c239b3f438a25afea4860171 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestPackage/Runtime/Uniyt.XR.Management.TestPackage.asmdef b/Tests/TestPackage/Runtime/Uniyt.XR.Management.TestPackage.asmdef new file mode 100644 index 0000000..33cd2c0 --- /dev/null +++ b/Tests/TestPackage/Runtime/Uniyt.XR.Management.TestPackage.asmdef @@ -0,0 +1,28 @@ +{ + "name": "Unity.XR.Management.TestPackage", + "references": [ + "Unity.Subsystem.Registration", + "Unity.XR.Management", + "Unity.XR.Management.Editor", + "Unity.XR.Management.Tests.Standalone" + ], + "includePlatforms": [ + "Editor", + "WindowsStandalone64" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": true, + "precompiledReferences": [ + "nunit.framework.dll" + ], + "autoReferenced": false, + "optionalUnityReferences": [ + "TestAssemblies" + ], + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" + ], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Tests/TestPackage/Runtime/Uniyt.XR.Management.TestPackage.asmdef.meta b/Tests/TestPackage/Runtime/Uniyt.XR.Management.TestPackage.asmdef.meta new file mode 100644 index 0000000..fb852cf --- /dev/null +++ b/Tests/TestPackage/Runtime/Uniyt.XR.Management.TestPackage.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 9b8b61ec9cb92d1439beb03814dc2cb0 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestTooling.meta b/Tests/TestTooling.meta new file mode 100644 index 0000000..61c060e --- /dev/null +++ b/Tests/TestTooling.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a6b025db892bd1c45836749411bbb6f2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestTooling/LoaderTestSetup.cs b/Tests/TestTooling/LoaderTestSetup.cs new file mode 100644 index 0000000..560b982 --- /dev/null +++ b/Tests/TestTooling/LoaderTestSetup.cs @@ -0,0 +1,96 @@ +using System.IO; + +using NUnit.Framework; + +using UnityEditor; + +using UnityEngine; +using UnityEngine.TestTools; +using UnityEngine.XR; +using UnityEngine.XR.Management; + + +namespace Unity.XR.TestTooling +{ + public abstract class LoaderTestSetup : ManagementTestSetup, IPrebuildSetup, IPostBuildCleanup + where L : XRLoader + where S : ScriptableObject + { + protected abstract string settingsKey { get; } + + protected L loader = null; + protected S settings = null; + private bool isRunning = false; + + public override void SetupTest() + { + base.SetupTest(); + + Assert.IsNotNull(xrGeneralSettings); + + // Deleted by ManagementSetup - deletes whole Temp folder + + // Setup Loader + loader = ScriptableObject.CreateInstance(); + var path = GetAssetPathForComponents(s_TempSettingsPath); + AssetDatabase.CreateAsset(loader, Path.Combine(path, $"Test_{typeof(L).Name}.asset")); + xrGeneralSettings.Manager.loaders.Add(loader); + + // Setup Settings + settings = ScriptableObject.CreateInstance(); + AssetDatabase.CreateAsset(settings, Path.Combine(path, $"Test_{typeof(S).Name}.asset")); + EditorBuildSettings.AddConfigObject(settingsKey, settings, true); + + AssetDatabase.SaveAssets(); + } + + public override void TearDownTest() + { + if (isRunning) + StopAndShutdown(); + xrGeneralSettings.Manager.loaders.Remove(loader); + loader = null; + + base.TearDownTest(); + } + + protected void InitializeAndStart() + { + if (loader != null) + { + if (loader.Initialize()) + isRunning = loader.Start(); + } + } + + protected void StopAndShutdown() + { + if (loader != null) + { + loader.Stop(); + loader.Deinitialize(); + isRunning = false; + } + } + + protected void RestartProvider() + { + StopAndShutdown(); + InitializeAndStart(); + } + + // IPrebuildSetup - Build time setup + void IPrebuildSetup.Setup() + { + if (XRGeneralSettings.Instance != null) + XRGeneralSettings.Instance.InitManagerOnStart = false; + } + + // IPostBuildCleanup - Build time cleanup + void IPostBuildCleanup.Cleanup() + { + if (XRGeneralSettings.Instance != null) + XRGeneralSettings.Instance.InitManagerOnStart = true; + } + } +} diff --git a/Tests/TestTooling/LoaderTestSetup.cs.meta b/Tests/TestTooling/LoaderTestSetup.cs.meta new file mode 100644 index 0000000..fe6070b --- /dev/null +++ b/Tests/TestTooling/LoaderTestSetup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 57a021d9ff05c6f4588567ea353dee33 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestTooling/ManagementTestSetup.cs b/Tests/TestTooling/ManagementTestSetup.cs new file mode 100644 index 0000000..750dfaf --- /dev/null +++ b/Tests/TestTooling/ManagementTestSetup.cs @@ -0,0 +1,129 @@ +using System; +using System.IO; + +using UnityEditor; +using UnityEditor.XR.Management; + +using UnityEngine; +using UnityEngine.XR.Management; + +namespace Unity.XR.TestTooling +{ + // Mostly borrowed from XRManagement - this should probably live in that package. + public abstract class ManagementTestSetup + { + protected static readonly string[] s_TestGeneralSettings = { "Temp", "Test" }; + protected static readonly string[] s_TempSettingsPath = {"Temp", "Test", "Settings" }; + + /// + /// When true, AssetDatabase.AddObjectToAsset will not be called to add XRManagerSettings to XRGeneralSettings. + /// + protected virtual bool TestManagerUpgradePath => false; + + protected string testPathToGeneralSettings; + protected string testPathToSettings; + + private UnityEngine.Object currentSettings = null; + + protected XRManagerSettings testManager = null; + protected XRGeneralSettings xrGeneralSettings = null; + protected XRGeneralSettingsPerBuildTarget buildTargetSettings = null; + + public virtual void SetupTest() + { + testManager = ScriptableObject.CreateInstance(); + + xrGeneralSettings = ScriptableObject.CreateInstance() as XRGeneralSettings; + xrGeneralSettings.Manager = testManager; + + + testPathToSettings = GetAssetPathForComponents(s_TempSettingsPath); + testPathToSettings = Path.Combine(testPathToSettings, "Test_XRGeneralSettings.asset"); + if (!string.IsNullOrEmpty(testPathToSettings)) + { + AssetDatabase.CreateAsset(xrGeneralSettings, testPathToSettings); + + if (!TestManagerUpgradePath) + { + AssetDatabase.AddObjectToAsset(testManager, xrGeneralSettings); + } + + AssetDatabase.SaveAssets(); + } + + testPathToGeneralSettings = GetAssetPathForComponents(s_TestGeneralSettings); + testPathToGeneralSettings = Path.Combine(testPathToGeneralSettings, "Test_XRGeneralSettingsPerBuildTarget.asset"); + + buildTargetSettings = ScriptableObject.CreateInstance(); + buildTargetSettings.SetSettingsForBuildTarget(BuildTargetGroup.Standalone, xrGeneralSettings); + if (!string.IsNullOrEmpty(testPathToSettings)) + { + AssetDatabase.CreateAsset(buildTargetSettings, testPathToGeneralSettings); + AssetDatabase.SaveAssets(); + + EditorBuildSettings.TryGetConfigObject(XRGeneralSettings.k_SettingsKey, out currentSettings); + EditorBuildSettings.AddConfigObject(XRGeneralSettings.k_SettingsKey, buildTargetSettings, true); + } + + } + + public virtual void TearDownTest() + { + EditorBuildSettings.RemoveConfigObject(XRGeneralSettings.k_SettingsKey); + + if (!string.IsNullOrEmpty(testPathToGeneralSettings)) + { + AssetDatabase.DeleteAsset(testPathToGeneralSettings); + } + + if (!string.IsNullOrEmpty(testPathToSettings)) + { + AssetDatabase.DeleteAsset(testPathToSettings); + } + + xrGeneralSettings.Manager = null; + UnityEngine.Object.DestroyImmediate(xrGeneralSettings); + xrGeneralSettings = null; + + UnityEngine.Object.DestroyImmediate(testManager); + testManager = null; + + UnityEngine.Object.DestroyImmediate(buildTargetSettings); + buildTargetSettings = null; + + if (currentSettings != null) + EditorBuildSettings.AddConfigObject(XRGeneralSettings.k_SettingsKey, currentSettings, true); + else + EditorBuildSettings.RemoveConfigObject(XRGeneralSettings.k_SettingsKey); + + AssetDatabase.DeleteAsset(Path.Combine("Assets","Temp")); + } + + public static string GetAssetPathForComponents(string[] pathComponents, string root = "Assets") + { + if (pathComponents.Length <= 0) + return null; + + string path = root; + foreach( var pc in pathComponents) + { + string subFolder = Path.Combine(path, pc); + bool shouldCreate = true; + foreach (var f in AssetDatabase.GetSubFolders(path)) + { + if (String.Compare(Path.GetFullPath(f), Path.GetFullPath(subFolder), true) == 0) + { + shouldCreate = false; + break; + } + } + + if (shouldCreate) + AssetDatabase.CreateFolder(path, pc); + path = subFolder; + } + + return path; + } + } +} diff --git a/Tests/TestTooling/ManagementTestSetup.cs.meta b/Tests/TestTooling/ManagementTestSetup.cs.meta new file mode 100644 index 0000000..842d679 --- /dev/null +++ b/Tests/TestTooling/ManagementTestSetup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a500e1fea16b2fa43b644ddf59175b68 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestTooling/README.md b/Tests/TestTooling/README.md new file mode 100644 index 0000000..e5d059a --- /dev/null +++ b/Tests/TestTooling/README.md @@ -0,0 +1,8 @@ +# xr.sdk.test-tooling +Shared repo to put generally useful XR test tooling and support. + +Use as a git submodule in your provider package to allow for shared testing tools support. + +# Requirements + +Your provider package must have a dependency on XR Plugin Management prior to using this. \ No newline at end of file diff --git a/Tests/TestTooling/README.md.meta b/Tests/TestTooling/README.md.meta new file mode 100644 index 0000000..939ab20 --- /dev/null +++ b/Tests/TestTooling/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 823b1590c944c4243ad4b7d942ee197e +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Tests/TestTooling/Unity.XR.TestSupport.asmdef b/Tests/TestTooling/Unity.XR.TestSupport.asmdef new file mode 100644 index 0000000..3073900 --- /dev/null +++ b/Tests/TestTooling/Unity.XR.TestSupport.asmdef @@ -0,0 +1,23 @@ +{ + "name": "Unity.XR.TestSupport", + "references": [ + "GUID:f9fe0089ec81f4079af78eb2287a6163", + "GUID:e40ba710768534012815d3193fa296cb" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "optionalUnityReferences": [ + "TestAssemblies" + ], + "defineConstraints": [ + "UNITY_INCLUDE_TESTS" + ], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Tests/TestTooling/Unity.XR.TestSupport.asmdef.meta b/Tests/TestTooling/Unity.XR.TestSupport.asmdef.meta new file mode 100644 index 0000000..41e023b --- /dev/null +++ b/Tests/TestTooling/Unity.XR.TestSupport.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 174dd372073128d46a2d10d2daaf414f +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json index 8e94f48..e30be34 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.unity.xr.management", "displayName": "XR Plugin Management", - "version": "3.2.11-preview.1", + "version": "3.2.12", "unity": "2019.3", "unityRelease": "0f6", "description": "Package to provide for simple management of XR plug-ins. Provides help and management for loading, initialization, settings, and build support for XR plug-ins.", @@ -19,15 +19,12 @@ "com.unity.subsystemregistration": "1.0.6" }, "repository": { - "type": "git", "url": "https://github.cds.internal.unity3d.com/unity/xr.sdk.management.git", - "revision": "abec73432b834ead569684051a6a3991240579ba" - }, - "relatedPackages": { - "com.unity.xr.management.tests": "3.2.11-preview.1" + "type": "git", + "revision": "34b12a1b64d6cac1c4f5f39edc3d4e827bf26063" }, "upmCi": { - "footprint": "118125d251fa67e1544eacbb8b5cb5c0fa907699" + "footprint": "58fdbe3fa39ee7f11abc325beff805b6ffc67162" }, "samples": [ {