Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ MonoBehaviour:
m_EditorClassIdentifier:
isCustomProfile: 0
initialServiceTypes:
- reference: Microsoft.MixedReality.Toolkit.SDK.Teleportation.MixedRealityTeleportManager,
Microsoft.MixedReality.Toolkit.SDK
- reference: Microsoft.MixedReality.Toolkit.SDK.BoundarySystem.MixedRealityBoundaryManager,
Microsoft.MixedReality.Toolkit.SDK
- reference: Microsoft.MixedReality.Toolkit.SDK.Input.MixedRealityInputManager,
Microsoft.MixedReality.Toolkit.SDK
targetExperienceScale: 3
enableCameraProfile: 1
cameraProfile: {fileID: 11400000, guid: 8089ccfdd4494cd38f676f9fc1f46a04, type: 2}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ namespace Microsoft.MixedReality.Toolkit.Core.Definitions
/// Configuration profile settings for the Mixed Reality Toolkit.
/// </summary>
[CreateAssetMenu(menuName = "Mixed Reality Toolkit/Mixed Reality Toolkit Configuration Profile", fileName = "MixedRealityToolkitConfigurationProfile", order = (int)CreateProfileMenuItemIndices.Configuration)]
public class MixedRealityToolkitConfigurationProfile : BaseMixedRealityProfile, ISerializationCallbackReceiver
public class MixedRealityToolkitConfigurationProfile : BaseMixedRealityProfile
{
#region Service Registry properties

[SerializeField]
private SystemType[] initialServiceTypes = null;

/// <summary>
/// Dictionary list of active Systems used by the Mixed Reality Toolkit at runtime
/// </summary>
Expand Down Expand Up @@ -238,33 +235,5 @@ public SystemType DiagnosticsSystemSystemType
public MixedRealityRegisteredServiceProvidersProfile RegisteredServiceProvidersProfile => registeredServiceProvidersProfile;

#endregion Mixed Reality Toolkit configurable properties

#region ISerializationCallbackReceiver Implementation

/// <inheritdoc />
void ISerializationCallbackReceiver.OnBeforeSerialize()
{
var count = ActiveServices.Count;
initialServiceTypes = new SystemType[count];

foreach (var service in ActiveServices)
{
--count;
initialServiceTypes[count] = new SystemType(service.Value.GetType());
}
}

/// <inheritdoc />
void ISerializationCallbackReceiver.OnAfterDeserialize()
{
if (ActiveServices.Count == 0)
{
for (int i = 0; i < initialServiceTypes?.Length; i++)
{
ActiveServices.Add(initialServiceTypes[i], Activator.CreateInstance(initialServiceTypes[i]) as IMixedRealityService);
}
}
}
}
#endregion ISerializationCallbackReceiver Implementation
}
66 changes: 35 additions & 31 deletions Assets/MixedRealityToolkit/_Core/Services/MixedRealityToolkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ private void Initialize()
Utilities.Editor.InputMappingAxisUtility.CheckUnityInputManagerMappings(Definitions.Devices.ControllerMappingLibrary.UnityInputManagerAxes);
#endif

RegisterService(typeof(IMixedRealityInputSystem), Activator.CreateInstance(ActiveProfile.InputSystemType) as IMixedRealityInputSystem);

