Skip to content

Commit 5f397e5

Browse files
author
David Kline
authored
Merge pull request #2981 from SimonDarksideJ/mrtk_development_SerializationFix
Mrtk development serialization fix
2 parents ceda129 + bc15100 commit 5f397e5

File tree

3 files changed

+32
-67
lines changed

3 files changed

+32
-67
lines changed

Assets/MixedRealityToolkit-SDK/Profiles/DefaultMixedRealityToolkitConfigurationProfile.asset

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ MonoBehaviour:
1212
m_Name: DefaultMixedRealityToolkitConfigurationProfile
1313
m_EditorClassIdentifier:
1414
isCustomProfile: 0
15-
initialServiceTypes:
16-
- reference: Microsoft.MixedReality.Toolkit.SDK.Teleportation.MixedRealityTeleportManager,
17-
Microsoft.MixedReality.Toolkit.SDK
18-
- reference: Microsoft.MixedReality.Toolkit.SDK.BoundarySystem.MixedRealityBoundaryManager,
19-
Microsoft.MixedReality.Toolkit.SDK
20-
- reference: Microsoft.MixedReality.Toolkit.SDK.Input.MixedRealityInputManager,
21-
Microsoft.MixedReality.Toolkit.SDK
2215
targetExperienceScale: 3
2316
enableCameraProfile: 1
2417
cameraProfile: {fileID: 11400000, guid: 8089ccfdd4494cd38f676f9fc1f46a04, type: 2}

Assets/MixedRealityToolkit/_Core/Definitions/MixedRealityToolkitConfigurationProfile.cs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@ namespace Microsoft.MixedReality.Toolkit.Core.Definitions
2121
/// Configuration profile settings for the Mixed Reality Toolkit.
2222
/// </summary>
2323
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Mixed Reality Toolkit Configuration Profile", fileName = "MixedRealityToolkitConfigurationProfile", order = (int)CreateProfileMenuItemIndices.Configuration)]
24-
public class MixedRealityToolkitConfigurationProfile : BaseMixedRealityProfile, ISerializationCallbackReceiver
24+
public class MixedRealityToolkitConfigurationProfile : BaseMixedRealityProfile
2525
{
2626
#region Service Registry properties
2727

28-
[SerializeField]
29-
private SystemType[] initialServiceTypes = null;
30-
3128
/// <summary>
3229
/// Dictionary list of active Systems used by the Mixed Reality Toolkit at runtime
3330
/// </summary>
@@ -238,33 +235,5 @@ public SystemType DiagnosticsSystemSystemType
238235
public MixedRealityRegisteredServiceProvidersProfile RegisteredServiceProvidersProfile => registeredServiceProvidersProfile;
239236

240237
#endregion Mixed Reality Toolkit configurable properties
241-
242-
#region ISerializationCallbackReceiver Implementation
243-
244-
/// <inheritdoc />
245-
void ISerializationCallbackReceiver.OnBeforeSerialize()
246-
{
247-
var count = ActiveServices.Count;
248-
initialServiceTypes = new SystemType[count];
249-
250-
foreach (var service in ActiveServices)
251-
{
252-
--count;
253-
initialServiceTypes[count] = new SystemType(service.Value.GetType());
254-
}
255-
}
256-
257-
/// <inheritdoc />
258-
void ISerializationCallbackReceiver.OnAfterDeserialize()
259-
{
260-
if (ActiveServices.Count == 0)
261-
{
262-
for (int i = 0; i < initialServiceTypes?.Length; i++)
263-
{
264-
ActiveServices.Add(initialServiceTypes[i], Activator.CreateInstance(initialServiceTypes[i]) as IMixedRealityService);
265-
}
266-
}
267-
}
268238
}
269-
#endregion ISerializationCallbackReceiver Implementation
270239
}

Assets/MixedRealityToolkit/_Core/Services/MixedRealityToolkit.cs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ private void Initialize()
177177
Utilities.Editor.InputMappingAxisUtility.CheckUnityInputManagerMappings(Definitions.Devices.ControllerMappingLibrary.UnityInputManagerAxes);
178178
#endif
179179

