in Assets/MixedRealityToolkit/Services/MixedRealityToolkit.cs [325:482]
private void InitializeServiceLocator()
{
isInitializing = true;
//If the Mixed Reality Toolkit is not configured, stop.
if (ActiveProfile == null)
{
Debug.LogError("No Mixed Reality Configuration Profile found, cannot initialize the Mixed Reality Toolkit");
return;
}
#if UNITY_EDITOR
if (ActiveSystems.Count > 0)
{
activeSystems.Clear();
}
if (RegisteredMixedRealityServices.Count > 0)
{
registeredMixedRealityServices.Clear();
}
#endif
ClearCoreSystemCache();
EnsureMixedRealityRequirements();
if (ActiveProfile.IsCameraProfileEnabled)
{
if (ActiveProfile.CameraProfile.IsCameraPersistent)
{
CameraCache.Main.transform.root.DontDestroyOnLoad();
}
if (ActiveProfile.CameraProfile.IsOpaque)
{
ActiveProfile.CameraProfile.ApplySettingsForOpaqueDisplay();
}
else
{
ActiveProfile.CameraProfile.ApplySettingsForTransparentDisplay();
}
}
#region Services Registration
// If the Input system has been selected for initialization in the Active profile, enable it in the project
if (ActiveProfile.IsInputSystemEnabled)
{
#if UNITY_EDITOR
// Make sure unity axis mappings are set.
InputMappingAxisUtility.CheckUnityInputManagerMappings(ControllerMappingLibrary.UnityInputManagerAxes);
#endif
object[] args = { this, ActiveProfile.InputSystemProfile, Instance.MixedRealityPlayspace };
if (!RegisterService<IMixedRealityInputSystem>(ActiveProfile.InputSystemType, args: args) || InputSystem == null)
{
Debug.LogError("Failed to start the Input System!");
}
args = new object[] { this, InputSystem, ActiveProfile.InputSystemProfile };
if (!RegisterDataProvider<IMixedRealityFocusProvider>(ActiveProfile.InputSystemProfile.FocusProviderType, args: args))
{
Debug.LogError("Failed to register the focus provider! The input system will not function without it.");
return;
}
}
else
{
#if UNITY_EDITOR
InputMappingAxisUtility.RemoveMappings(ControllerMappingLibrary.UnityInputManagerAxes);
#endif
}
// If the Boundary system has been selected for initialization in the Active profile, enable it in the project
if (ActiveProfile.IsBoundarySystemEnabled)
{
object[] args = { this, ActiveProfile.BoundaryVisualizationProfile, Instance.MixedRealityPlayspace, ActiveProfile.TargetExperienceScale };
if (!RegisterService<IMixedRealityBoundarySystem>(ActiveProfile.BoundarySystemSystemType, args: args) || BoundarySystem == null)
{
Debug.LogError("Failed to start the Boundary System!");
}
}
// If the Spatial Awareness system has been selected for initialization in the Active profile, enable it in the project
if (ActiveProfile.IsSpatialAwarenessSystemEnabled)
{
#if UNITY_EDITOR
LayerExtensions.SetupLayer(31, "Spatial Awareness");
#endif
object[] args = { this, ActiveProfile.SpatialAwarenessSystemProfile };
if (!RegisterService<IMixedRealitySpatialAwarenessSystem>(ActiveProfile.SpatialAwarenessSystemSystemType, args: args) && SpatialAwarenessSystem != null)
{
Debug.LogError("Failed to start the Spatial Awareness System!");
}
}
// If the Teleport system has been selected for initialization in the Active profile, enable it in the project
if (ActiveProfile.IsTeleportSystemEnabled)
{
object[] args = { this, Instance.MixedRealityPlayspace };
if (!RegisterService<IMixedRealityTeleportSystem>(ActiveProfile.TeleportSystemSystemType, args: args) || TeleportSystem == null)
{
Debug.LogError("Failed to start the Teleport System!");
}
}
if (ActiveProfile.IsDiagnosticsSystemEnabled)
{
object[] args = { this, ActiveProfile.DiagnosticsSystemProfile, Instance.MixedRealityPlayspace };
if (!RegisterService<IMixedRealityDiagnosticsSystem>(ActiveProfile.DiagnosticsSystemSystemType, args: args) || DiagnosticsSystem == null)
{
Debug.LogError("Failed to start the Diagnostics System!");
}
}
if (ActiveProfile.RegisteredServiceProvidersProfile != null)
{
for (int i = 0; i < ActiveProfile.RegisteredServiceProvidersProfile?.Configurations?.Length; i++)
{
var configuration = ActiveProfile.RegisteredServiceProvidersProfile.Configurations[i];
if (typeof(IMixedRealityExtensionService).IsAssignableFrom(configuration.ComponentType.Type))
{
object[] args = { this, configuration.ComponentName, configuration.Priority, configuration.ConfigurationProfile };
if (!RegisterService<IMixedRealityExtensionService>(configuration.ComponentType, configuration.RuntimePlatform, args))
{
Debug.LogError($"Failed to register {configuration.ComponentName}");
}
}
}
}
#endregion Service Registration
#region Services Initialization
var orderedCoreSystems = activeSystems.OrderBy(m => m.Value.Priority).ToArray();
activeSystems.Clear();
foreach (var system in orderedCoreSystems)
{
RegisterServiceInternal(system.Key, system.Value);
}
var orderedServices = registeredMixedRealityServices.OrderBy(service => service.Item2.Priority).ToArray();
registeredMixedRealityServices.Clear();
foreach (var service in orderedServices)
{
RegisterServiceInternal(service.Item1, service.Item2);
}
InitializeAllServices();
#endregion Services Initialization
isInitializing = false;
}