Пример #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);
        }
Пример #2
0
        // NOTE: This method intentionally does not add to the registry. This is actually mostly a helper function for RegisterServiceInternal<T>.
        private bool RegisterServiceInternal(Type interfaceType, IMixedRealityService serviceInstance)
        {
            if (serviceInstance == null)
            {
                Debug.LogWarning($"Unable to add a {interfaceType.Name} service with a null instance.");
                return(false);
            }

            if (!CanGetService(interfaceType))
            {
                return(false);
            }

            IMixedRealityService preExistingService = GetServiceByNameInternal(interfaceType, serviceInstance.Name);

            if (preExistingService != null)
            {
                Debug.LogError($"There's already a {interfaceType.Name}.{preExistingService.Name} registered!");
                return(false);
            }

            if (IsCoreSystem(interfaceType))
            {
                activeSystems.Add(interfaceType, serviceInstance);
            }
            else if (typeof(IMixedRealityDataProvider).IsAssignableFrom(interfaceType) ||
                     typeof(IMixedRealityExtensionService).IsAssignableFrom(interfaceType))
            {
                registeredMixedRealityServices.Add(new Tuple <Type, IMixedRealityService>(interfaceType, serviceInstance));
            }
            else
            {
                Debug.LogError($"Unable to register {interfaceType.Name}. Concrete type does not implement {typeof(IMixedRealityExtensionService).Name} or {typeof(IMixedRealityDataProvider).Name}.");
                return(false);
            }

            if (!isInitializing)
            {
                serviceInstance.Initialize();
                serviceInstance.Enable();
            }

            return(true);
        }