Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Fixed issue where configuration would lose the runtime platform types…
Browse files Browse the repository at this point in the history
… when installed (#741)

* Fixed issue where platform configuration would lost runtime platform types when installed

* unselect any object before attempting to install
  • Loading branch information
StephenHodgson authored Dec 24, 2020
1 parent e18b4aa commit c6ebadb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 52 deletions.
69 changes: 30 additions & 39 deletions Editor/PackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ public static bool TryInstallAssets(Dictionary<string, string> installationPaths

if (!Application.isBatchMode)
{
EditorApplication.delayCall += () => AddConfigurations(installedAssets);
EditorApplication.delayCall += () =>
{
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
EditorApplication.delayCall += () =>
AddConfigurations(installedAssets);
};
}

EditorUtility.ClearProgressBar();
Expand All @@ -131,48 +136,41 @@ public static bool TryInstallAssets(Dictionary<string, string> installationPaths

private static void AddConfigurations(List<string> profiles)
{
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
MixedRealityToolkitRootProfile rootProfile;

if (MixedRealityToolkit.IsInitialized)
{
rootProfile = MixedRealityToolkit.Instance.ActiveProfile;
}
else
{
var availableRootProfiles = ScriptableObjectExtensions.GetAllInstances<MixedRealityToolkitRootProfile>();
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")))
{
var platformConfigurationProfile = AssetDatabase.LoadAssetAtPath<MixedRealityPlatformServiceConfigurationProfile>(profile);

if (platformConfigurationProfile.IsNull()) { continue; }

MixedRealityToolkitRootProfile rootProfile;
if (MixedRealityToolkit.IsInitialized)
{
rootProfile = MixedRealityToolkit.Instance.ActiveProfile;
}
else
{
var availableRootProfiles = ScriptableObjectExtensions.GetAllInstances<MixedRealityToolkitRootProfile>();
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);
}
}
}
Expand Down Expand Up @@ -200,13 +198,6 @@ private static string CopyAsset(this string rootPath, string sourceAssetPath, st
/// <param name="rootProfile">The root profile to install the </param>
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;
Expand Down
29 changes: 16 additions & 13 deletions Runtime/Definitions/MixedRealityServiceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,28 @@ public IReadOnlyList<IMixedRealityPlatform> RuntimePlatforms
{
runtimePlatforms = new List<IMixedRealityPlatform>();

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);
}
}

Expand Down

0 comments on commit c6ebadb

Please sign in to comment.