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

Misc bug fixes for 0.2.0 release #710

Merged
merged 6 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Submodules/SDK
Submodule SDK updated from 2d52a9 to bd5c63
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public override void OnInspectorGUI()
EditorApplication.delayCall += () =>
{
changed = true;
var rootProfile =
AssetDatabase.LoadAssetAtPath<MixedRealityToolkitRootProfile>(rootProfilePath);
var rootProfile = AssetDatabase.LoadAssetAtPath<MixedRealityToolkitRootProfile>(rootProfilePath);
Debug.Assert(rootProfile != null);
activeProfile.objectReferenceValue = rootProfile;
EditorGUIUtility.PingObject(rootProfile);
Expand Down
6 changes: 3 additions & 3 deletions XRTK-Core/Packages/com.xrtk.core/Editor/PackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration
{
case Type _ when typeof(IMixedRealityCameraDataProvider).IsAssignableFrom(configurationType):
var cameraSystemProfile = rootProfile.CameraSystemProfile;
var cameraDataProviderConfiguration = new MixedRealityServiceConfiguration<IMixedRealityCameraDataProvider>(configuration.InstancedType, configuration.Name, configuration.Priority, configuration.RuntimePlatforms, configuration.Profile);
var cameraDataProviderConfiguration = new MixedRealityServiceConfiguration<IMixedRealityCameraDataProvider>(configuration);

if (cameraSystemProfile.RegisteredServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != cameraDataProviderConfiguration.InstancedType.Type))
{
Expand All @@ -219,7 +219,7 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration

case Type _ when typeof(IMixedRealityInputDataProvider).IsAssignableFrom(configurationType):
var inputSystemProfile = rootProfile.InputSystemProfile;
var inputDataProviderConfiguration = new MixedRealityServiceConfiguration<IMixedRealityInputDataProvider>(configuration.InstancedType, configuration.Name, configuration.Priority, configuration.RuntimePlatforms, configuration.Profile);
var inputDataProviderConfiguration = new MixedRealityServiceConfiguration<IMixedRealityInputDataProvider>(configuration);

if (inputSystemProfile.RegisteredServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != inputDataProviderConfiguration.InstancedType.Type))
{
Expand All @@ -231,7 +231,7 @@ public static void InstallConfiguration(MixedRealityPlatformServiceConfiguration

case Type _ when typeof(IMixedRealitySpatialAwarenessDataProvider).IsAssignableFrom(configurationType):
var spatialAwarenessSystemProfile = rootProfile.SpatialAwarenessProfile;
var spatialObserverConfiguration = new MixedRealityServiceConfiguration<IMixedRealitySpatialAwarenessDataProvider>(configuration.InstancedType, configuration.Name, configuration.Priority, configuration.RuntimePlatforms, configuration.Profile);
var spatialObserverConfiguration = new MixedRealityServiceConfiguration<IMixedRealitySpatialAwarenessDataProvider>(configuration);

if (spatialAwarenessSystemProfile.RegisteredServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != spatialObserverConfiguration.InstancedType.Type))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

using UnityEditor;
using UnityEditor.Experimental.SceneManagement;
using UnityEditor.PackageManager;
using UnityEngine;
using XRTK.Definitions;
using XRTK.Editor.Utilities;
using XRTK.Extensions;
using XRTK.Interfaces;
using XRTK.Services;

namespace XRTK.Editor.Profiles
Expand Down Expand Up @@ -88,19 +91,41 @@ protected override void OnEnable()

var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();

// Create The MR Manager if none exists.
// Create the MixedRealityToolkit object if none exists.
if (!MixedRealityToolkit.IsInitialized && prefabStage == null && !didPromptToConfigure)
{
// Search for all instances, in case we've just hot reloaded the assembly.
var managerSearch = FindObjectsOfType<MixedRealityToolkit>();

if (managerSearch.Length == 0)
{
if (!ValidateImplementationsExists())
{
if (EditorUtility.DisplayDialog(
"Attention!",
$"We were unable to find any services or data providers to configure. Would you like to install the {nameof(MixedRealityToolkit)} SDK?",
"Yes",
"Later",
DialogOptOutDecisionType.ForThisSession,
"XRTK_Prompt_Install_SDK"))
{
EditorApplication.delayCall += () =>
{
Client.Add("com.xrtk.sdk");
};
}

Selection.activeObject = null;
return;
}

if (EditorUtility.DisplayDialog(
"Attention!",
"There is no active Mixed Reality Toolkit in your scene!\n\nWould you like to create one now?",
"Yes",
"Later"))
"Later",
DialogOptOutDecisionType.ForThisSession,
"XRTK_Prompt_Configure_Scene"))
{
if (MixedRealityToolkit.CameraSystem != null)
{
Expand Down Expand Up @@ -254,5 +279,13 @@ internal void RenderSystemFields()
EditorApplication.delayCall += () => MixedRealityToolkit.Instance.ResetProfile(rootProfile);
}
}

private static bool ValidateImplementationsExists()
{
return TypeExtensions.HasValidImplementations<IMixedRealitySystem>() &&
TypeExtensions.HasValidImplementations<IMixedRealityService>() &&
TypeExtensions.HasValidImplementations<IMixedRealityDataProvider>();

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
}
}

Debug.Assert(!selectedProfile.ParentProfile.IsNull());
Debug.Assert(selectedProfile.ParentProfile != selectedProfile);
Debug.Assert(selectedProfile.ParentProfile != selectedProfile, $"{selectedProfile} cannot be a parent of itself!");
}

