private void InitializeServiceLocator()

in Assets/MRTK/Core/Services/MixedRealityToolkit.cs [389:560]


        private void InitializeServiceLocator()
        {
            isInitializing = true;

            // If the Mixed Reality Toolkit is not configured, stop.
            if (ActiveProfile == null)
            {
                if (!Application.isPlaying)
                {
                    // Log as warning if in edit mode. Likely user is making changes etc.
                    Debug.LogWarning(NoMRTKProfileErrorMessage);
                }
                else
                {
                    Debug.LogError(NoMRTKProfileErrorMessage);
                }

                return;
            }

            // If verbose logging is to be enabled, this should be done as early in service
            // initialization as possible to allow for other services to use verbose logging
            // as they initialize.
            DebugUtilities.LogLevel = activeProfile.EnableVerboseLogging ? DebugUtilities.LoggingLevel.Verbose : DebugUtilities.LoggingLevel.Information;

#if UNITY_EDITOR
            if (activeSystems.Count > 0)
            {
                activeSystems.Clear();
            }

            if (registeredMixedRealityServices.Count > 0)
            {
                registeredMixedRealityServices.Clear();
            }

            EnsureEditorSetup();
#endif

            CoreServices.ResetCacheReferences();
            EnsureMixedRealityRequirements();

            #region Services Registration

            // If the Input system has been selected for initialization in the Active profile, enable it in the project
            if (ActiveProfile.IsInputSystemEnabled)
            {
                DebugUtilities.LogVerbose("Begin registration of the input system");

#if UNITY_EDITOR
                // Make sure unity axis mappings are set.	
                InputMappingAxisUtility.CheckUnityInputManagerMappings(ControllerMappingLibrary.UnityInputManagerAxes);
#endif

                object[] args = { ActiveProfile.InputSystemProfile };
                if (!RegisterService<IMixedRealityInputSystem>(ActiveProfile.InputSystemType, args: args) || CoreServices.InputSystem == null)
                {
                    Debug.LogError("Failed to start the Input System!");
                }

                args = new object[] { ActiveProfile.InputSystemProfile };
                if (!RegisterService<IMixedRealityFocusProvider>(ActiveProfile.InputSystemProfile.FocusProviderType, args: args))
                {
                    Debug.LogError("Failed to register the focus provider! The input system will not function without it.");
                    return;
                }

                args = new object[] { ActiveProfile.InputSystemProfile };
                if (!RegisterService<IMixedRealityRaycastProvider>(ActiveProfile.InputSystemProfile.RaycastProviderType, args: args))
                {
                    Debug.LogError("Failed to register the raycast provider! The input system will not function without it.");
                    return;
                }

                DebugUtilities.LogVerbose("End registration of the input system");
            }
            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)
            {
                DebugUtilities.LogVerbose("Begin registration of the boundary system");
                object[] args = { ActiveProfile.BoundaryVisualizationProfile, ActiveProfile.TargetExperienceScale };
                if (!RegisterService<IMixedRealityBoundarySystem>(ActiveProfile.BoundarySystemSystemType, args: args) || CoreServices.BoundarySystem == null)
                {
                    Debug.LogError("Failed to start the Boundary System!");
                }
                DebugUtilities.LogVerbose("End registration of the boundary system");
            }

            // If the Camera system has been selected for initialization in the Active profile, enable it in the project
            if (ActiveProfile.IsCameraSystemEnabled)
            {
                DebugUtilities.LogVerbose("Begin registration of the camera system");
                object[] args = { ActiveProfile.CameraProfile };
                if (!RegisterService<IMixedRealityCameraSystem>(ActiveProfile.CameraSystemType, args: args) || CoreServices.CameraSystem == null)
                {
                    Debug.LogError("Failed to start the Camera System!");
                }
                DebugUtilities.LogVerbose("End registration of the camera system");
            }

            // If the Spatial Awareness system has been selected for initialization in the Active profile, enable it in the project
            if (ActiveProfile.IsSpatialAwarenessSystemEnabled)
            {
                DebugUtilities.LogVerbose("Begin registration of the spatial awareness system");
                object[] args = { ActiveProfile.SpatialAwarenessSystemProfile };
                if (!RegisterService<IMixedRealitySpatialAwarenessSystem>(ActiveProfile.SpatialAwarenessSystemSystemType, args: args) && CoreServices.SpatialAwarenessSystem != null)
                {
                    Debug.LogError("Failed to start the Spatial Awareness System!");
                }
                DebugUtilities.LogVerbose("End registration of 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)
            {
                DebugUtilities.LogVerbose("Begin registration of the teleport system");
                if (!RegisterService<IMixedRealityTeleportSystem>(ActiveProfile.TeleportSystemSystemType) || CoreServices.TeleportSystem == null)
                {
                    Debug.LogError("Failed to start the Teleport System!");
                }
                DebugUtilities.LogVerbose("End registration of the teleport system");
            }

            if (ActiveProfile.IsDiagnosticsSystemEnabled)
            {
                DebugUtilities.LogVerbose("Begin registration of the diagnostic system");
                object[] args = { ActiveProfile.DiagnosticsSystemProfile };
                if (!RegisterService<IMixedRealityDiagnosticsSystem>(ActiveProfile.DiagnosticsSystemSystemType, args: args) || CoreServices.DiagnosticsSystem == null)
                {
                    Debug.LogError("Failed to start the Diagnostics System!");
                }
                DebugUtilities.LogVerbose("End registration of the diagnostic system");
            }

            if (ActiveProfile.IsSceneSystemEnabled)
            {
                DebugUtilities.LogVerbose("Begin registration of the scene system");
                object[] args = { ActiveProfile.SceneSystemProfile };
                if (!RegisterService<IMixedRealitySceneSystem>(ActiveProfile.SceneSystemSystemType, args: args) || CoreServices.SceneSystem == null)
                {
                    Debug.LogError("Failed to start the Scene System!");
                }
                DebugUtilities.LogVerbose("End registration of the scene 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 = { configuration.ComponentName, configuration.Priority, configuration.Profile };
                        RegisterService<IMixedRealityExtensionService>(configuration.ComponentType, configuration.RuntimePlatform, args);
                    }
                }
            }

            #endregion Service Registration

            InitializeAllServices();

            isInitializing = false;
        }