Skip to content

Commit 8dc3aec

Browse files
authored
Merge pull request #2747 from StephenHodgson/vNEXT-GetComponentSimplification
Fixed MixedRealityManager bugs
2 parents dc65b6f + b98dfb7 commit 8dc3aec

File tree

4 files changed

+50
-18
lines changed

4 files changed

+50
-18
lines changed

Assets/MixedRealityToolkit-SDK/Inspectors/Input/Handlers/BaseInputHandlerInspector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

4+
using Microsoft.MixedReality.Toolkit.Core.Managers;
45
using UnityEditor;
56

67
namespace Microsoft.MixedReality.Toolkit.SDK.Inspectors.Input.Handlers
@@ -11,6 +12,7 @@ public class BaseInputHandlerInspector : Editor
1112

1213
protected virtual void OnEnable()
1314
{
15+
MixedRealityManager.ConfirmInitialized();
1416
isFocusRequiredProperty = serializedObject.FindProperty("isFocusRequired");
1517
}
1618

Assets/MixedRealityToolkit-SDK/Inspectors/Input/Handlers/SpeechInputHandlerInspector.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@ public override void OnInspectorGUI()
3636
base.OnInspectorGUI();
3737
serializedObject.Update();
3838

39-
if (registeredKeywords == null || registeredKeywords.Length == 0)
39+
if (!MixedRealityManager.Instance.ActiveProfile.IsInputSystemEnabled)
4040
{
41+
EditorGUILayout.HelpBox("No input system is enabled, or you need to specify the type in the main configuration profile.", MessageType.Error);
42+
return;
43+
}
4144

45+
if (registeredKeywords == null || registeredKeywords.Length == 0)
46+
{
47+
registeredKeywords = RegisteredKeywords().Distinct().ToArray();
4248
EditorGUILayout.HelpBox("No keywords registered.\n\nKeywords can be registered via Speech Commands Profile on the Mixed Reality Manager's Configuration Profile.", MessageType.Error);
4349
return;
4450
}
@@ -136,7 +142,7 @@ private void ShowList(SerializedProperty list)
136142

137143
private static IEnumerable<string> RegisteredKeywords()
138144
{
139-
if (!MixedRealityManager.HasActiveProfile ||
145+
if (!MixedRealityManager.ConfirmInitialized() ||
140146
!MixedRealityManager.Instance.ActiveProfile.IsInputSystemEnabled ||
141147
!MixedRealityManager.Instance.ActiveProfile.InputSystemProfile.IsSpeechCommandsEnabled ||
142148
MixedRealityManager.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile.SpeechCommands.Length == 0)

Assets/MixedRealityToolkit/_Core/Managers/BaseManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class BaseManager : Interfaces.IMixedRealityManager
1616
/// <summary>
1717
/// Optional Priority to reorder registered managers based on their respective priority, reduces the risk of race conditions by prioritizing the order in which managers are evaluated.
1818
/// </summary>
19-
public virtual uint Priority { get; set; }
19+
public virtual uint Priority { get; set; } = 5;
2020

2121
/// <summary>
2222
/// The initialize function is used to setup the manager once created.

Assets/MixedRealityToolkit/_Core/Managers/MixedRealityManager.cs

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ private void Initialize()
140140
}
141141
else
142142
{
143+
mixedRealityComponentsCount = 0;
144+
MixedRealityComponents.Clear();
143145
ActiveProfile.ActiveManagers.Clear();
144146
}
145147
}
@@ -192,7 +194,6 @@ private void Initialize()
192194
for (int i = 0; i < ActiveProfile.RegisteredComponentsProfile.Configurations?.Length; i++)
193195
{
194196
var configuration = ActiveProfile.RegisteredComponentsProfile.Configurations[i];
195-
196197
#if UNITY_EDITOR
197198
if (UnityEditor.EditorUserBuildSettings.activeBuildTarget.IsPlatformSupported(configuration.RuntimePlatform))
198199
#else
@@ -485,6 +486,11 @@ public IMixedRealityManager GetManager(Type type)
485486
throw new ArgumentNullException($"Unable to get {nameof(type)} Manager as the Mixed Reality Manager has no Active Profile.");
486487
}
487488

