示例#1
0
        /// <summary>
        /// Add a new service to the Mixed Reality Toolkit active service registry.
        /// </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 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(false);
            }

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

            if (IsCoreSystem(type))
            {
                IMixedRealityService preExistingService;

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

                if (preExistingService == null)
                {
                    ActiveProfile.ActiveServices.Add(type, service);
                    return(true);
                }

                Debug.LogError($"There's already a {type.Name} registered.");
                return(false);
            }

            if (!typeof(IMixedRealityExtensionService).IsAssignableFrom(type))
            {
                Debug.LogError($"Unable to register {type}. Concrete type does not implement the IMixedRealityExtensionService implementation.");
                return(false);
            }

            MixedRealityComponents.Add(new Tuple <Type, IMixedRealityExtensionService>(type, (IMixedRealityExtensionService)service));
            if (!isInitializing)
            {
                service.Initialize();
            }
            mixedRealityComponentsCount = MixedRealityComponents.Count;
            return(true);
        }
        /// <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;
            }
        }