if (InputSystem == null)
if (!RegisterService(typeof(IMixedRealityInputSystem), Activator.CreateInstance(ActiveProfile.InputSystemType) as IMixedRealityInputSystem) ||
InputSystem == null)
{
Debug.LogError("Failed to start the Input System!");
}
Expand All @@ -188,9 +187,8 @@ private void Initialize()
// If the Boundary system has been selected for initialization in the Active profile, enable it in the project
if (ActiveProfile.IsBoundarySystemEnabled)
{
RegisterService(typeof(IMixedRealityBoundarySystem), Activator.CreateInstance(ActiveProfile.BoundarySystemSystemType) as IMixedRealityBoundarySystem);

if (BoundarySystem == null)
if (!RegisterService(typeof(IMixedRealityBoundarySystem), Activator.CreateInstance(ActiveProfile.BoundarySystemSystemType) as IMixedRealityBoundarySystem) ||
BoundarySystem == null)
{
Debug.LogError("Failed to start the Boundary System!");
}
Expand All @@ -200,19 +198,17 @@ private void Initialize()
// If the Teleport system has been selected for initialization in the Active profile, enable it in the project
if (ActiveProfile.IsTeleportSystemEnabled)
{
RegisterService(typeof(IMixedRealityTeleportSystem), Activator.CreateInstance(ActiveProfile.TeleportSystemSystemType) as IMixedRealityTeleportSystem);

if (TeleportSystem == null)
if (!RegisterService(typeof(IMixedRealityTeleportSystem), Activator.CreateInstance(ActiveProfile.TeleportSystemSystemType) as IMixedRealityTeleportSystem) ||
TeleportSystem == null)
{
Debug.LogError("Failed to start the Teleport System!");
}
}

if (ActiveProfile.IsDiagnosticsSystemEnabled)
{
RegisterService(typeof(IMixedRealityDiagnosticsSystem), Activator.CreateInstance(ActiveProfile.DiagnosticsSystemSystemType) as IMixedRealityDiagnosticsSystem);

if (DiagnosticsSystem == null)
if (!RegisterService(typeof(IMixedRealityDiagnosticsSystem), Activator.CreateInstance(ActiveProfile.DiagnosticsSystemSystemType) as IMixedRealityDiagnosticsSystem) ||
DiagnosticsSystem == null)
{
Debug.LogError("Failed to start the Diagnostics System!");
}
Expand All @@ -231,7 +227,10 @@ private void Initialize()
{
if (configuration.ComponentType.Type != null)
{
RegisterService(typeof(IMixedRealityExtensionService), Activator.CreateInstance(configuration.ComponentType, configuration.ComponentName, configuration.Priority) as IMixedRealityExtensionService);
if(!RegisterService(typeof(IMixedRealityExtensionService), Activator.CreateInstance(configuration.ComponentType, configuration.ComponentName, configuration.Priority) as IMixedRealityExtensionService))
{
Debug.LogError($"Failed to register the {configuration.ComponentType.Type} Extension Service!");
}
}
}
}
Expand Down Expand Up @@ -489,50 +488,55 @@ private void OnDestroy()
/// </summary>
/// <param name="type">The interface type for the system to be managed. E.G. InputSystem, BoundarySystem</param>
/// <param name="service">The Instance of the service class to register</param>
public void RegisterService(Type type, IMixedRealityService service)
public bool RegisterService(Type type, IMixedRealityService service)
{
if (ActiveProfile == null)
{
Debug.LogError($"Unable to add a new {type.Name} Service as the Mixed Reality Toolkit has to Active Profile");
return false;
}

if (type == null)
{
Debug.LogWarning("Unable to add a manager of type null.");
return;
return false;
}
if (service == null)
{
Debug.LogWarning("Unable to add a manager with a null instance.");
return;
return false;
}

if (IsCoreSystem(type))
{
IMixedRealityService preExistingService;
if (IsCoreSystem(type))
{
ActiveProfile.ActiveServices.TryGetValue(type, out preExistingService);
}
else
{
GetService(type, out preExistingService);
}

ActiveProfile.ActiveServices.TryGetValue(type, out preExistingService);

if (preExistingService == null)
{
ActiveProfile.ActiveServices.Add(type, service);
return true;
}
else
{
Debug.LogError($"There's already a {type.Name} registered.");
return false;
}
}
else
{
MixedRealityComponents.Add(new Tuple<Type, IMixedRealityExtensionService>(type, (IMixedRealityExtensionService)service));
if (!isInitializing) { service.Initialize(); }
mixedRealityComponentsCount = MixedRealityComponents.Count;
try
{
MixedRealityComponents.Add(new Tuple<Type, IMixedRealityExtensionService>(type, (IMixedRealityExtensionService)service));
if (!isInitializing) { service.Initialize(); }
mixedRealityComponentsCount = MixedRealityComponents.Count;
return true;
}
catch (Exception)
{
return false;
}
}
}

Expand Down Expand Up @@ -1024,10 +1028,10 @@ private bool IsCoreSystem(Type type)
return false;
}

return type == typeof(IMixedRealityInputSystem) ||
type == typeof(IMixedRealityTeleportSystem) ||
type == typeof(IMixedRealityBoundarySystem) ||
type == typeof(IMixedRealityDiagnosticsSystem);
return typeof(IMixedRealityInputSystem).IsAssignableFrom(type) ||
typeof(IMixedRealityTeleportSystem).IsAssignableFrom(type) ||
typeof(IMixedRealityBoundarySystem).IsAssignableFrom(type) ||
typeof(IMixedRealityDiagnosticsSystem).IsAssignableFrom(type);
}

/// <summary>
Expand Down