/// <summary> /// Add a new manager to the Mixed Reality Manager active Manager registry. /// </summary> /// <param name="type">The interface type for the system to be managed. E.G. InputSystem, BoundarySystem</param> /// <param name="manager">The Instance of the manager class to register</param> public void AddManager(Type type, IMixedRealityManager manager) { if (ActiveProfile == null) { Debug.LogError($"Unable to add a new {type.Name} Manager as the Mixed Reality manager has to Active Profile"); } if (type == null) { throw new ArgumentNullException(nameof(type)); } if (manager == null) { throw new ArgumentNullException(nameof(manager)); } if (IsCoreManagerType(type)) { IMixedRealityManager preexistingManager; if (IsCoreManagerType(type)) { ActiveProfile.ActiveManagers.TryGetValue(type, out preexistingManager); } else { GetComponentByType(type, out preexistingManager); } if (preexistingManager == null) { ActiveProfile.ActiveManagers.Add(type, manager); } else { Debug.LogError($"There's already a {type.Name} registered."); } } else { MixedRealityComponents.Add(new Tuple <Type, IMixedRealityManager>(type, manager)); if (!isMixedRealityManagerInitializing) { manager.Initialize(); } mixedRealityComponentsCount = MixedRealityComponents.Count; } }
/// <summary> /// Retrieve the first component from the registry that meets the selected type and name /// </summary> /// <param name="type">Interface type of the component being requested</param> /// <param name="managerName">Name of the specific manager</param> /// <param name="manager">return parameter of the function</param> private void GetComponentByTypeAndName(Type type, string managerName, out IMixedRealityManager manager) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (string.IsNullOrEmpty(managerName)) { throw new ArgumentNullException(nameof(managerName)); } manager = null; for (int i = 0; i < mixedRealityComponentsCount; i++) { if (MixedRealityComponents[i].Item1.Name == type.Name && MixedRealityComponents[i].Item2.Name == managerName) { manager = MixedRealityComponents[i].Item2; break; } } }
/// <summary> /// Retrieve the first component from the registry that meets the selected type /// </summary> /// <param name="type">Interface type of the component being requested</param> /// <param name="manager">return parameter of the function</param> private void GetComponentByType(Type type, out IMixedRealityManager manager) { if (type == null) { throw new ArgumentNullException(nameof(type)); } manager = null; for (int i = 0; i < mixedRealityComponentsCount; i++) { if (MixedRealityComponents[i].Item1.Name == type.Name || MixedRealityComponents[i].Item2.GetType().Name == type.Name) { manager = MixedRealityComponents[i].Item2; break; } } if (manager == null) { throw new NullReferenceException($"Unable to find {type.Name} Manager."); } }