489+
if (!IsInitialized)
490+
{
491+
throw new ArgumentNullException($"Unable to get {nameof(type)} Manager as the Mixed Reality Manager has not been initialized!");
492+
}
493+
488494
if (type == null) { throw new ArgumentNullException(nameof(type)); }
489495

490496
IMixedRealityManager manager;
@@ -558,7 +564,12 @@ public void RemoveManager(Type type)
558564
}
559565
else
560566
{
561-
MixedRealityComponents.RemoveAll(tuple => tuple.Item1.Name == type.Name);
567+
IMixedRealityManager manager;
568+
GetComponentByType(type, out manager);
569+
if (manager != null)
570+
{
571+
MixedRealityComponents.Remove(new Tuple<Type, IMixedRealityManager>(type, manager));
572+
}
562573
}
563574
}
564575

@@ -584,7 +595,12 @@ public void RemoveManager(Type type, string managerName)
584595
}
585596
else
586597
{
587-
MixedRealityComponents.RemoveAll(tuple => tuple.Item1.Name == type.Name && tuple.Item2.Name == managerName);
598+
IMixedRealityManager manager;
599+
GetComponentByTypeAndName(type, managerName, out manager);
600+
if (manager != null)
601+
{
602+
MixedRealityComponents.Remove(new Tuple<Type, IMixedRealityManager>(type, manager));
603+
}
588604
}
589605
}
590606

@@ -869,6 +885,7 @@ private bool IsCoreManagerType(Type type)
869885
if (type == null) { throw new ArgumentNullException(nameof(type)); }
870886

871887
return type == typeof(IMixedRealityInputSystem) ||
888+
type == typeof(IMixedRealityTeleportSystem) ||
872889
type == typeof(IMixedRealityBoundarySystem);
873890
}
874891

@@ -896,6 +913,17 @@ private void GetComponentByTypeAndName(Type type, string managerName, out IMixed
896913

897914
manager = null;
898915

916+
if (isMixedRealityManagerInitializing)
917+
{
918+
Debug.LogWarning("Unable to get a manager while initializing!");
919+
return;
920+
}
921+
922+
if (mixedRealityComponentsCount != MixedRealityComponents.Count)
923+
{
924+
Initialize();
925+
}
926+
899927
for (int i = 0; i < mixedRealityComponentsCount; i++)
900928
{
901929
if (CheckComponentMatch(type, managerName, MixedRealityComponents[i]))
@@ -926,26 +954,22 @@ private void GetComponentsByTypeAndName(Type type, string managerName, ref List<
926954
}
927955
}
928956

929-
private bool CheckComponentMatch(Type type, string managerName, Tuple<Type, IMixedRealityManager> managerTuple)
957+
private static bool CheckComponentMatch(Type type, string managerName, Tuple<Type, IMixedRealityManager> managerTuple)
930958
{
931959
if ((managerTuple.Item1.Name == type.Name ||
932960
managerTuple.Item2.GetType().Name == type.Name) &&
933-
(string.IsNullOrEmpty(managerName) ? true :
934-
managerTuple.Item2.Name == managerName))
961+
(string.IsNullOrEmpty(managerName) || managerTuple.Item2.Name == managerName))
935962
{
936963
return true;
937964
}
938-
else
965+
966+
var interfaces = managerTuple.Item2.GetType().GetInterfaces();
967+
for (int i = 0; i < interfaces.Length; i++)
939968
{
940-
var interfaces = managerTuple.Item2.GetType().GetInterfaces();
941-
for (int j = 0; j < interfaces.Length; j++)
969+
if (interfaces[i].Name == type.Name &&
970+
(string.IsNullOrEmpty(managerName) || managerTuple.Item2.Name == managerName))
942971
{
943-
if (interfaces[j].Name == type.Name &&
944-
(string.IsNullOrEmpty(managerName) ? true :
945-
managerTuple.Item2.Name == managerName))
946-
{
947-
return true;
948-
}
972+
return true;
949973
}
950974
}
951975

0 commit comments

Comments
 (0)