180-
RegisterService(typeof(IMixedRealityInputSystem), Activator.CreateInstance(ActiveProfile.InputSystemType) as IMixedRealityInputSystem);
181-
182-
if (InputSystem == null)
180+
if (!RegisterService(typeof(IMixedRealityInputSystem), Activator.CreateInstance(ActiveProfile.InputSystemType) as IMixedRealityInputSystem) ||
181+
InputSystem == null)
183182
{
184183
Debug.LogError("Failed to start the Input System!");
185184
}
@@ -188,9 +187,8 @@ private void Initialize()
188187
// If the Boundary system has been selected for initialization in the Active profile, enable it in the project
189188
if (ActiveProfile.IsBoundarySystemEnabled)
190189
{
191-
RegisterService(typeof(IMixedRealityBoundarySystem), Activator.CreateInstance(ActiveProfile.BoundarySystemSystemType) as IMixedRealityBoundarySystem);
192-
193-
if (BoundarySystem == null)
190+
if (!RegisterService(typeof(IMixedRealityBoundarySystem), Activator.CreateInstance(ActiveProfile.BoundarySystemSystemType) as IMixedRealityBoundarySystem) ||
191+
BoundarySystem == null)
194192
{
195193
Debug.LogError("Failed to start the Boundary System!");
196194
}
@@ -200,19 +198,17 @@ private void Initialize()
200198
// If the Teleport system has been selected for initialization in the Active profile, enable it in the project
201199
if (ActiveProfile.IsTeleportSystemEnabled)
202200
{
203-
RegisterService(typeof(IMixedRealityTeleportSystem), Activator.CreateInstance(ActiveProfile.TeleportSystemSystemType) as IMixedRealityTeleportSystem);
204-
205-
if (TeleportSystem == null)
201+
if (!RegisterService(typeof(IMixedRealityTeleportSystem), Activator.CreateInstance(ActiveProfile.TeleportSystemSystemType) as IMixedRealityTeleportSystem) ||
202+
TeleportSystem == null)
206203
{
207204
Debug.LogError("Failed to start the Teleport System!");
208205
}
209206
}
210207

211208
if (ActiveProfile.IsDiagnosticsSystemEnabled)
212209
{
213-
RegisterService(typeof(IMixedRealityDiagnosticsSystem), Activator.CreateInstance(ActiveProfile.DiagnosticsSystemSystemType) as IMixedRealityDiagnosticsSystem);
214-
215-
if (DiagnosticsSystem == null)
210+
if (!RegisterService(typeof(IMixedRealityDiagnosticsSystem), Activator.CreateInstance(ActiveProfile.DiagnosticsSystemSystemType) as IMixedRealityDiagnosticsSystem) ||
211+
DiagnosticsSystem == null)
216212
{
217213
Debug.LogError("Failed to start the Diagnostics System!");
218214
}
@@ -231,7 +227,10 @@ private void Initialize()
231227
{
232228
if (configuration.ComponentType.Type != null)
233229
{
234-
RegisterService(typeof(IMixedRealityExtensionService), Activator.CreateInstance(configuration.ComponentType, configuration.ComponentName, configuration.Priority) as IMixedRealityExtensionService);
230+
if(!RegisterService(typeof(IMixedRealityExtensionService), Activator.CreateInstance(configuration.ComponentType, configuration.ComponentName, configuration.Priority) as IMixedRealityExtensionService))
231+
{
232+
Debug.LogError($"Failed to register the {configuration.ComponentType.Type} Extension Service!");
233+
}
235234
}
236235
}
237236
}
@@ -489,50 +488,54 @@ private void OnDestroy()
489488
/// </summary>
490489
/// <param name="type">The interface type for the system to be managed. E.G. InputSystem, BoundarySystem</param>
491490
/// <param name="service">The Instance of the service class to register</param>
492-
public void RegisterService(Type type, IMixedRealityService service)
491+
public bool RegisterService(Type type, IMixedRealityService service)
493492
{
494493
if (ActiveProfile == null)
495494
{
496495
Debug.LogError($"Unable to add a new {type.Name} Service as the Mixed Reality Toolkit has to Active Profile");
496+
return false;
497497
}
498498

499499
if (type == null)
500500
{
501501
Debug.LogWarning("Unable to add a manager of type null.");
502-
return;
502+
return false;
503503
}
504504
if (service == null)
505505
{
506506
Debug.LogWarning("Unable to add a manager with a null instance.");
507-
return;
507+
return false;
508508
}
509509

510510
if (IsCoreSystem(type))
511511
{
512512
IMixedRealityService preExistingService;
513-
if (IsCoreSystem(type))
514-
{
515-
ActiveProfile.ActiveServices.TryGetValue(type, out preExistingService);
516-
}
517-
else
518-
{
519-
GetService(type, out preExistingService);
520-
}
513+
514+
ActiveProfile.ActiveServices.TryGetValue(type, out preExistingService);
521515

522516
if (preExistingService == null)
523517
{
524518
ActiveProfile.ActiveServices.Add(type, service);
519+
return true;
525520
}
526521
else
527522
{
528523
Debug.LogError($"There's already a {type.Name} registered.");
524+
return false;
529525
}
530526
}
531527
else
532528
{
529+
if (!typeof(IMixedRealityExtensionService).IsAssignableFrom(type))
530+
{
531+
Debug.LogError($"Unable to register {service}. Concrete type does not implement the IMixedRealityExtensionService implementation.");
532+
return false;
533+
}
534+
533535
MixedRealityComponents.Add(new Tuple<Type, IMixedRealityExtensionService>(type, (IMixedRealityExtensionService)service));
534536
if (!isInitializing) { service.Initialize(); }
535537
mixedRealityComponentsCount = MixedRealityComponents.Count;
538+
return true;
536539
}
537540
}
538541

@@ -1024,10 +1027,10 @@ private bool IsCoreSystem(Type type)
10241027
return false;
10251028
}
10261029

1027-
return type == typeof(IMixedRealityInputSystem) ||
1028-
type == typeof(IMixedRealityTeleportSystem) ||
1029-
type == typeof(IMixedRealityBoundarySystem) ||
1030-
type == typeof(IMixedRealityDiagnosticsSystem);
1030+
return typeof(IMixedRealityInputSystem).IsAssignableFrom(type) ||
1031+
typeof(IMixedRealityTeleportSystem).IsAssignableFrom(type) ||
1032+
typeof(IMixedRealityBoundarySystem).IsAssignableFrom(type) ||
1033+
typeof(IMixedRealityDiagnosticsSystem).IsAssignableFrom(type);
10311034
}
10321035

10331036
/// <summary>

0 commit comments

Comments
 (0)