DrawCloneButtons = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public static string RepositoryRootDir

private static string projectRootDir;

internal static bool HasSubmodules => File.Exists($"{RepositoryRootDir}/.gitmodules");

[MenuItem("Assets/Submodules/Force update all submodules", true, 23)]
public static bool ForceUpdateSubmodulesValidation()
{
return HasSubmodules;
}

[MenuItem("Assets/Submodules/Force update all submodules", false, 23)]
public static void ForceUpdateSubmodules()
{
Expand Down Expand Up @@ -119,20 +127,24 @@ public static void WritePathToGitIgnore(string ignoredPath)
/// <returns>True, if update was successful.</returns>
internal static bool UpdateSubmodules()
{
EditorUtility.DisplayProgressBar("Updating Submodules...", "Please wait...", 0.5f);
if (HasSubmodules)
{
EditorUtility.DisplayProgressBar("Updating Submodules...", "Please wait...", 0.5f);

var isGitInstalled = new Process().Run("git --version", out var message) && !message.Contains("'git' is not recognized");
var isGitInstalled = new Process().Run("git --version", out var message) && !message.Contains("'git' is not recognized");

if (isGitInstalled)
{
var success = new Process().Run($@"cd ""{RepositoryRootDir}"" && git submodule update --init --all", out _);
if (isGitInstalled)
{
var success = new Process().Run($@"cd ""{RepositoryRootDir}"" && git submodule update --init --all", out _);

EditorUtility.ClearProgressBar();
return success;
}

EditorUtility.ClearProgressBar();
return success;
Debug.LogError(message);
}

EditorUtility.ClearProgressBar();
Debug.LogError(message);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,51 @@ namespace XRTK.Editor.Utilities
/// </summary>
public static class GuidRegenerator
{
[Serializable]
private struct GuidPair
{
public string Key;
public string Value;
}

[Serializable]
private struct GuidMap
{
public List<GuidPair> Map;

public bool TryGetKey(string inGuid, out string outGuid)
{
for (int i = 0; i < Map.Count; i++)
{
if (Map[i].Value == inGuid)
{
outGuid = Map[i].Key;
return true;
}
}

outGuid = string.Empty;
return false;
}

public bool TryGetValue(string inGuid, out string outGuid)
{
for (int i = 0; i < Map.Count; i++)
{
if (Map[i].Key == inGuid)
{
outGuid = Map[i].Value;
return true;
}
}

outGuid = string.Empty;
return false;
}
}

private static readonly string GuidMapFilePath = $"{Application.dataPath}/{MixedRealityPreferences.ProfileGenerationPath}xrtk.guid.map.json";

/// <summary>
/// Regenerate the guids for assets located in the <see cref="assetsRootPath"/>.
/// </summary>
Expand Down Expand Up @@ -64,13 +109,17 @@ private static void RegenerateGuidsInternal(List<string> assetsRootPath)
filesPaths.AddRange(UnityFileHelper.GetUnityAssetsAtPath(assetsRootPath[i]));
}

var guidMap = File.Exists(GuidMapFilePath)
? JsonUtility.FromJson<GuidMap>(File.ReadAllText(GuidMapFilePath))
: new GuidMap { Map = new List<GuidPair>(0) };

// Create dictionary to hold old-to-new GUID map
var guidOldToNewMap = new Dictionary<string, string>();
var guidsInFileMap = new Dictionary<string, List<string>>();

// We must only replace GUIDs for Resources present in the path.
// Otherwise built-in resources (shader, meshes etc) get overwritten.
var ownGuids = new HashSet<string>();
var guidsToReplace = new HashSet<string>();

// Traverse all files, remember which GUIDs are in which files and generate new GUIDs
var counter = 0;
Expand All @@ -80,32 +129,49 @@ private static void RegenerateGuidsInternal(List<string> assetsRootPath)
EditorUtility.DisplayProgressBar("Gathering asset info...", filePath, counter / (float)filesPaths.Count);

var isFirstGuid = true;
var guids = GetGuids(File.ReadAllText(filePath));
var oldGuids = GetGuids(File.ReadAllText(filePath));

foreach (var oldGuid in guids)
foreach (var oldGuid in oldGuids)
{
// If we've previously regenerated the guids for this asset
// then replace the original guid key
var guid = guidMap.TryGetKey(oldGuid, out var originalGuid)
? originalGuid
: oldGuid;

// First GUID in .meta file is always the GUID of the asset itself
if (isFirstGuid && Path.GetExtension(filePath) == ".meta")
{
ownGuids.Add(oldGuid);
guidsToReplace.Add(guid);
isFirstGuid = false;
}

// Generate and save new GUID if we haven't added it before
if (!guidOldToNewMap.ContainsKey(oldGuid))
if (!guidOldToNewMap.ContainsKey(guid))
{
var newGuid = Guid.NewGuid().ToString("N");
guidOldToNewMap.Add(oldGuid, newGuid);
// If we've previously replaced this guid then
// use the generated guid from before
if (!guidMap.TryGetValue(guid, out var newGuid))
{
newGuid = Guid.NewGuid().ToString("N");
guidMap.Map.Add(new GuidPair
{
Key = guid,
Value = newGuid
});
}

guidOldToNewMap.Add(guid, newGuid);
}

if (!guidsInFileMap.ContainsKey(filePath))
{
guidsInFileMap[filePath] = new List<string>();
}

if (!guidsInFileMap[filePath].Contains(oldGuid))
if (!guidsInFileMap[filePath].Contains(guid))
{
guidsInFileMap[filePath].Add(oldGuid);
guidsInFileMap[filePath].Add(guid);
}
}

Expand All @@ -125,7 +191,7 @@ private static void RegenerateGuidsInternal(List<string> assetsRootPath)

foreach (var oldGuid in guidsInFileMap[filePath])
{
if (!ownGuids.Contains(oldGuid)) { continue; }
if (!guidsToReplace.Contains(oldGuid)) { continue; }

var newGuid = guidOldToNewMap[oldGuid];

Expand Down Expand Up @@ -155,6 +221,16 @@ private static void RegenerateGuidsInternal(List<string> assetsRootPath)
}
}

// Write guid map to file.
try
{
File.WriteAllText(GuidMapFilePath, JsonUtility.ToJson(guidMap));
}
catch (Exception e)
{
Debug.LogError(e);
}

EditorUtility.ClearProgressBar();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public interface IMixedRealityServiceProfile<out TService> where TService : IMix
/// The <see cref="IMixedRealityService"/> type to constrain all of the valid <see cref="IMixedRealityServiceConfiguration.InstancedType"/>s to.
/// Only types that implement the <see cref="TService"/> will show up in the inspector dropdown for the <see cref="IMixedRealityServiceConfiguration.InstancedType"/>
/// </typeparam>
public abstract class BaseMixedRealityServiceProfile<TService> : BaseMixedRealityProfile,
IMixedRealityServiceProfile<TService>
where TService : IMixedRealityService
public abstract class BaseMixedRealityServiceProfile<TService> : BaseMixedRealityProfile, IMixedRealityServiceProfile<TService> where TService : IMixedRealityService
{
[SerializeField]
private MixedRealityServiceConfiguration[] configurations = new MixedRealityServiceConfiguration[0];
Expand All @@ -50,7 +48,7 @@ public IMixedRealityServiceConfiguration<TService>[] RegisteredServiceConfigurat
{
var cachedConfig = configurations[i];
Debug.Assert(cachedConfig != null);
var serviceConfig = new MixedRealityServiceConfiguration<TService>(cachedConfig.InstancedType, cachedConfig.Name, cachedConfig.Priority, cachedConfig.RuntimePlatforms, cachedConfig.Profile);
var serviceConfig = new MixedRealityServiceConfiguration<TService>(cachedConfig);
Debug.Assert(serviceConfig != null);
registeredServiceConfigurations[i] = serviceConfig;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ namespace XRTK.Definitions
public class MixedRealityServiceConfiguration<T> : MixedRealityServiceConfiguration, IMixedRealityServiceConfiguration<T>
where T : IMixedRealityService
{
/// <inheritdoc />
public MixedRealityServiceConfiguration(IMixedRealityServiceConfiguration configuration)
: base(configuration.InstancedType, configuration.Name, configuration.Priority, configuration.RuntimePlatforms, configuration.Profile)
{
}

/// <inheritdoc />
public MixedRealityServiceConfiguration(SystemType instancedType, string name, uint priority, IReadOnlyList<IMixedRealityPlatform> runtimePlatforms, BaseMixedRealityProfile profile)
: base(instancedType, name, priority, runtimePlatforms, profile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using UnityEngine;

namespace XRTK.Extensions.XRTK.Extensions
namespace XRTK.Extensions
{
/// <summary>
/// Extension methods for Unity's <see cref="Collider"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using UnityEngine;

namespace XRTK.Extensions.XRTK.Extensions
namespace XRTK.Extensions
{
public static class CollisionExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// 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.Extensions
{
#if UNITY_WSA
public static class GestureRecognizerExtensions
{
[Obsolete]
[System.Obsolete]
public static void UpdateAndResetGestures(this UnityEngine.XR.WSA.Input.GestureRecognizer recognizer, UnityEngine.XR.WSA.Input.GestureSettings gestureSettings)
{
bool reset = recognizer.IsCapturingGestures();
Expand Down
Loading