From c6ebadb0d01509f41bed2906f72e31c2493b7e9c Mon Sep 17 00:00:00 2001 From: Stephen Hodgson Date: Thu, 24 Dec 2020 16:54:26 -0500 Subject: [PATCH] Fixed issue where configuration would lose the runtime platform types when installed (#741) * Fixed issue where platform configuration would lost runtime platform types when installed * unselect any object before attempting to install --- Editor/PackageInstaller.cs | 69 ++++++++----------- .../MixedRealityServiceConfiguration.cs | 29 ++++---- 2 files changed, 46 insertions(+), 52 deletions(-) diff --git a/Editor/PackageInstaller.cs b/Editor/PackageInstaller.cs index 9df935666..62cb43230 100644 --- a/Editor/PackageInstaller.cs +++ b/Editor/PackageInstaller.cs @@ -122,7 +122,12 @@ public static bool TryInstallAssets(Dictionary installationPaths if (!Application.isBatchMode) { - EditorApplication.delayCall += () => AddConfigurations(installedAssets); + EditorApplication.delayCall += () => + { + AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); + EditorApplication.delayCall += () => + AddConfigurations(installedAssets); + }; } EditorUtility.ClearProgressBar(); @@ -131,14 +136,28 @@ public static bool TryInstallAssets(Dictionary installationPaths private static void AddConfigurations(List profiles) { - AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); + MixedRealityToolkitRootProfile rootProfile; + + if (MixedRealityToolkit.IsInitialized) + { + rootProfile = MixedRealityToolkit.Instance.ActiveProfile; + } + else + { + var availableRootProfiles = ScriptableObjectExtensions.GetAllInstances(); + rootProfile = availableRootProfiles.Length > 0 ? availableRootProfiles[0] : null; + } - //Clear the selection to ensure the inspector does not cause errors, Empty try catch to avoid Unity crashing when Selection is null - try + // Only if a root profile is available at all it makes sense to display the + // platform configuration import dialog. If the user does not have a root profile yet, + // for whatever reason, there is nothing we can do here. + if (rootProfile.IsNull()) { - Selection.activeObject = null; + EditorUtility.DisplayDialog("Attention!", "Each data provider will need to be manually registered in each service configuration.", "OK"); + return; } - catch { } + + Selection.activeObject = null; foreach (var profile in profiles.Where(x => x.EndsWith(".asset"))) { @@ -146,33 +165,12 @@ private static void AddConfigurations(List profiles) if (platformConfigurationProfile.IsNull()) { continue; } - MixedRealityToolkitRootProfile rootProfile; - if (MixedRealityToolkit.IsInitialized) - { - rootProfile = MixedRealityToolkit.Instance.ActiveProfile; - } - else - { - var availableRootProfiles = ScriptableObjectExtensions.GetAllInstances(); - rootProfile = availableRootProfiles.Length > 0 ? availableRootProfiles[0] : null; - } - - // Only if a root profile is available at all it makes sense to display the - // platform configuration import dialog. If the user does not have a root profile yet, - // for whatever reason, there is nothing we can do here. - if (!rootProfile.IsNull()) + if (EditorUtility.DisplayDialog("We found a new Platform Configuration", + $"We found the {platformConfigurationProfile.name.ToProperCase()}. Would you like to add this platform configuration to your {nameof(MixedRealityToolkitRootProfile)}?", + "Yes, Absolutely!", + "later")) { - if (EditorUtility.DisplayDialog("We found a new Platform Configuration", - $"We found the {platformConfigurationProfile.name.ToProperCase()}. Would you like to add this platform configuration to your {rootProfile.name}?", - "Yes, Absolutely!", - "later")) - { - InstallConfiguration(platformConfigurationProfile, rootProfile); - } - else - { - EditorUtility.DisplayDialog("Attention!", "Each data provider will need to be manually registered in each service configuration.", "OK"); - } + InstallConfiguration(platformConfigurationProfile, rootProfile); } } } @@ -200,13 +198,6 @@ private static string CopyAsset(this string rootPath, string sourceAssetPath, st /// The root profile to install the public static void InstallConfiguration(MixedRealityPlatformServiceConfigurationProfile platformConfigurationProfile, MixedRealityToolkitRootProfile rootProfile) { - //Clear the selection to ensure the inspector does not cause errors, Empty try catch to avoid Unity crashing when Selection is null - try - { - Selection.activeObject = null; - } - catch { } - foreach (var configuration in platformConfigurationProfile.Configurations) { var configurationType = configuration.InstancedType.Type; diff --git a/Runtime/Definitions/MixedRealityServiceConfiguration.cs b/Runtime/Definitions/MixedRealityServiceConfiguration.cs index dd272a992..eab18f5f1 100644 --- a/Runtime/Definitions/MixedRealityServiceConfiguration.cs +++ b/Runtime/Definitions/MixedRealityServiceConfiguration.cs @@ -111,25 +111,28 @@ public IReadOnlyList RuntimePlatforms { runtimePlatforms = new List(); - for (int i = 0; i < MixedRealityToolkit.AvailablePlatforms.Count; i++) + for (int i = 0; i < platformEntries?.RuntimePlatforms?.Length; i++) { - var availablePlatform = MixedRealityToolkit.AvailablePlatforms[i]; - var availablePlatformType = availablePlatform.GetType(); + var platformType = platformEntries.RuntimePlatforms[i]?.Type; - for (int j = 0; j < platformEntries?.RuntimePlatforms?.Length; j++) + if (platformType == null) { - var platformType = platformEntries.RuntimePlatforms[j]?.Type; + continue; + } - if (platformType == null) - { - continue; - } + IMixedRealityPlatform platformInstance; - if (availablePlatformType == platformType) - { - runtimePlatforms.Add(availablePlatform); - } + try + { + platformInstance = Activator.CreateInstance(platformType) as IMixedRealityPlatform; } + catch (Exception e) + { + Debug.LogError(e); + continue; + } + + runtimePlatforms.Add(platformInstance); } }