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

Commit

Permalink
Fix/package installer (#788)
Browse files Browse the repository at this point in the history
* try to change to forward slash as early as possible

* fixed platform data provider instalation before configuration is initialized

* fixed windows speech data provider NRE on initialization

* fixed system profiles not getting the correct profile type check

* cleaned up ordering and make sure to re-initialize after a user drags the list

* updated package version

* updated sdk checkout

* better runtime platform check

* switched the project back to DirectX rendering pipeline on windows standalone

* added UserSettings/ to gitignore
  • Loading branch information
StephenHodgson authored Feb 14, 2021
1 parent aeb252f commit 9bb9766
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 52 deletions.
36 changes: 25 additions & 11 deletions Editor/PackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace XRTK.Editor
{
public static class PackageInstaller
{
private static string ProjectRootPath => Directory.GetParent(Application.dataPath).FullName.ToForwardSlashes();

/// <summary>
/// Attempt to copy any assets found in the source path into the project.
/// </summary>
Expand Down Expand Up @@ -52,8 +54,8 @@ public static bool TryInstallAssets(Dictionary<string, string> installationPaths

foreach (var installationPath in installationPaths)
{
var sourcePath = installationPath.Key;
var destinationPath = installationPath.Value;
var sourcePath = installationPath.Key.ToForwardSlashes();
var destinationPath = installationPath.Value.ToForwardSlashes();
installedDirectories.Add(destinationPath);

if (Directory.Exists(destinationPath))
Expand All @@ -66,7 +68,7 @@ public static bool TryInstallAssets(Dictionary<string, string> installationPaths
for (int i = 0; i < installedAssets.Count; i++)
{
EditorUtility.DisplayProgressBar("Verifying assets...", Path.GetFileNameWithoutExtension(installedAssets[i]), i / (float)installedAssets.Count);
installedAssets[i] = installedAssets[i].Replace($"{Directory.GetParent(Application.dataPath).FullName}\\", string.Empty).ToForwardSlashes();
installedAssets[i] = installedAssets[i].Replace($"{ProjectRootPath}\\", string.Empty).ToForwardSlashes();
}

EditorUtility.ClearProgressBar();
Expand Down Expand Up @@ -171,7 +173,8 @@ private static void AddConfigurations(List<string> profiles)
if (platformConfigurationProfile.IsNull()) { continue; }

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)}?",
// ReSharper disable once PossibleNullReferenceException
$"We found the {platformConfigurationProfile.name.ToProperCase()}. Would you like to add this platform configuration to your {rootProfile.name}?",
"Yes, Absolutely!",
"later"))
{
Expand All @@ -184,16 +187,27 @@ private static string CopyAsset(this string rootPath, string sourceAssetPath, st
{
sourceAssetPath = sourceAssetPath.ToForwardSlashes();
destinationPath = $"{destinationPath}{sourceAssetPath.Replace(Path.GetFullPath(rootPath), string.Empty)}".ToForwardSlashes();
destinationPath = Path.Combine(Directory.GetParent(Application.dataPath).FullName, destinationPath).ToForwardSlashes();
destinationPath = Path.Combine(ProjectRootPath, destinationPath).ToForwardSlashes();

if (!File.Exists(destinationPath))
{
Directory.CreateDirectory(Directory.GetParent(destinationPath).FullName);
if (!Directory.Exists(Directory.GetParent(destinationPath).FullName))
{
Directory.CreateDirectory(Directory.GetParent(destinationPath).FullName);
}

File.Copy(sourceAssetPath, destinationPath);
try
{
File.Copy(sourceAssetPath, destinationPath);
}
catch
{
Debug.LogError($"$Failed to copy asset!\n{sourceAssetPath}\n{destinationPath}");
throw;
}
}

return destinationPath.Replace($"{Directory.GetParent(Application.dataPath).FullName}\\", string.Empty);
return destinationPath.Replace($"{ProjectRootPath}\\", string.Empty);
}

/// <summary>
Expand All @@ -216,7 +230,7 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration
switch (configurationType)
{
case Type _ when typeof(IMixedRealityCameraDataProvider).IsAssignableFrom(configurationType):
if (MixedRealityToolkit.TryGetSystemProfile<IMixedRealityCameraSystem, MixedRealityCameraSystemProfile>(out var cameraSystemProfile))
if (MixedRealityToolkit.TryGetSystemProfile<IMixedRealityCameraSystem, MixedRealityCameraSystemProfile>(out var cameraSystemProfile, rootProfile))
{
var cameraDataProviderConfiguration = new MixedRealityServiceConfiguration<IMixedRealityCameraDataProvider>(configuration);

Expand All @@ -230,7 +244,7 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration
break;

case Type _ when typeof(IMixedRealityInputDataProvider).IsAssignableFrom(configurationType):
if (MixedRealityToolkit.TryGetSystemProfile<IMixedRealityInputSystem, MixedRealityInputSystemProfile>(out var inputSystemProfile))
if (MixedRealityToolkit.TryGetSystemProfile<IMixedRealityInputSystem, MixedRealityInputSystemProfile>(out var inputSystemProfile, rootProfile))
{
var inputDataProviderConfiguration = new MixedRealityServiceConfiguration<IMixedRealityInputDataProvider>(configuration);

Expand All @@ -244,7 +258,7 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration
break;

case Type _ when typeof(IMixedRealitySpatialAwarenessDataProvider).IsAssignableFrom(configurationType):
if (MixedRealityToolkit.TryGetSystemProfile<IMixedRealitySpatialAwarenessSystem, MixedRealitySpatialAwarenessSystemProfile>(out var spatialAwarenessSystemProfile))
if (MixedRealityToolkit.TryGetSystemProfile<IMixedRealitySpatialAwarenessSystem, MixedRealitySpatialAwarenessSystemProfile>(out var spatialAwarenessSystemProfile, rootProfile))
{
var spatialObserverConfiguration = new MixedRealityServiceConfiguration<IMixedRealitySpatialAwarenessDataProvider>(configuration);

Expand Down
11 changes: 10 additions & 1 deletion Editor/Profiles/MixedRealityServiceProviderProfileInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protected override void OnEnable()
configurationList.onAddCallback += OnConfigurationOptionAdded;
configurationList.onRemoveCallback += OnConfigurationOptionRemoved;
configurationList.elementHeightCallback += ElementHeightCallback;
configurationList.onReorderCallback += OnElementReorderedCallback;
}

public override void OnInspectorGUI()
Expand Down Expand Up @@ -170,7 +171,7 @@ private void DrawConfigurationOptionElement(Rect rect, int index, bool isActive,
}
}

priorityProperty.intValue = index;
priorityProperty.intValue = index - 1;

var lastMode = EditorGUIUtility.wideMode;
var prevLabelWidth = EditorGUIUtility.labelWidth;
Expand Down Expand Up @@ -324,5 +325,13 @@ private void OnConfigurationOptionRemoved(ReorderableList list)
EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetProfile(MixedRealityToolkit.Instance.ActiveProfile);
}
}

private void OnElementReorderedCallback(ReorderableList list)
{
if (MixedRealityToolkit.IsInitialized)
{
EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetProfile(MixedRealityToolkit.Instance.ActiveProfile);
}
}
}
}
13 changes: 7 additions & 6 deletions Runtime/Providers/Speech/WindowsSpeechDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ public WindowsSpeechDataProvider(string name, uint priority, MixedRealitySpeechC
#endif

#if UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN
var newKeywords = new string[commands.Length];

for (int i = 0; i < commands.Length; i++)
{
newKeywords[i] = commands[i].Keyword;
}

if (!MixedRealityToolkit.TryGetSystemProfile<IMixedRealityInputSystem, MixedRealityInputSystemProfile>(out var inputSystemProfile))
{
Expand All @@ -48,6 +42,13 @@ public WindowsSpeechDataProvider(string name, uint priority, MixedRealitySpeechC
RecognitionConfidenceLevel = inputSystemProfile.SpeechCommandsProfile.SpeechRecognitionConfidenceLevel;
commands = inputSystemProfile.SpeechCommandsProfile.SpeechCommands;

var newKeywords = new string[commands.Length];

for (int i = 0; i < commands.Length; i++)
{
newKeywords[i] = commands[i].Keyword;
}

if (keywordRecognizer == null)
{
try
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Services/BaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class BaseService : IMixedRealityService
public virtual string Name { get; protected set; }

/// <inheritdoc />
public virtual uint Priority { get; protected set; } = 5;
public virtual uint Priority { get; protected set; }

/// <inheritdoc />
public virtual void Initialize() { }
Expand Down
56 changes: 24 additions & 32 deletions Runtime/Services/MixedRealityToolkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ private void InitializeServiceLocator()
{
if (TryCreateAndRegisterService(configuration, out var service) && service != null)
{
if (configuration.Profile is BaseMixedRealityServiceProfile<IMixedRealityDataProvider> profile)
if (configuration.Profile is IMixedRealityServiceProfile<IMixedRealityDataProvider> profile)
{
TryRegisterDataProviderConfigurations(profile.RegisteredServiceConfigurations, service);
}
Expand Down Expand Up @@ -687,13 +687,6 @@ public static bool TryRegisterServiceConfigurations<T>(IMixedRealityServiceConfi
{
var configuration = configurations[i];

if (configuration.InstancedType.Type == null)
{
anyFailed = true;
Debug.LogWarning($"Could not load the {configuration.Name} configuration's {nameof(configuration.InstancedType)}.");
continue;
}

if (TryCreateAndRegisterService(configuration, out var serviceInstance))
{
if (configuration.Profile is IMixedRealityServiceProfile<IMixedRealityDataProvider> profile &&
Expand Down Expand Up @@ -727,13 +720,6 @@ public static bool TryRegisterDataProviderConfigurations<T>(IMixedRealityService
{
var configuration = configurations[i];

if (configuration.InstancedType.Type == null)
{
anyFailed = true;
Debug.LogWarning($"Could not load the {configuration.Name} configuration's {nameof(configuration.InstancedType)}.");
continue;
}

if (!TryCreateAndRegisterDataProvider(configuration, serviceParent))
{
Debug.LogError($"Failed to start {configuration.Name}!");
Expand Down Expand Up @@ -861,7 +847,9 @@ private static bool TryCreateAndRegisterServiceInternal<T>(Type concreteType, IR
}
}

if (platforms.Count == 0)
if (platforms.Count == 0 ||
Application.isEditor &&
!CurrentBuildTargetPlatform.IsBuildTargetActive(platforms))
{
if (runtimePlatforms == null ||
runtimePlatforms.Count == 0)
Expand All @@ -881,16 +869,6 @@ private static bool TryCreateAndRegisterServiceInternal<T>(Type concreteType, IR
Debug.LogError($"Unable to register a service with a null concrete {typeof(T).Name} type.");
return false;
}

if (Application.isEditor &&
!CurrentBuildTargetPlatform.IsBuildTargetActive(platforms))
{
// 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
// when there isn't a valid build target active to run the service on.
return true;
}
}
else
{
Expand Down Expand Up @@ -1841,12 +1819,19 @@ public static bool IsSystemRegistered<T>() where T : IMixedRealitySystem
/// Is the <see cref="IMixedRealitySystem"/> enabled in the <see cref="ActiveProfile"/>?
/// </summary>
/// <typeparam name="T"><see cref="IMixedRealitySystem"/> to check.</typeparam>
/// <param name="rootProfile">Optional root profile reference.</param>
/// <returns>True, if the system is enabled in the <see cref="ActiveProfile"/>, otherwise false.</returns>
public static bool IsSystemEnabled<T>() where T : IMixedRealitySystem
public static bool IsSystemEnabled<T>(MixedRealityToolkitRootProfile rootProfile = null) where T : IMixedRealitySystem
{
if (HasActiveProfile)
if (rootProfile.IsNull())
{
foreach (var configuration in instance.activeProfile.RegisteredServiceConfigurations)
rootProfile = instance.activeProfile;
}

if (!rootProfile.IsNull())
{
// ReSharper disable once PossibleNullReferenceException
foreach (var configuration in rootProfile.RegisteredServiceConfigurations)
{
if (typeof(T).IsAssignableFrom(configuration.InstancedType.Type.FindMixedRealityServiceInterfaceType(typeof(T))) &&
configuration.Enabled)
Expand All @@ -1865,14 +1850,21 @@ public static bool IsSystemEnabled<T>() where T : IMixedRealitySystem
/// <typeparam name="TSystem">The <see cref="IMixedRealitySystem"/> type to get the <see cref="TProfile"/> for.</typeparam>
/// <typeparam name="TProfile">The <see cref="BaseMixedRealityProfile"/> type to get for the <see cref="TSystem"/>.</typeparam>
/// <param name="profile">The profile instance.</param>
/// <param name="rootProfile">Optional root profile reference.</param>
/// <returns>True if a <see cref="TSystem"/> type is matched and a valid <see cref="TProfile"/> is found, otherwise false.</returns>
public static bool TryGetSystemProfile<TSystem, TProfile>(out TProfile profile)
public static bool TryGetSystemProfile<TSystem, TProfile>(out TProfile profile, MixedRealityToolkitRootProfile rootProfile = null)
where TSystem : IMixedRealitySystem
where TProfile : BaseMixedRealityProfile
{
if (HasActiveProfile)
if (rootProfile.IsNull())
{
rootProfile = instance.activeProfile;
}

if (!rootProfile.IsNull())
{
foreach (var configuration in instance.activeProfile.RegisteredServiceConfigurations)
// ReSharper disable once PossibleNullReferenceException
foreach (var configuration in rootProfile.RegisteredServiceConfigurations)
{
if (typeof(TSystem).IsAssignableFrom(configuration.InstancedType.Type.FindMixedRealityServiceInterfaceType(typeof(TSystem))))
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Mixed Reality",
"DI"
],
"version": "0.2.7",
"version": "0.2.8",
"unity": "2019.4",
"license": "MIT",
"repository": {
Expand Down

0 comments on commit 9bb9766

Please sign in to comment.