diff --git a/Submodules/Lumin b/Submodules/Lumin index 7a14f04f0..b2d25c32c 160000 --- a/Submodules/Lumin +++ b/Submodules/Lumin @@ -1 +1 @@ -Subproject commit 7a14f04f0e4b002db6c1145a5bbbedbea0ffc2f1 +Subproject commit b2d25c32c25dbbd1cac48997996a6b76a83eb8e0 diff --git a/Submodules/SDK b/Submodules/SDK index 5a3b20ef7..844a0638c 160000 --- a/Submodules/SDK +++ b/Submodules/SDK @@ -1 +1 @@ -Subproject commit 5a3b20ef7fc24483aa13f3ed0acace87bd9ab7ee +Subproject commit 844a0638cb422c6b7006eb6c37ee69b24010f2c5 diff --git a/XRTK-Core/Assets/XRTK.Tests/Core/TestFixture_01_MixedRealityToolkitTests.cs b/XRTK-Core/Assets/XRTK.Tests/Core/TestFixture_01_MixedRealityToolkitTests.cs index f73a91a19..b1baef340 100644 --- a/XRTK-Core/Assets/XRTK.Tests/Core/TestFixture_01_MixedRealityToolkitTests.cs +++ b/XRTK-Core/Assets/XRTK.Tests/Core/TestFixture_01_MixedRealityToolkitTests.cs @@ -1,11 +1,12 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using XRTK.Interfaces; -using XRTK.Services; using NUnit.Framework; +using UnityEditor.SceneManagement; using UnityEngine; using UnityEngine.TestTools; +using XRTK.Interfaces; +using XRTK.Services; using XRTK.Tests.Services; using XRTK.Utilities.Editor; @@ -18,14 +19,14 @@ public class TestFixture_01_MixedRealityToolkitTests [Test] public void Test_01_InitializeMixedRealityToolkit() { - TestUtilities.CleanupScene(); + EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single); MixedRealityToolkit.ConfirmInitialized(); Debug.Log(MixedRealityEditorSettings.MixedRealityToolkit_AbsoluteFolderPath); Debug.Log(MixedRealityEditorSettings.MixedRealityToolkit_RelativeFolderPath); // Tests - GameObject gameObject = GameObject.Find(nameof(MixedRealityToolkit)); + var gameObject = GameObject.Find(nameof(MixedRealityToolkit)); Assert.AreEqual(nameof(MixedRealityToolkit), gameObject.name); } @@ -42,6 +43,8 @@ public void Test_02_TestNoMixedRealityConfigurationFound() MixedRealityToolkit.Instance.ActiveProfile = null; // Tests + Assert.AreEqual(0, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(0, MixedRealityToolkit.RegisteredMixedRealityServices.Count); Assert.IsFalse(MixedRealityToolkit.HasActiveProfile); Assert.IsNull(MixedRealityToolkit.Instance.ActiveProfile); Assert.IsFalse(MixedRealityToolkit.HasActiveProfile); @@ -169,6 +172,9 @@ public void Test_04_04_UnregisterMixedRealityDataProvidersByType() { TestUtilities.InitializeMixedRealityToolkitScene(); + var activeSystemCount = MixedRealityToolkit.ActiveSystems.Count; + var activeServiceCount = MixedRealityToolkit.RegisteredMixedRealityServices.Count; + // Add test ExtensionService MixedRealityToolkit.RegisterService(new TestDataProvider1("Test Data Provider 1")); MixedRealityToolkit.RegisterService(new TestDataProvider2("Test Data Provider 2")); @@ -178,8 +184,8 @@ public void Test_04_04_UnregisterMixedRealityDataProvidersByType() // Tests Assert.IsNotNull(MixedRealityToolkit.Instance.ActiveProfile); - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.AreEqual(2, MixedRealityToolkit.RegisteredMixedRealityServices.Count); + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount + 2, MixedRealityToolkit.RegisteredMixedRealityServices.Count); Assert.AreEqual(extensionServices.Count, MixedRealityToolkit.RegisteredMixedRealityServices.Count); // Retrieve services @@ -202,8 +208,8 @@ public void Test_04_04_UnregisterMixedRealityDataProvidersByType() Assert.IsTrue(success2); Assert.IsFalse(isService1Registered); Assert.IsFalse(isService2Registered); - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.IsEmpty(MixedRealityToolkit.RegisteredMixedRealityServices); + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount, MixedRealityToolkit.RegisteredMixedRealityServices.Count); LogAssert.Expect(LogType.Error, $"Unable to find {typeof(ITestDataProvider1).Name} service."); LogAssert.Expect(LogType.Error, $"Unable to find {typeof(ITestDataProvider2).Name} service."); } @@ -309,6 +315,8 @@ public void Test_04_09_GetAllMixedRealityDataProviders() public void Test_05_01_RegisterMixedRealityExtensionService() { TestUtilities.InitializeMixedRealityToolkitScene(); + var activeSystemCount = MixedRealityToolkit.ActiveSystems.Count; + var activeServiceCount = MixedRealityToolkit.RegisteredMixedRealityServices.Count; // Register ITestExtensionService1 MixedRealityToolkit.RegisterService(new TestExtensionService1("Test ExtensionService 1")); @@ -318,14 +326,16 @@ public void Test_05_01_RegisterMixedRealityExtensionService() // Tests Assert.IsNotNull(extensionService1); - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.AreEqual(1, MixedRealityToolkit.RegisteredMixedRealityServices.Count); + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount + 1, MixedRealityToolkit.RegisteredMixedRealityServices.Count); } [Test] public void Test_05_02_01_UnregisterMixedRealityExtensionServiceByType() { TestUtilities.InitializeMixedRealityToolkitScene(); + var activeSystemCount = MixedRealityToolkit.ActiveSystems.Count; + var activeServiceCount = MixedRealityToolkit.RegisteredMixedRealityServices.Count; // Register ITestExtensionService1 MixedRealityToolkit.RegisterService(new TestExtensionService1("Test ExtensionService 1")); @@ -335,8 +345,8 @@ public void Test_05_02_01_UnregisterMixedRealityExtensionServiceByType() // Tests Assert.IsNotNull(extensionService1); - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.AreEqual(1, MixedRealityToolkit.RegisteredMixedRealityServices.Count); + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount + 1, MixedRealityToolkit.RegisteredMixedRealityServices.Count); var success = MixedRealityToolkit.UnregisterServicesOfType(); @@ -346,8 +356,8 @@ public void Test_05_02_01_UnregisterMixedRealityExtensionServiceByType() // Tests Assert.IsTrue(success); Assert.IsFalse(isServiceRegistered); - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.IsEmpty(MixedRealityToolkit.RegisteredMixedRealityServices); + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount, MixedRealityToolkit.RegisteredMixedRealityServices.Count); LogAssert.Expect(LogType.Error, $"Unable to find {typeof(ITestExtensionService1).Name} service."); } @@ -355,6 +365,8 @@ public void Test_05_02_01_UnregisterMixedRealityExtensionServiceByType() public void Test_05_02_02_UnregisterMixedRealityExtensionServiceByTypeAndName() { TestUtilities.InitializeMixedRealityToolkitScene(); + var activeSystemCount = MixedRealityToolkit.ActiveSystems.Count; + var activeServiceCount = MixedRealityToolkit.RegisteredMixedRealityServices.Count; // Register ITestExtensionService1 MixedRealityToolkit.RegisterService(new TestExtensionService1("Test ExtensionService 1")); @@ -364,8 +376,8 @@ public void Test_05_02_02_UnregisterMixedRealityExtensionServiceByTypeAndName() // Tests Assert.IsNotNull(extensionService1); - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.AreEqual(1, MixedRealityToolkit.RegisteredMixedRealityServices.Count); + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount + 1, MixedRealityToolkit.RegisteredMixedRealityServices.Count); var success = MixedRealityToolkit.UnregisterService(extensionService1.Name); @@ -375,8 +387,8 @@ public void Test_05_02_02_UnregisterMixedRealityExtensionServiceByTypeAndName() // Tests Assert.IsTrue(success); Assert.IsFalse(isServiceRegistered); - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.IsEmpty(MixedRealityToolkit.RegisteredMixedRealityServices); + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount, MixedRealityToolkit.RegisteredMixedRealityServices.Count); LogAssert.Expect(LogType.Error, $"Unable to find {typeof(ITestExtensionService1).Name} service."); } @@ -384,6 +396,8 @@ public void Test_05_02_02_UnregisterMixedRealityExtensionServiceByTypeAndName() public void Test_05_03_RegisterMixedRealityExtensionServices() { TestUtilities.InitializeMixedRealityToolkitScene(); + var activeSystemCount = MixedRealityToolkit.ActiveSystems.Count; + var activeServiceCount = MixedRealityToolkit.RegisteredMixedRealityServices.Count; // Add test ExtensionService MixedRealityToolkit.RegisterService(new TestExtensionService1("Test ExtensionService 1")); @@ -394,15 +408,16 @@ public void Test_05_03_RegisterMixedRealityExtensionServices() // Tests Assert.IsNotNull(MixedRealityToolkit.Instance.ActiveProfile); - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.AreEqual(2, MixedRealityToolkit.RegisteredMixedRealityServices.Count); - Assert.AreEqual(extensionServices.Count, MixedRealityToolkit.RegisteredMixedRealityServices.Count); + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount + extensionServices.Count, MixedRealityToolkit.RegisteredMixedRealityServices.Count); } [Test] public void Test_05_04_UnregisterMixedRealityExtensionServicesByType() { TestUtilities.InitializeMixedRealityToolkitScene(); + var activeSystemCount = MixedRealityToolkit.ActiveSystems.Count; + var activeServiceCount = MixedRealityToolkit.RegisteredMixedRealityServices.Count; // Add test ExtensionService MixedRealityToolkit.RegisterService(new TestExtensionService1("Test ExtensionService 1")); @@ -413,9 +428,8 @@ public void Test_05_04_UnregisterMixedRealityExtensionServicesByType() // Tests Assert.IsNotNull(MixedRealityToolkit.Instance.ActiveProfile); - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.AreEqual(2, MixedRealityToolkit.RegisteredMixedRealityServices.Count); - Assert.AreEqual(extensionServices.Count, MixedRealityToolkit.RegisteredMixedRealityServices.Count); + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount + extensionServices.Count, MixedRealityToolkit.RegisteredMixedRealityServices.Count); // Retrieve services var extensionService1 = MixedRealityToolkit.GetService(); @@ -435,8 +449,8 @@ public void Test_05_04_UnregisterMixedRealityExtensionServicesByType() Assert.IsTrue(success); Assert.IsFalse(isService1Registered); Assert.IsFalse(isService2Registered); - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.IsEmpty(MixedRealityToolkit.RegisteredMixedRealityServices); + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount, MixedRealityToolkit.RegisteredMixedRealityServices.Count); LogAssert.Expect(LogType.Error, $"Unable to find {typeof(ITestExtensionService1).Name} service."); LogAssert.Expect(LogType.Error, $"Unable to find {typeof(ITestExtensionService2).Name} service."); } @@ -510,7 +524,7 @@ public void Test_05_08_GetMixedRealityExtensionServiceCollectionByInterface() MixedRealityToolkit.RegisterService(new TestExtensionService2("Test15-2.1")); MixedRealityToolkit.RegisterService(new TestExtensionService2("Test15-2.2")); - // Retrieve ExtensionService2 + // Retrieve ExtensionService 2 var extensionServices = MixedRealityToolkit.GetActiveServices(); // Tests @@ -545,17 +559,18 @@ public void Test_05_09_GetAllMixedRealityExtensionServices() public void Test_06_01_TryRegisterMixedRealityDataProvider() { TestUtilities.InitializeMixedRealityToolkitScene(); + var activeSystemCount = MixedRealityToolkit.ActiveSystems.Count; + var activeServiceCount = MixedRealityToolkit.RegisteredMixedRealityServices.Count; // Register MixedRealityToolkit.RegisterService(new TestDataProvider1("Test Data Provider 1")); // Retrieve - ITestDataProvider1 extensionService1 = null; - bool result = MixedRealityToolkit.TryGetService(out extensionService1); + var result = MixedRealityToolkit.TryGetService(out var extensionService1); // Tests - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.AreEqual(1, MixedRealityToolkit.RegisteredMixedRealityServices.Count); + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount + 1, MixedRealityToolkit.RegisteredMixedRealityServices.Count); // Tests Assert.IsTrue(result); @@ -566,43 +581,39 @@ public void Test_06_01_TryRegisterMixedRealityDataProvider() public void Test_06_02_TryRegisterMixedRealityDataProviderFail() { TestUtilities.InitializeMixedRealityToolkitScene(); - - LogAssert.Expect(LogType.Error, "Unable to find ITestDataProvider1 service."); + var activeSystemCount = MixedRealityToolkit.ActiveSystems.Count; + var activeServiceCount = MixedRealityToolkit.RegisteredMixedRealityServices.Count; // Retrieve - ITestDataProvider1 extensionService1 = null; - bool result = MixedRealityToolkit.TryGetService(out extensionService1); - - // Tests - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.IsEmpty(MixedRealityToolkit.RegisteredMixedRealityServices); + var result = MixedRealityToolkit.TryGetService(out var extensionService1); // Tests + LogAssert.Expect(LogType.Error, $"Unable to find {nameof(ITestDataProvider1)} service."); Assert.IsFalse(result); Assert.IsNull(extensionService1); + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount, MixedRealityToolkit.RegisteredMixedRealityServices.Count); } [Test] public void Test_06_03_TryRegisterMixedRealityDataProviderByName() { TestUtilities.InitializeMixedRealityToolkitScene(); - - LogAssert.Expect(LogType.Error, "Unable to find Test Data Provider 2 service."); - + var activeSystemCount = MixedRealityToolkit.ActiveSystems.Count; + var activeServiceCount = MixedRealityToolkit.RegisteredMixedRealityServices.Count; // Register MixedRealityToolkit.RegisterService(new TestDataProvider1("Test Data Provider 1")); // Retrieve - ITestDataProvider1 extensionService1 = null; - ITestDataProvider1 extensionService2 = null; - - bool resultTrue = MixedRealityToolkit.TryGetService("Test Data Provider 1", out extensionService1); - bool resultFalse = MixedRealityToolkit.TryGetService("Test Data Provider 2", out extensionService2); + var resultTrue = MixedRealityToolkit.TryGetService("Test Data Provider 1", out var extensionService1); + var resultFalse = MixedRealityToolkit.TryGetService("Test Data Provider 2", out var extensionService2); // Tests - Assert.IsEmpty(MixedRealityToolkit.ActiveSystems); - Assert.AreEqual(1, MixedRealityToolkit.RegisteredMixedRealityServices.Count); + LogAssert.Expect(LogType.Error, "Unable to find Test Data Provider 2 service."); + + Assert.AreEqual(activeSystemCount, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount + 1, MixedRealityToolkit.RegisteredMixedRealityServices.Count); // Tests Assert.IsTrue(resultTrue, "Test Data Provider 1 found"); diff --git a/XRTK-Core/Assets/XRTK.Tests/Core/TestFixture_02_MixedRealityToolkitUtilityTests.cs b/XRTK-Core/Assets/XRTK.Tests/Core/TestFixture_02_MixedRealityToolkitUtilityTests.cs index 0d0e55600..caa26debd 100644 --- a/XRTK-Core/Assets/XRTK.Tests/Core/TestFixture_02_MixedRealityToolkitUtilityTests.cs +++ b/XRTK-Core/Assets/XRTK.Tests/Core/TestFixture_02_MixedRealityToolkitUtilityTests.cs @@ -1,12 +1,13 @@ // Copyright (c) XRTK. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. +using System.Collections.Generic; using NUnit.Framework; using UnityEngine; using XRTK.Definitions; using XRTK.Definitions.Controllers; using XRTK.Definitions.InputSystem; -using XRTK.Definitions.Utilities; +using XRTK.Definitions.Platforms; using XRTK.Extensions; using XRTK.Interfaces; using XRTK.Providers.Controllers.OpenVR; @@ -26,6 +27,8 @@ private void SetupServiceLocator() #region Configuration Validation Tests + private readonly List testPlatforms = new List { new EditorPlatform(), new WindowsStandalonePlatform() }; + [Test] public void Test_01_ConfirmExtensionServiceProviderConfigurationNotPresent() { @@ -34,7 +37,7 @@ public void Test_01_ConfirmExtensionServiceProviderConfigurationNotPresent() var dataProviderTypes = new[] { typeof(TestExtensionService1) }; var newConfigs = new[] { - new MixedRealityServiceConfiguration(typeof(TestExtensionService1), "Test Extension Service 1", 2,SupportedPlatforms.WindowsStandalone | SupportedPlatforms.Editor, null) + new MixedRealityServiceConfiguration(typeof(TestExtensionService1), "Test Extension Service 1", 2, testPlatforms, null) }; Assert.IsFalse(profile.ValidateService(dataProviderTypes, newConfigs, false)); @@ -46,7 +49,7 @@ public void Test_02_ConfirmExtensionServiceProviderConfigurationPresent() SetupServiceLocator(); var profile = MixedRealityToolkit.Instance.ActiveProfile.RegisteredServiceProvidersProfile; var dataProviderTypes = new[] { typeof(TestExtensionService1) }; - var newConfig = new MixedRealityServiceConfiguration(typeof(TestExtensionService1), "Test Extension Service 1", 2, SupportedPlatforms.WindowsStandalone | SupportedPlatforms.Editor, null); + var newConfig = new MixedRealityServiceConfiguration(typeof(TestExtensionService1), "Test Extension Service 1", 2, testPlatforms, null); Debug.Assert(newConfig != null); var newConfigs = profile.RegisteredServiceConfigurations.AddItem(newConfig); Debug.Assert(newConfigs != null); diff --git a/XRTK-Core/Assets/XRTK.Tests/InputSystem/TestFixture_03_InputSystemTests.cs b/XRTK-Core/Assets/XRTK.Tests/InputSystem/TestFixture_03_InputSystemTests.cs index f571f22aa..db470f53a 100644 --- a/XRTK-Core/Assets/XRTK.Tests/InputSystem/TestFixture_03_InputSystemTests.cs +++ b/XRTK-Core/Assets/XRTK.Tests/InputSystem/TestFixture_03_InputSystemTests.cs @@ -16,6 +16,8 @@ public class TestFixture_03_InputSystemTests public void Test01_CreateMixedRealityInputSystem() { TestUtilities.InitializeMixedRealityToolkitScene(); + var activeSystemCount = MixedRealityToolkit.ActiveSystems.Count; + var activeServiceCount = MixedRealityToolkit.RegisteredMixedRealityServices.Count; // Add Input System MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile = InputSystemTestUtilities.SetupInputSystemProfile(); @@ -23,8 +25,8 @@ public void Test01_CreateMixedRealityInputSystem() // Tests Assert.IsNotEmpty(MixedRealityToolkit.ActiveSystems); - Assert.AreEqual(1, MixedRealityToolkit.ActiveSystems.Count); - Assert.AreEqual(0, MixedRealityToolkit.RegisteredMixedRealityServices.Count); + Assert.AreEqual(activeSystemCount + 1, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(activeServiceCount, MixedRealityToolkit.RegisteredMixedRealityServices.Count); } [Test] diff --git a/XRTK-Core/Assets/XRTK.Tests/TestUtilities.cs b/XRTK-Core/Assets/XRTK.Tests/TestUtilities.cs index 9983aa299..3cd245cd4 100644 --- a/XRTK-Core/Assets/XRTK.Tests/TestUtilities.cs +++ b/XRTK-Core/Assets/XRTK.Tests/TestUtilities.cs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. -using System.Linq; using NUnit.Framework; +using System.Linq; using UnityEditor.SceneManagement; using UnityEngine; using XRTK.Definitions; @@ -28,6 +28,8 @@ public static void InitializeMixedRealityToolkitScene(bool useDefaultProfile = f // Setup CleanupScene(); Assert.IsTrue(!MixedRealityToolkit.IsInitialized); + Assert.AreEqual(0, MixedRealityToolkit.ActiveSystems.Count); + Assert.AreEqual(0, MixedRealityToolkit.RegisteredMixedRealityServices.Count); InitializeMixedRealityToolkit(); // Tests diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/BaseMixedRealityServiceProfile.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/BaseMixedRealityServiceProfile.cs index 42b51fc1a..381a25c8d 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Definitions/BaseMixedRealityServiceProfile.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/BaseMixedRealityServiceProfile.cs @@ -36,7 +36,7 @@ public MixedRealityServiceConfiguration[] RegisteredServiceConfigurati { var cachedConfig = configurations[i]; Debug.Assert(cachedConfig != null); - var serviceConfig = new MixedRealityServiceConfiguration(cachedConfig.InstancedType, cachedConfig.Name, cachedConfig.Priority, cachedConfig.RuntimePlatform, cachedConfig.ConfigurationProfile); + var serviceConfig = new MixedRealityServiceConfiguration(cachedConfig.InstancedType, cachedConfig.Name, cachedConfig.Priority, cachedConfig.RuntimePlatforms, cachedConfig.ConfigurationProfile); Debug.Assert(serviceConfig != null); serviceConfigurations[i] = serviceConfig; } @@ -59,7 +59,7 @@ internal set { var serviceConfig = serviceConfigurations[i]; Debug.Assert(serviceConfig != null); - var newConfig = new MixedRealityServiceConfiguration(serviceConfig.InstancedType, serviceConfig.Name, serviceConfig.Priority, serviceConfig.RuntimePlatform, serviceConfig.ConfigurationProfile); + var newConfig = new MixedRealityServiceConfiguration(serviceConfig.InstancedType, serviceConfig.Name, serviceConfig.Priority, serviceConfig.RuntimePlatforms, serviceConfig.ConfigurationProfile); Debug.Assert(newConfig != null); configurations[i] = newConfig; } diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/MixedRealityServiceConfiguration.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/MixedRealityServiceConfiguration.cs index e1f6e194b..4a3020228 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Definitions/MixedRealityServiceConfiguration.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/MixedRealityServiceConfiguration.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using System; +using System.Collections.Generic; using UnityEngine; using UnityEngine.Serialization; using XRTK.Attributes; @@ -16,8 +17,8 @@ public class MixedRealityServiceConfiguration : MixedRealityServiceConfigurat where T : IMixedRealityService { /// - public MixedRealityServiceConfiguration(SystemType instancedType, string name, uint priority, SupportedPlatforms runtimePlatform, BaseMixedRealityProfile configurationProfile) - : base(instancedType, name, priority, runtimePlatform, configurationProfile) + public MixedRealityServiceConfiguration(SystemType instancedType, string name, uint priority, IReadOnlyList runtimePlatforms, BaseMixedRealityProfile configurationProfile) + : base(instancedType, name, priority, runtimePlatforms, configurationProfile) { } } @@ -34,14 +35,26 @@ public class MixedRealityServiceConfiguration : IMixedRealityServiceConfiguratio /// The concrete type for the . /// The simple, human readable name for the . /// The priority this will be initialized in. - /// The runtime platform(s) to run this to run on. + /// runtimePlatform">The runtime platform(s) to run this to run on. /// The configuration profile for . - public MixedRealityServiceConfiguration(SystemType instancedType, string name, uint priority, SupportedPlatforms runtimePlatform, BaseMixedRealityProfile configurationProfile) + public MixedRealityServiceConfiguration(SystemType instancedType, string name, uint priority, IReadOnlyList runtimePlatforms, BaseMixedRealityProfile configurationProfile) { this.instancedType = instancedType; this.name = name; this.priority = priority; - this.runtimePlatform = runtimePlatform; + + if (runtimePlatforms != null) + { + this.runtimePlatforms = new List(runtimePlatforms.Count); + + for (int i = 0; i < runtimePlatforms.Count; i++) + { + this.runtimePlatforms.Add(runtimePlatforms[i]); + } + + platformEntries = new RuntimePlatformEntry(runtimePlatforms); + } + this.configurationProfile = configurationProfile; } @@ -84,15 +97,48 @@ public uint Priority internal set => priority = value; } - [EnumFlags] [SerializeField] - private SupportedPlatforms runtimePlatform; + private RuntimePlatformEntry platformEntries = new RuntimePlatformEntry(); + + [NonSerialized] + private List runtimePlatforms = null; /// - public SupportedPlatforms RuntimePlatform + public IReadOnlyList RuntimePlatforms { - get => runtimePlatform; - internal set => runtimePlatform = value; + get + { + if (runtimePlatforms == null || + runtimePlatforms.Count == 0 || + runtimePlatforms.Count != platformEntries?.RuntimePlatforms?.Length) + { + runtimePlatforms = new List(); + + for (int i = 0; i < MixedRealityToolkit.AvailablePlatforms.Count; i++) + { + var availablePlatform = MixedRealityToolkit.AvailablePlatforms[i]; + var availablePlatformType = availablePlatform.GetType(); + + for (int j = 0; j < platformEntries?.RuntimePlatforms?.Length; j++) + { + var platformType = platformEntries.RuntimePlatforms[j]?.Type; + + if (platformType == null) + { + Debug.LogError($"Failed to resolve {platformEntries.RuntimePlatforms[j]} for {name}"); + continue; + } + + if (availablePlatformType == platformType) + { + runtimePlatforms.Add(availablePlatform); + } + } + } + } + + return runtimePlatforms; + } } [SerializeField] @@ -105,4 +151,4 @@ public BaseMixedRealityProfile ConfigurationProfile internal set => configurationProfile = value; } } -} \ No newline at end of file +} diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/MixedRealityToolkitConfigurationProfile.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/MixedRealityToolkitConfigurationProfile.cs index b3deec8f6..06bb2891e 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Definitions/MixedRealityToolkitConfigurationProfile.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/MixedRealityToolkitConfigurationProfile.cs @@ -27,6 +27,8 @@ public class MixedRealityToolkitConfigurationProfile : BaseMixedRealityProfile { #region Mixed Reality Toolkit configurable properties + #region Camera System Properties + [SerializeField] [Tooltip("Enable the Camera System on Startup.")] private bool enableCameraSystem = false; @@ -54,7 +56,6 @@ public SystemType CameraSystemType internal set => cameraSystemType = value; } - [SerializeField] [Tooltip("Camera profile.")] private MixedRealityCameraProfile cameraProfile; @@ -69,6 +70,10 @@ public MixedRealityCameraProfile CameraProfile internal set => cameraProfile = value; } + #endregion Camera System Properties + + #region Input System Properties + [SerializeField] [Tooltip("Enable the Input System on Startup.")] private bool enableInputSystem = false; @@ -109,6 +114,10 @@ public SystemType InputSystemType internal set => inputSystemType = value; } + #endregion Input System Properties + + #region Boundary System Properties + [SerializeField] [Tooltip("Enable the Boundary on Startup")] private bool enableBoundarySystem = false; @@ -149,6 +158,10 @@ public MixedRealityBoundaryVisualizationProfile BoundaryVisualizationProfile internal set => boundaryVisualizationProfile = value; } + #endregion Boundary System Properties + + #region Teleportation System Properties + [SerializeField] [Tooltip("Enable the Teleport System on Startup")] private bool enableTeleportSystem = false; @@ -176,6 +189,10 @@ public SystemType TeleportSystemSystemType internal set => teleportSystemType = value; } + #endregion Teleportation System Properties + + #region Spatial Awareness System Properties + [SerializeField] [Tooltip("Enable the Spatial Awareness system on Startup")] private bool enableSpatialAwarenessSystem = false; @@ -216,6 +233,10 @@ public MixedRealitySpatialAwarenessSystemProfile SpatialAwarenessProfile internal set => spatialAwarenessProfile = value; } + #endregion Spatial Awareness System Properties + + #region Networking System Properties + [SerializeField] [Tooltip("Profile for wiring up networking assets.")] private MixedRealityNetworkSystemProfile networkingSystemProfile; @@ -256,6 +277,10 @@ public SystemType NetworkingSystemSystemType internal set => networkingSystemType = value; } + #endregion Networking System Properties + + #region Diagnostics System Properties + [SerializeField] [Tooltip("Profile for wiring up diagnostic assets.")] private MixedRealityDiagnosticsSystemProfile diagnosticsSystemProfile; @@ -296,6 +321,8 @@ public SystemType DiagnosticsSystemSystemType internal set => diagnosticsSystemType = value; } + #endregion Diagnostics System Properties + [SerializeField] [Tooltip("All the additional non-required services registered with the Mixed Reality Toolkit.")] private MixedRealityRegisteredServiceProvidersProfile registeredServiceProvidersProfile = null; diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms.meta b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms.meta new file mode 100644 index 000000000..467a92ab4 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a8f99e951b050464082ba476eaeba31e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/AllPlatforms.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/AllPlatforms.cs new file mode 100644 index 000000000..2750c2aa6 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/AllPlatforms.cs @@ -0,0 +1,14 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace XRTK.Definitions.Platforms +{ + /// + /// Used by the XRTK to signal that the feature is available on every platform. + /// + public sealed class AllPlatforms : BasePlatform + { + /// + public override bool IsAvailable => true; + } +} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/SupportedPlatforms.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/AllPlatforms.cs.meta similarity index 67% rename from XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/SupportedPlatforms.cs.meta rename to XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/AllPlatforms.cs.meta index 87f64c7aa..daff517e6 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/SupportedPlatforms.cs.meta +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/AllPlatforms.cs.meta @@ -1,11 +1,11 @@ fileFormatVersion: 2 -guid: e8bfc155d5fe450e91b0af0d5251d241 +guid: adf3513e2a004ab489b86b1277f8df3e MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} - userData: - assetBundleName: - assetBundleVariant: + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/AndroidPlatform.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/AndroidPlatform.cs new file mode 100644 index 000000000..b287dfc13 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/AndroidPlatform.cs @@ -0,0 +1,24 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace XRTK.Definitions.Platforms +{ + /// + /// Used by the XRTK to signal that the feature is available on the Android platform. + /// + public class AndroidPlatform : BasePlatform + { + /// + public override bool IsAvailable + { + get + { +#if PLATFORM_ANDROID + return true; +#else + return false; +#endif + } + } + } +} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Utilities/PlatformUtility.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/AndroidPlatform.cs.meta similarity index 67% rename from XRTK-Core/Packages/com.xrtk.core/Utilities/PlatformUtility.cs.meta rename to XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/AndroidPlatform.cs.meta index c5b296785..57b134766 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Utilities/PlatformUtility.cs.meta +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/AndroidPlatform.cs.meta @@ -1,11 +1,11 @@ fileFormatVersion: 2 -guid: 5bb67be90b764c1381666ab3036da299 +guid: 5de6a379461f43b45828c74598cf13a4 MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} - userData: - assetBundleName: - assetBundleVariant: + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/BasePlatform.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/BasePlatform.cs new file mode 100644 index 000000000..b65047be3 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/BasePlatform.cs @@ -0,0 +1,18 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using XRTK.Interfaces; + +namespace XRTK.Definitions.Platforms +{ + /// + /// Base platform class to derive all s from. + /// + [Serializable] + public abstract class BasePlatform : IMixedRealityPlatform + { + /// + public virtual bool IsAvailable => false; + } +} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/BasePlatform.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/BasePlatform.cs.meta new file mode 100644 index 000000000..96c4c5828 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/BasePlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: de648548bb3441442b739bf8ec299c74 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/EditorPlatform.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/EditorPlatform.cs new file mode 100644 index 000000000..7aaa16f30 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/EditorPlatform.cs @@ -0,0 +1,19 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEngine; + +namespace XRTK.Definitions.Platforms +{ + /// + /// Used by the XRTK to signal that the feature is available in the Unity Editor. + /// + /// + /// Defines any editor platform for Win, OSX, and Linux. + /// + public sealed class EditorPlatform : BasePlatform + { + /// + public override bool IsAvailable => Application.isEditor; + } +} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/EditorPlatform.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/EditorPlatform.cs.meta new file mode 100644 index 000000000..6e6b012f3 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/EditorPlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cd18a6020a895a64d834c381e17026dc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/IOSPlatform.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/IOSPlatform.cs new file mode 100644 index 000000000..47b72b90a --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/IOSPlatform.cs @@ -0,0 +1,24 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace XRTK.Definitions.Platforms +{ + /// + /// Used by the XRTK to signal that the feature is available on the iOS platform. + /// + public class IOSPlatform : BasePlatform + { + /// + public override bool IsAvailable + { + get + { +#if PLATFORM_IOS + return true; +#else + return false; +#endif + } + } + } +} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/IOSPlatform.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/IOSPlatform.cs.meta new file mode 100644 index 000000000..b8d0c59df --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/IOSPlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9b46f1ec45b964847a9e091ddf2b90c9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/OSXPlatform.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/OSXPlatform.cs new file mode 100644 index 000000000..1e10eb093 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/OSXPlatform.cs @@ -0,0 +1,24 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace XRTK.Definitions.Platforms +{ + /// + /// Used by the XRTK to signal that the feature is available on the OSX platform. + /// + public class OSXPlatform : BasePlatform + { + /// + public override bool IsAvailable + { + get + { +#if UNITY_STANDALONE_OSX + return true; +#else + return false; +#endif + } + } + } +} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/OSXPlatform.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/OSXPlatform.cs.meta new file mode 100644 index 000000000..63b7f3bd2 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/OSXPlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 48d4cbc5eaa669e48ba9204c537ca9df +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/UniversalWindowsPlatform.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/UniversalWindowsPlatform.cs new file mode 100644 index 000000000..a9f5bb601 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/UniversalWindowsPlatform.cs @@ -0,0 +1,24 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace XRTK.Definitions.Platforms +{ + /// + /// Used by the XRTK to signal that the feature is available on the Windows Universal Platform. + /// + public class UniversalWindowsPlatform : BasePlatform + { + /// + public override bool IsAvailable + { + get + { +#if UNITY_WSA + return true; +#else + return false; +#endif + } + } + } +} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/UniversalWindowsPlatform.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/UniversalWindowsPlatform.cs.meta new file mode 100644 index 000000000..f0c74ef12 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/UniversalWindowsPlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: de428e85b48473640a3dc63ebe35a8d8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/WebGlPlatform.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/WebGlPlatform.cs new file mode 100644 index 000000000..5352dd94f --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/WebGlPlatform.cs @@ -0,0 +1,24 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace XRTK.Definitions.Platforms +{ + /// + /// Used by the XRTK to signal that the feature is available on the WebGL platform. + /// + public class WebGlPlatform : BasePlatform + { + /// + public override bool IsAvailable + { + get + { +#if PLATFORM_WEBGL + return true; +#else + return false; +#endif + } + } + } +} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/WebGlPlatform.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/WebGlPlatform.cs.meta new file mode 100644 index 000000000..8f33a2c67 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/WebGlPlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 32755bf257aaad4489412842de96b216 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/WindowsStandalonePlatform.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/WindowsStandalonePlatform.cs new file mode 100644 index 000000000..3d97c851c --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/WindowsStandalonePlatform.cs @@ -0,0 +1,24 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace XRTK.Definitions.Platforms +{ + /// + /// Used by the XRTK to signal that the feature is available on the Windows Standalone platform. + /// + public class WindowsStandalonePlatform : BasePlatform + { + /// + public override bool IsAvailable + { + get + { +#if UNITY_STANDALONE_WIN + return true; +#else + return false; +#endif + } + } + } +} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/WindowsStandalonePlatform.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/WindowsStandalonePlatform.cs.meta new file mode 100644 index 000000000..2ccd29cff --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Platforms/WindowsStandalonePlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3c1fa3b5d4d0980418941be1e4592150 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/RuntimePlatformEntry.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/RuntimePlatformEntry.cs new file mode 100644 index 000000000..9c7026951 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/RuntimePlatformEntry.cs @@ -0,0 +1,37 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using System.Collections.Generic; +using UnityEngine; +using XRTK.Attributes; +using XRTK.Definitions.Utilities; +using XRTK.Interfaces; + +namespace XRTK.Definitions +{ + [Serializable] + public class RuntimePlatformEntry + { + public RuntimePlatformEntry() + { + runtimePlatforms = new SystemType[0]; + } + + public RuntimePlatformEntry(IReadOnlyList runtimePlatforms) + { + this.runtimePlatforms = new SystemType[runtimePlatforms.Count]; + + for (int i = 0; i < runtimePlatforms.Count; i++) + { + this.runtimePlatforms[i] = new SystemType(runtimePlatforms[i].GetType()); + } + } + + [SerializeField] + [Implements(typeof(IMixedRealityPlatform), TypeGrouping.ByNamespaceFlat)] + private SystemType[] runtimePlatforms; + + public SystemType[] RuntimePlatforms => runtimePlatforms; + } +} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/RuntimePlatformEntry.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Definitions/RuntimePlatformEntry.cs.meta new file mode 100644 index 000000000..b069472a6 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/RuntimePlatformEntry.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 83c83d39e2504d6db9b4b2ec01563a10 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/ProfileMenuItemIndices.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/ProfileMenuItemIndices.cs index d7fa571e3..21f0b18c8 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/ProfileMenuItemIndices.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/ProfileMenuItemIndices.cs @@ -9,6 +9,7 @@ namespace XRTK.Definitions.Utilities public enum CreateProfileMenuItemIndices { Configuration = 0, + Platform, Camera, Input, Pointer, diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/SupportedPlatforms.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/SupportedPlatforms.cs deleted file mode 100644 index c61fd02cb..000000000 --- a/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/SupportedPlatforms.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using System; - -namespace XRTK.Definitions.Utilities -{ - /// - /// The supported platforms for Mixed Reality Toolkit Components and Features. - /// - [Flags] - public enum SupportedPlatforms - { - /// - /// Editor. - /// - Editor = 1 << 0, - /// - /// Windows Standalone platforms. - /// - WindowsStandalone = 1 << 1, - /// - /// Mac OSX standalone platforms. - /// - MacStandalone = 1 << 2, - /// - /// Linux standalone platforms. - /// - LinuxStandalone = 1 << 3, - /// - /// Windows UWP platforms. - /// - WindowsUniversal = 1 << 4, - /// - /// Magic Leap platform. - /// - Lumin = 1 << 5, - /// - /// Android mobile platforms - /// - Android = 1 << 6, - /// - /// Mac iOS mobile platforms. - /// - iOS = 1 << 7 - } -} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/SystemType.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/SystemType.cs index 547f6d9bd..6ab2d4dee 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/SystemType.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Utilities/SystemType.cs @@ -100,7 +100,7 @@ public static implicit operator string(SystemType type) public static implicit operator Type(SystemType type) { - return type.Type; + return type?.Type; } public static implicit operator SystemType(Type type) @@ -110,7 +110,7 @@ public static implicit operator SystemType(Type type) public override string ToString() { - return Type?.FullName ?? "(None)"; + return Type?.FullName ?? (string.IsNullOrWhiteSpace(reference) ? "{None}" : reference); } } } \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Extensions/StringExtensions.cs b/XRTK-Core/Packages/com.xrtk.core/Extensions/StringExtensions.cs index 569ba6b07..2bd37566e 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Extensions/StringExtensions.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Extensions/StringExtensions.cs @@ -46,7 +46,7 @@ public static string ToProperCase(this string value) { // If there are 0 or 1 characters, just return the string. if (value == null) { return string.Empty; } - if (value.Length < 2) { return value.ToUpper(); } + if (value.Length < 4) { return value.ToUpper(); } // If there's already spaces in the string, return. if (value.Contains(WhiteSpace)) { return value; } diff --git a/XRTK-Core/Packages/com.xrtk.core/Extensions/TypeExtensions.cs b/XRTK-Core/Packages/com.xrtk.core/Extensions/TypeExtensions.cs index 45fb6c377..7076522cf 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Extensions/TypeExtensions.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Extensions/TypeExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using System; +using System.Collections.Generic; using UnityEngine; namespace XRTK.Extensions @@ -11,6 +12,24 @@ namespace XRTK.Extensions /// public static class TypeExtensions { + private static readonly Dictionary TypeMap = new Dictionary(); + + /// + /// Attempts to resolve the class reference by the . + /// + /// The of the type to get. + /// The from + public static Type ResolveType(string classRef) + { + if (!TypeMap.TryGetValue(classRef, out var type)) + { + type = !string.IsNullOrEmpty(classRef) ? Type.GetType(classRef) : null; + TypeMap[classRef] = type; + } + + return type; + } + /// /// Recursively looks for generic type arguments in type hierarchy, starting with the /// root type provided. If no generic type arguments are found on a type, it's base diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityServiceProviderProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityServiceProviderProfileInspector.cs index 08ddb463c..6e1bd7dfe 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityServiceProviderProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityServiceProviderProfileInspector.cs @@ -98,11 +98,13 @@ private void DrawConfigurationOptionElement(Rect rect, int index, bool isActive, var nameProperty = configurationProperty.FindPropertyRelative("name"); var priorityProperty = configurationProperty.FindPropertyRelative("priority"); var instanceTypeProperty = configurationProperty.FindPropertyRelative("instancedType"); - var runtimePlatformProperty = configurationProperty.FindPropertyRelative("runtimePlatform"); + var platformEntriesProperty = configurationProperty.FindPropertyRelative("platformEntries"); var configurationProfileProperty = configurationProperty.FindPropertyRelative("configurationProfile"); var configurationProfile = configurationProfileProperty.objectReferenceValue as BaseMixedRealityProfile; + priorityProperty.intValue = index; + EditorGUI.BeginChangeCheck(); EditorGUI.PropertyField(nameRect, nameProperty); TypeReferencePropertyDrawer.FilterConstraintOverride = IsConstraintSatisfied; @@ -137,8 +139,7 @@ private void DrawConfigurationOptionElement(Rect rect, int index, bool isActive, } } - priorityProperty.intValue = index; - EditorGUI.PropertyField(runtimeRect, runtimePlatformProperty); + EditorGUI.PropertyField(runtimeRect, platformEntriesProperty); var update = false; @@ -231,16 +232,18 @@ private void OnConfigurationOptionAdded(ReorderableList list) var index = configurations.arraySize - 1; var configuration = configurations.GetArrayElementAtIndex(index); + var nameProperty = configuration.FindPropertyRelative("name"); - var instancedTypeProperty = configuration.FindPropertyRelative("instancedType"); var priorityProperty = configuration.FindPropertyRelative("priority"); - var runtimePlatformProperty = configuration.FindPropertyRelative("runtimePlatform"); + var instancedTypeProperty = configuration.FindPropertyRelative("instancedType"); + var platformEntriesProperty = configuration.FindPropertyRelative("platformEntries"); var configurationProfileProperty = configuration.FindPropertyRelative("configurationProfile"); + var runtimePlatformsProperty = platformEntriesProperty.FindPropertyRelative("runtimePlatforms"); nameProperty.stringValue = $"New Configuration {index}"; instancedTypeProperty.FindPropertyRelative("reference").stringValue = string.Empty; priorityProperty.intValue = index; - runtimePlatformProperty.intValue = 0; + runtimePlatformsProperty.ClearArray(); configurationProfileProperty.objectReferenceValue = null; serializedObject.ApplyModifiedProperties(); diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityToolkitConfigurationProfileInspector.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityToolkitConfigurationProfileInspector.cs index 2eff3f441..692e37d5b 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityToolkitConfigurationProfileInspector.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Profiles/MixedRealityToolkitConfigurationProfileInspector.cs @@ -14,7 +14,7 @@ namespace XRTK.Inspectors.Profiles [CustomEditor(typeof(MixedRealityToolkitConfigurationProfile))] public class MixedRealityToolkitConfigurationProfileInspector : BaseMixedRealityProfileInspector { - // Camera properties + // Camera system properties private SerializedProperty enableCameraSystem; private SerializedProperty cameraSystemType; private SerializedProperty cameraProfile; @@ -86,29 +86,35 @@ protected override void OnEnable() } } - // Camera configuration + // Camera system configuration enableCameraSystem = serializedObject.FindProperty("enableCameraSystem"); cameraSystemType = serializedObject.FindProperty("cameraSystemType"); cameraProfile = serializedObject.FindProperty("cameraProfile"); + // Input system configuration enableInputSystem = serializedObject.FindProperty("enableInputSystem"); inputSystemType = serializedObject.FindProperty("inputSystemType"); inputSystemProfile = serializedObject.FindProperty("inputSystemProfile"); + // Boundary system configuration enableBoundarySystem = serializedObject.FindProperty("enableBoundarySystem"); boundarySystemType = serializedObject.FindProperty("boundarySystemType"); boundaryVisualizationProfile = serializedObject.FindProperty("boundaryVisualizationProfile"); + // Teleport system configuration enableTeleportSystem = serializedObject.FindProperty("enableTeleportSystem"); teleportSystemType = serializedObject.FindProperty("teleportSystemType"); + // Spatial Awareness system configuration enableSpatialAwarenessSystem = serializedObject.FindProperty("enableSpatialAwarenessSystem"); spatialAwarenessSystemType = serializedObject.FindProperty("spatialAwarenessSystemType"); spatialAwarenessProfile = serializedObject.FindProperty("spatialAwarenessProfile"); + // Networking system configuration enableNetworkingSystem = serializedObject.FindProperty("enableNetworkingSystem"); networkingSystemType = serializedObject.FindProperty("networkingSystemType"); networkingSystemProfile = serializedObject.FindProperty("networkingSystemProfile"); + // Diagnostics system configuration enableDiagnosticsSystem = serializedObject.FindProperty("enableDiagnosticsSystem"); diagnosticsSystemType = serializedObject.FindProperty("diagnosticsSystemType"); diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/PlatformEntryPropertyDrawer.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/PlatformEntryPropertyDrawer.cs new file mode 100644 index 000000000..a7451d397 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/PlatformEntryPropertyDrawer.cs @@ -0,0 +1,247 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using UnityEditor; +using UnityEngine; +using XRTK.Definitions; +using XRTK.Definitions.Platforms; +using XRTK.Definitions.Utilities; +using XRTK.Extensions; +using XRTK.Services; + +namespace XRTK.Inspectors.PropertyDrawers +{ + [CustomPropertyDrawer(typeof(RuntimePlatformEntry))] + public class PlatformEntryPropertyDrawer : PropertyDrawer + { + private const string Nothing = "Nothing"; + private const string TypeReferenceUpdated = "TypeReferenceUpdated"; + + private static readonly GUIContent NothingContent = new GUIContent(Nothing); + private static readonly GUIContent EverythingContent = new GUIContent("Everything"); + private static readonly GUIContent RuntimePlatformContent = new GUIContent("Runtime Platforms"); + private static readonly GUIContent TempContent = new GUIContent(); + private static readonly int ControlHint = typeof(PlatformEntryPropertyDrawer).GetHashCode(); + + private static int selectionControlId; + private static int arraySize = 0; + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + position = EditorGUI.PrefixLabel(position, RuntimePlatformContent); + + var runtimePlatformsProperty = property.FindPropertyRelative("runtimePlatforms"); + + DrawTypeSelectionControl(position, runtimePlatformsProperty); + } + + private static void DrawTypeSelectionControl(Rect position, SerializedProperty runtimePlatformsProperty) + { + var triggerDropDown = false; + var controlId = GUIUtility.GetControlID(ControlHint, FocusType.Keyboard, position); + + switch (Event.current.GetTypeForControl(controlId)) + { + case EventType.ExecuteCommand: + if (Event.current.commandName == TypeReferenceUpdated && + selectionControlId == controlId) + { + if (runtimePlatformsProperty.arraySize != arraySize) + { + GUI.changed = true; + } + + arraySize = 0; + selectionControlId = 0; + } + + break; + + case EventType.MouseDown: + if (GUI.enabled && position.Contains(Event.current.mousePosition)) + { + GUIUtility.keyboardControl = controlId; + triggerDropDown = true; + Event.current.Use(); + } + + break; + + case EventType.KeyDown: + if (GUI.enabled && GUIUtility.keyboardControl == controlId) + { + if (Event.current.keyCode == KeyCode.Return || + Event.current.keyCode == KeyCode.Space) + { + triggerDropDown = true; + Event.current.Use(); + } + } + + break; + + case EventType.Repaint: + switch (runtimePlatformsProperty.arraySize) + { + case 0: + TempContent.text = Nothing; + break; + case 1: + // Remove assembly name and namespace from content of popup control. + var systemTypeProperty = runtimePlatformsProperty.GetArrayElementAtIndex(0); + var classRefProperty = systemTypeProperty.FindPropertyRelative("reference"); + var classRefParts = classRefProperty.stringValue.Split(','); + var className = classRefParts[0].Trim(); + className = className.Substring(className.LastIndexOf(".", StringComparison.Ordinal) + 1); + TempContent.text = className.Replace("Platform", "").ToProperCase(); + + if (TempContent.text == string.Empty) + { + TempContent.text = Nothing; + } + + break; + default: + TempContent.text = runtimePlatformsProperty.arraySize == MixedRealityToolkit.AvailablePlatforms.Count ? "Everything" : "Multiple..."; + break; + } + + EditorStyles.popup.Draw(position, TempContent, controlId); + break; + } + + if (triggerDropDown) + { + arraySize = runtimePlatformsProperty.arraySize; + selectionControlId = controlId; + + var menu = new GenericMenu(); + + menu.AddItem(NothingContent, arraySize == 0, OnNothingSelected, null); + menu.AddItem(EverythingContent, arraySize == MixedRealityToolkit.AvailablePlatforms.Count, OnEverythingSelected, null); + + for (var i = 0; i < MixedRealityToolkit.AvailablePlatforms.Count; i++) + { + var platform = MixedRealityToolkit.AvailablePlatforms[i]; + var platformType = platform.GetType(); + if (platformType == typeof(AllPlatforms)) { continue; } + menu.AddItem(new GUIContent(platformType.Name.Replace("Platform", "").ToProperCase()), IsPlatformActive(platformType), OnSelectedTypeName, platformType); + } + + menu.DropDown(position); + + void OnNothingSelected(object _) + { + runtimePlatformsProperty.ClearArray(); + runtimePlatformsProperty.serializedObject.ApplyModifiedProperties(); + EditorWindow.focusedWindow.SendEvent(EditorGUIUtility.CommandEvent(TypeReferenceUpdated)); + } + + void OnEverythingSelected(object _) + { + runtimePlatformsProperty.ClearArray(); + + for (int i = 0; i < MixedRealityToolkit.AvailablePlatforms.Count; i++) + { + AddPlatformReference(SystemType.GetReference(MixedRealityToolkit.AvailablePlatforms[i].GetType())); + } + + runtimePlatformsProperty.serializedObject.ApplyModifiedProperties(); + EditorWindow.focusedWindow.SendEvent(EditorGUIUtility.CommandEvent(TypeReferenceUpdated)); + } + + void OnSelectedTypeName(object typeRef) + { + var selectedPlatformType = typeRef as Type; + var selectedReference = SystemType.GetReference(selectedPlatformType); + + if (!TryRemovePlatformReference(selectedReference)) + { + if (selectedPlatformType != null) + { + AddPlatformReference(selectedReference); + } + + if (runtimePlatformsProperty.arraySize + 1 == MixedRealityToolkit.AvailablePlatforms.Count) + { + AddPlatformReference(SystemType.GetReference(typeof(AllPlatforms))); + } + } + + EditorWindow.focusedWindow.SendEvent(EditorGUIUtility.CommandEvent(TypeReferenceUpdated)); + } + + bool IsPlatformActive(Type platformType) + { + for (int i = 0; i < runtimePlatformsProperty.arraySize; i++) + { + var systemTypeProperty = runtimePlatformsProperty.GetArrayElementAtIndex(i); + var referenceProperty = systemTypeProperty.FindPropertyRelative("reference"); + var referenceType = TypeExtensions.ResolveType(referenceProperty.stringValue); + + // Clean up any broken references + if (referenceType == null) + { + Debug.LogError($"Failed to resolve {referenceProperty.stringValue}! Removing from runtime platform entry..."); + runtimePlatformsProperty.DeleteArrayElementAtIndex(i); + runtimePlatformsProperty.serializedObject.ApplyModifiedProperties(); + continue; + } + + if (platformType == referenceType) + { + return true; + } + } + + return false; + } + + void AddPlatformReference(string classReference) + { + var index = runtimePlatformsProperty.arraySize; + runtimePlatformsProperty.serializedObject.ApplyModifiedProperties(); + runtimePlatformsProperty.InsertArrayElementAtIndex(index); + var systemTypeProperty = runtimePlatformsProperty.GetArrayElementAtIndex(index); + var referenceProperty = systemTypeProperty.FindPropertyRelative("reference"); + referenceProperty.stringValue = classReference; + runtimePlatformsProperty.serializedObject.ApplyModifiedProperties(); + } + + bool TryRemovePlatformReference(string classReference) + { + var selectedPlatformType = TypeExtensions.ResolveType(classReference); + + for (int i = 0; i < runtimePlatformsProperty.arraySize; i++) + { + var systemTypeProperty = runtimePlatformsProperty.GetArrayElementAtIndex(i); + var referenceProperty = systemTypeProperty.FindPropertyRelative("reference"); + var referenceType = TypeExtensions.ResolveType(referenceProperty.stringValue); + + if (selectedPlatformType == referenceType) + { + bool removeEveryPlatform = selectedPlatformType != typeof(AllPlatforms) && + runtimePlatformsProperty.arraySize == MixedRealityToolkit.AvailablePlatforms.Count; + + runtimePlatformsProperty.DeleteArrayElementAtIndex(i); + + if (removeEveryPlatform) + { + TryRemovePlatformReference(SystemType.GetReference(typeof(AllPlatforms))); + } + else + { + runtimePlatformsProperty.serializedObject.ApplyModifiedProperties(); + } + + return true; + } + } + + return false; + } + } + } + } +} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/PlatformEntryPropertyDrawer.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/PlatformEntryPropertyDrawer.cs.meta new file mode 100644 index 000000000..d8bad542f --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/PlatformEntryPropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5ef89bb003493bf4eb541140f8e5ae8f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/TypeReferencePropertyDrawer.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/TypeReferencePropertyDrawer.cs index 9d54cbcbd..ffad6814b 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/TypeReferencePropertyDrawer.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/PropertyDrawers/TypeReferencePropertyDrawer.cs @@ -9,6 +9,7 @@ using UnityEngine; using XRTK.Attributes; using XRTK.Definitions.Utilities; +using XRTK.Extensions; using Assembly = System.Reflection.Assembly; namespace XRTK.Inspectors.PropertyDrawers @@ -26,7 +27,6 @@ public class TypeReferencePropertyDrawer : PropertyDrawer private static int selectionControlId; private static string selectedReference; - private static readonly Dictionary TypeMap = new Dictionary(); private static readonly int ControlHint = typeof(TypeReferencePropertyDrawer).GetHashCode(); private static readonly GUIContent TempContent = new GUIContent(); private static readonly GUIContent RepairContent = new GUIContent("Repair", "Try to repair the reference"); @@ -136,21 +136,6 @@ where type.IsVisible && isValid #endregion Type Filtering - #region Type Utility - - private static Type ResolveType(string classRef) - { - if (!TypeMap.TryGetValue(classRef, out var type)) - { - type = !string.IsNullOrEmpty(classRef) ? Type.GetType(classRef) : null; - TypeMap[classRef] = type; - } - - return type; - } - - #endregion Type Utility - #region Control Drawing / Event Handling /// @@ -232,7 +217,7 @@ private static void DrawTypeSelectionControl(Rect position, GUIContent label, re selectionControlId = controlId; selectedReference = classRef; - DisplayDropDown(position, GetFilteredTypes(filter), ResolveType(classRef), filter?.Grouping ?? TypeGrouping.ByNamespaceFlat); + DisplayDropDown(position, GetFilteredTypes(filter), TypeExtensions.ResolveType(classRef), filter?.Grouping ?? TypeGrouping.ByNamespaceFlat); } } @@ -255,7 +240,7 @@ private static void DrawTypeSelectionControl(Rect position, SerializedProperty s var restoreColor = GUI.color; var reference = referenceProperty.stringValue; var restoreShowMixedValue = EditorGUI.showMixedValue; - var isValidClassRef = string.IsNullOrEmpty(reference) || ResolveType(reference) != null; + var isValidClassRef = string.IsNullOrEmpty(reference) || TypeExtensions.ResolveType(reference) != null; if (!isValidClassRef) { @@ -411,11 +396,10 @@ private static string FormatGroupedTypeName(Type type, TypeGrouping grouping) } } - private static void OnSelectedTypeName(object userData) + private static void OnSelectedTypeName(object typeRef) { - selectedReference = SystemType.GetReference(userData as Type); - var typeReferenceUpdatedEvent = EditorGUIUtility.CommandEvent(TypeReferenceUpdated); - EditorWindow.focusedWindow.SendEvent(typeReferenceUpdatedEvent); + selectedReference = SystemType.GetReference(typeRef as Type); + EditorWindow.focusedWindow.SendEvent(EditorGUIUtility.CommandEvent(TypeReferenceUpdated)); } #endregion Control Drawing / Event Handling diff --git a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Utilities/MixedRealityInspectorUtility.cs b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Utilities/MixedRealityInspectorUtility.cs index 6a8a5c90d..18cd59fff 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Inspectors/Utilities/MixedRealityInspectorUtility.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Inspectors/Utilities/MixedRealityInspectorUtility.cs @@ -8,9 +8,7 @@ using UnityEditor; using UnityEngine; using XRTK.Definitions; -using XRTK.Definitions.Utilities; using XRTK.Services; -using XRTK.Utilities; using XRTK.Utilities.Editor; using Object = UnityEngine.Object; @@ -188,27 +186,6 @@ public static void CheckProfileLock(this BaseMixedRealityProfile target, bool di } } - /// - /// Checks if the profile can be inspected with the currently active build target and renders - /// a hint to switch build target if not. - /// - /// The supported platforms by the profile. - /// Optional info text to override info box text. - /// True, if the profile and the active build target match. - public static bool CheckProfilePlatform(SupportedPlatforms supportedPlatforms, string infoText = null) - { - if (!PlatformUtility.IsPlatformSupported(EditorUserBuildSettings.activeBuildTarget, supportedPlatforms)) - { - EditorGUILayout.HelpBox(string.IsNullOrWhiteSpace(infoText) ? - $"You can't edit this profile with the current build target. Please switch to {supportedPlatforms}." - : infoText, MessageType.Info); - - return false; - } - - return true; - } - #endregion Utilities #region Gizmos diff --git a/XRTK-Core/Packages/com.xrtk.core/Interfaces/IMixedRealityPlatform.cs b/XRTK-Core/Packages/com.xrtk.core/Interfaces/IMixedRealityPlatform.cs new file mode 100644 index 000000000..12e72e2f6 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Interfaces/IMixedRealityPlatform.cs @@ -0,0 +1,16 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace XRTK.Interfaces +{ + /// + /// Defines the platform to be registered + /// + public interface IMixedRealityPlatform + { + /// + /// Is this platform currently available? + /// + bool IsAvailable { get; } + } +} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Interfaces/IMixedRealityPlatform.cs.meta b/XRTK-Core/Packages/com.xrtk.core/Interfaces/IMixedRealityPlatform.cs.meta new file mode 100644 index 000000000..f2edf1e28 --- /dev/null +++ b/XRTK-Core/Packages/com.xrtk.core/Interfaces/IMixedRealityPlatform.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c4270f975d5bbc04ea83c7a6413898eb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/XRTK-Core/Packages/com.xrtk.core/Interfaces/IMixedRealityServiceConfiguration.cs b/XRTK-Core/Packages/com.xrtk.core/Interfaces/IMixedRealityServiceConfiguration.cs index a4e3bb8b1..1c4fbdc5b 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Interfaces/IMixedRealityServiceConfiguration.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Interfaces/IMixedRealityServiceConfiguration.cs @@ -1,6 +1,7 @@ // Copyright (c) XRTK. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. +using System.Collections.Generic; using XRTK.Definitions; using XRTK.Definitions.Utilities; using XRTK.Services; @@ -26,6 +27,14 @@ public interface IMixedRealityServiceConfiguration /// SystemType InstancedType { get; } + /// + /// The simple, human readable name for the . + /// + /// + /// This name should be unique. + /// + string Name { get; } + /// /// The priority order of execution for this . /// @@ -37,19 +46,11 @@ public interface IMixedRealityServiceConfiguration /// /// The runtime platform(s) to run this to run on. /// - SupportedPlatforms RuntimePlatform { get; } + IReadOnlyList RuntimePlatforms { get; } /// /// The configuration profile for the . /// BaseMixedRealityProfile ConfigurationProfile { get; } - - /// - /// The simple, human readable name for the . - /// - /// - /// This name should be unique. - /// - string Name { get; } } } \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Services/MixedRealityToolkit.cs b/XRTK-Core/Packages/com.xrtk.core/Services/MixedRealityToolkit.cs index 347846a58..43748d86f 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Services/MixedRealityToolkit.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Services/MixedRealityToolkit.cs @@ -7,7 +7,7 @@ using UnityEngine; using UnityEngine.EventSystems; using XRTK.Definitions; -using XRTK.Definitions.Utilities; +using XRTK.Definitions.Platforms; using XRTK.Extensions; using XRTK.Interfaces; using XRTK.Interfaces.BoundarySystem; @@ -129,6 +129,22 @@ public void ResetConfiguration(MixedRealityToolkitConfigurationProfile profile) #region Mixed Reality runtime service registry + // ReSharper disable once InconsistentNaming + private static readonly List availablePlatforms = new List(); + + /// + /// The list of active platforms detected by the . + /// + public static IReadOnlyList AvailablePlatforms => availablePlatforms; + + // ReSharper disable once InconsistentNaming + private static readonly List activePlatforms = new List(); + + /// + /// The list of active platforms detected by the . + /// + public static IReadOnlyList ActivePlatforms => activePlatforms; + // ReSharper disable once InconsistentNaming private static readonly Dictionary activeSystems = new Dictionary(); @@ -283,6 +299,7 @@ void OnPlayModeStateChanged(UnityEditor.PlayModeStateChange playModeState) if (HasActiveProfile) { + EnsureMixedRealityRequirements(); InitializeServiceLocator(); } } @@ -324,6 +341,8 @@ public static bool ConfirmInitialized() return IsInitialized; } + #endregion Instance Management + /// /// Once all services are registered and properties updated, the Mixed Reality Toolkit will initialize all active services. /// This ensures all services can reference each other once started. @@ -362,16 +381,14 @@ private void InitializeServiceLocator() Debug.Assert(RegisteredMixedRealityServices.Count == 0); ClearCoreSystemCache(); - EnsureMixedRealityRequirements(); #region Services Registration if (ActiveProfile.IsCameraSystemEnabled && - (!CreateAndRegisterService(ActiveProfile.CameraSystemType, ActiveProfile.CameraProfile) || CameraSystem == null)) + (!CreateAndRegisterService(ActiveProfile.CameraSystemType, ActiveProfile.CameraProfile) || + CameraSystem == null)) { Debug.LogError("Failed to start the Camera System!"); - isInitializing = false; - return; } if (ActiveProfile.IsInputSystemEnabled) @@ -528,6 +545,37 @@ private void InitializeServiceLocator() private static void EnsureMixedRealityRequirements() { + activePlatforms.Clear(); + availablePlatforms.Clear(); + + var platformTypes = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(assembly => assembly.GetTypes()) + .Where(type => typeof(IMixedRealityPlatform).IsAssignableFrom(type) && type.IsClass && !type.IsAbstract) + .OrderBy(type => type.Name); + + foreach (var platformType in platformTypes) + { + IMixedRealityPlatform platformInstance = null; + + try + { + platformInstance = Activator.CreateInstance(platformType) as IMixedRealityPlatform; + } + catch (Exception e) + { + Debug.LogError(e); + } + + if (platformInstance == null) { continue; } + + availablePlatforms.Add(platformInstance); + + if (platformInstance.IsAvailable) + { + activePlatforms.Add(platformInstance); + } + } + // There's lots of documented cases that if the camera doesn't start at 0,0,0, things break with the WMR SDK specifically. // We'll enforce that here, then tracking can update it to the appropriate position later. CameraCache.Main.transform.position = Vector3.zero; @@ -569,8 +617,6 @@ private static void EnsureMixedRealityRequirements() } } - #endregion Instance Management - #region MonoBehaviour Implementation #if UNITY_EDITOR @@ -764,7 +810,7 @@ public static bool CreateAndRegisterService(IMixedRealityServiceConfiguration { return CreateAndRegisterService( configuration.InstancedType, - configuration.RuntimePlatform, + configuration.RuntimePlatforms, configuration.Name, configuration.Priority, configuration.ConfigurationProfile); @@ -779,33 +825,58 @@ public static bool CreateAndRegisterService(IMixedRealityServiceConfiguration /// True, if the service was successfully created and registered. public static bool CreateAndRegisterService(Type concreteType, params object[] args) where T : IMixedRealityService { - return CreateAndRegisterService(concreteType, (SupportedPlatforms)(-1), args); + return CreateAndRegisterService(concreteType, AllPlatforms, args); } + private static readonly IMixedRealityPlatform[] AllPlatforms = { new AllPlatforms() }; + /// /// Creates a new instance of a service and registers it to the Mixed Reality Toolkit service registry for the specified platform. /// /// The interface type for the system to be registered. /// The concrete type to instantiate. - /// The runtime platform to check against when registering. + /// The runtime platform to check against when registering. /// Optional arguments used when instantiating the concrete type. /// True, if the service was successfully created and registered. - public static bool CreateAndRegisterService(Type concreteType, SupportedPlatforms supportedPlatforms, params object[] args) where T : IMixedRealityService + public static bool CreateAndRegisterService(Type concreteType, IReadOnlyList runtimePlatforms, params object[] args) where T : IMixedRealityService { if (IsApplicationQuitting) { return false; } -#if !UNITY_EDITOR - if (!Application.platform.IsPlatformSupported(supportedPlatforms)) -#else - if (!UnityEditor.EditorUserBuildSettings.activeBuildTarget.IsPlatformSupported(supportedPlatforms)) -#endif + bool canRunOnPlatform = false; + + for (var i = 0; i < runtimePlatforms?.Count; i++) + { + for (var j = 0; j < ActivePlatforms.Count; j++) + { + if (ActivePlatforms[j].GetType() == runtimePlatforms[i].GetType()) + { + canRunOnPlatform = true; + break; + } + } + + if (canRunOnPlatform) + { + break; + } + } + + if (!canRunOnPlatform) { // We return true so we don't raise en error. // Even though we did not register the service, - // it's expected that this is the intended behavior. + // it's expected that this is the intended behavior + // when there isn't a valid platform to run the service on. + + if (runtimePlatforms == null || + runtimePlatforms.Count == 0) + { + Debug.LogWarning($"No runtime platforms defined for the {concreteType?.Name} service."); + } + return true; } @@ -1439,11 +1510,17 @@ public static bool IsServiceRegistered() where T : IMixedRealityService /// /// Note: type should be the Interface of the system to be retrieved and not the concrete class itself. /// - /// True, there is a system registered with the selected interface, False, no system found for that interface - /// Type is . + /// True, there is a system registered with the selected interface, False, no system found for that interface. public static bool IsSystemRegistered() where T : IMixedRealityService { - return activeSystems.TryGetValue(typeof(T), out _); + try + { + return activeSystems.TryGetValue(typeof(T), out _); + } + catch (Exception) + { + return false; + } } private static bool IsCoreSystem(Type concreteType) @@ -1714,7 +1791,7 @@ public static IMixedRealityCameraSystem CameraSystem if (!IsInitialized || IsApplicationQuitting || instance.activeProfile == null || - (instance.activeProfile != null && !instance.activeProfile.IsCameraSystemEnabled)) + instance.activeProfile != null && !instance.activeProfile.IsCameraSystemEnabled) { return null; } @@ -1746,7 +1823,7 @@ public static IMixedRealityInputSystem InputSystem if (!IsInitialized || IsApplicationQuitting || instance.activeProfile == null || - (instance.activeProfile != null && !instance.activeProfile.IsInputSystemEnabled)) + instance.activeProfile != null && !instance.activeProfile.IsInputSystemEnabled) { return null; } @@ -1778,7 +1855,7 @@ public static IMixedRealityBoundarySystem BoundarySystem if (!IsInitialized || IsApplicationQuitting || instance.activeProfile == null || - (instance.activeProfile != null && !instance.activeProfile.IsBoundarySystemEnabled)) + instance.activeProfile != null && !instance.activeProfile.IsBoundarySystemEnabled) { return null; } @@ -1810,7 +1887,7 @@ public static IMixedRealitySpatialAwarenessSystem SpatialAwarenessSystem if (!IsInitialized || IsApplicationQuitting || instance.activeProfile == null || - (instance.activeProfile != null && !instance.activeProfile.IsSpatialAwarenessSystemEnabled)) + instance.activeProfile != null && !instance.activeProfile.IsSpatialAwarenessSystemEnabled) { return null; } @@ -1842,7 +1919,7 @@ public static IMixedRealityTeleportSystem TeleportSystem if (!IsInitialized || IsApplicationQuitting || instance.activeProfile == null || - (instance.activeProfile != null && !instance.activeProfile.IsTeleportSystemEnabled)) + instance.activeProfile != null && !instance.activeProfile.IsTeleportSystemEnabled) { return null; } @@ -1874,7 +1951,7 @@ public static IMixedRealityNetworkingSystem NetworkingSystem if (!IsInitialized || IsApplicationQuitting || instance.activeProfile == null || - (instance.activeProfile != null && !instance.activeProfile.IsNetworkingSystemEnabled)) + instance.activeProfile != null && !instance.activeProfile.IsNetworkingSystemEnabled) { return null; } @@ -1906,7 +1983,7 @@ public static IMixedRealityDiagnosticsSystem DiagnosticsSystem if (!IsInitialized || IsApplicationQuitting || instance.activeProfile == null || - (instance.activeProfile != null && !instance.activeProfile.IsDiagnosticsSystemEnabled)) + instance.activeProfile != null && !instance.activeProfile.IsDiagnosticsSystemEnabled) { return null; } @@ -1937,6 +2014,9 @@ public static IMixedRealityDiagnosticsSystem DiagnosticsSystem OnDispose(true); } + /// + /// Dispose the object. + /// public void Dispose() { if (disposed) { return; } diff --git a/XRTK-Core/Packages/com.xrtk.core/Utilities/PlatformUtility.cs b/XRTK-Core/Packages/com.xrtk.core/Utilities/PlatformUtility.cs deleted file mode 100644 index 2ea481e80..000000000 --- a/XRTK-Core/Packages/com.xrtk.core/Utilities/PlatformUtility.cs +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See LICENSE in the project root for license information. - -using UnityEngine; -using XRTK.Definitions.Utilities; - -namespace XRTK.Utilities -{ - public static class PlatformUtility - { - /// - /// Checks to see if the is part of the - /// - /// - /// - /// True, if the runtime platform is included in the list of supported platforms, otherwise false. - public static bool IsPlatformSupported(this RuntimePlatform runtimePlatform, SupportedPlatforms platforms) - { - if ((int)platforms == -1) - { - return true; - } - - if (platforms == 0) - { - return false; - } - - var target = GetSupportedPlatformMask(runtimePlatform); - return IsPlatformSupported(target, platforms); - } - - private static SupportedPlatforms GetSupportedPlatformMask(RuntimePlatform runtimePlatform) - { - SupportedPlatforms supportedPlatforms = 0; - - switch (runtimePlatform) - { - case RuntimePlatform.Android: - supportedPlatforms |= SupportedPlatforms.Android; - break; - case RuntimePlatform.IPhonePlayer: - supportedPlatforms |= SupportedPlatforms.iOS; - break; - case RuntimePlatform.WindowsPlayer: - case RuntimePlatform.WindowsEditor: - supportedPlatforms |= SupportedPlatforms.WindowsStandalone; - break; - case RuntimePlatform.WSAPlayerARM: - case RuntimePlatform.WSAPlayerX86: - case RuntimePlatform.WSAPlayerX64: - case RuntimePlatform.XboxOne: - supportedPlatforms |= SupportedPlatforms.WindowsUniversal; - break; - case RuntimePlatform.OSXPlayer: - case RuntimePlatform.OSXEditor: - supportedPlatforms |= SupportedPlatforms.MacStandalone; - break; - case RuntimePlatform.LinuxPlayer: - case RuntimePlatform.LinuxEditor: - supportedPlatforms |= SupportedPlatforms.LinuxStandalone; - break; - case RuntimePlatform.Lumin: - supportedPlatforms |= SupportedPlatforms.Lumin; - break; - } - - return supportedPlatforms; - } - - private static bool IsPlatformSupported(SupportedPlatforms target, SupportedPlatforms supported) - { - return (target & supported) != 0; - } - -#if UNITY_EDITOR - - /// - /// Checks to see if the is part of the - /// - /// - /// - /// True, if the runtime platform is included in the list of supported platforms, otherwise false. - public static bool IsPlatformSupported(this UnityEditor.BuildTarget editorBuildTarget, SupportedPlatforms platforms) - { - var isEditorSupported = IsEditorSupported(platforms); - - // If any platform set or if only the editor flag is set - if ((int)platforms == -1 || platforms == SupportedPlatforms.Editor) - { - return true; - } - - // If no platform set or if the editor is not supported - if (platforms == 0 || !isEditorSupported) - { - return false; - } - - // If editor is supported and the current build target is enabled - var target = GetSupportedPlatformMask(editorBuildTarget); - return IsPlatformSupported(target, platforms); - } - - private static bool IsEditorSupported(SupportedPlatforms platforms) - { - return (platforms & SupportedPlatforms.Editor) != 0; - } - - private static SupportedPlatforms GetSupportedPlatformMask(UnityEditor.BuildTarget editorBuildTarget) - { - SupportedPlatforms supportedPlatforms = 0; - - switch (editorBuildTarget) - { - case UnityEditor.BuildTarget.Android: - supportedPlatforms |= SupportedPlatforms.Android; - break; - case UnityEditor.BuildTarget.iOS: - supportedPlatforms |= SupportedPlatforms.iOS; - break; - case UnityEditor.BuildTarget.StandaloneWindows: - case UnityEditor.BuildTarget.StandaloneWindows64: - supportedPlatforms |= SupportedPlatforms.WindowsStandalone; - break; - case UnityEditor.BuildTarget.WSAPlayer: - case UnityEditor.BuildTarget.XboxOne: - supportedPlatforms |= SupportedPlatforms.WindowsUniversal; - break; - case UnityEditor.BuildTarget.StandaloneOSX: - supportedPlatforms |= SupportedPlatforms.MacStandalone; - break; - case UnityEditor.BuildTarget.StandaloneLinux64: - supportedPlatforms |= SupportedPlatforms.LinuxStandalone; - break; - case UnityEditor.BuildTarget.Lumin: - supportedPlatforms |= SupportedPlatforms.Lumin; - break; - } - - return supportedPlatforms; - } -#endif - } -} \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/package.json b/XRTK-Core/Packages/com.xrtk.core/package.json index b97ccc262..1bcbdfa03 100644 --- a/XRTK-Core/Packages/com.xrtk.core/package.json +++ b/XRTK-Core/Packages/com.xrtk.core/package.json @@ -10,7 +10,7 @@ "Mixed Reality", "DI" ], - "version": "0.1.31", + "version": "0.1.32", "unity": "2019.1", "license": "MIT", "author": "XRTK Team (https://github.com/XRTK)",