Beispiel #1
0
        /// <summary>
        /// Installs the provided <see cref="MixedRealityServiceConfiguration"/> in the provided <see cref="MixedRealityToolkitRootProfile"/>.
        /// </summary>
        /// <param name="platformConfigurationProfile">The platform configuration to install.</param>
        /// <param name="rootProfile">The root profile to install the </param>
        public static void InstallConfiguration(MixedRealityPlatformServiceConfigurationProfile platformConfigurationProfile, MixedRealityToolkitRootProfile rootProfile)
        {
            foreach (var configuration in platformConfigurationProfile.Configurations)
            {
                var configurationType = configuration.InstancedType.Type;

                if (configurationType == null)
                {
                    Debug.LogError($"Failed to find a valid {nameof(configuration.InstancedType)} for {configuration.Name}!");
                    continue;
                }

                switch (configurationType)
                {
                case Type _ when typeof(IMixedRealityCameraDataProvider).IsAssignableFrom(configurationType):
                    var cameraSystemProfile             = rootProfile.CameraSystemProfile;
                    var cameraDataProviderConfiguration = new MixedRealityServiceConfiguration <IMixedRealityCameraDataProvider>(configuration);

                    if (cameraSystemProfile.RegisteredServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != cameraDataProviderConfiguration.InstancedType.Type))
                    {
                        Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
                        cameraSystemProfile.RegisteredServiceConfigurations = cameraSystemProfile.RegisteredServiceConfigurations.AddItem(cameraDataProviderConfiguration);
                        EditorUtility.SetDirty(cameraSystemProfile);
                    }
                    break;

                case Type _ when typeof(IMixedRealityInputDataProvider).IsAssignableFrom(configurationType):
                    var inputSystemProfile             = rootProfile.InputSystemProfile;
                    var inputDataProviderConfiguration = new MixedRealityServiceConfiguration <IMixedRealityInputDataProvider>(configuration);

                    if (inputSystemProfile.RegisteredServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != inputDataProviderConfiguration.InstancedType.Type))
                    {
                        Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
                        inputSystemProfile.RegisteredServiceConfigurations = inputSystemProfile.RegisteredServiceConfigurations.AddItem(inputDataProviderConfiguration);
                        EditorUtility.SetDirty(inputSystemProfile);
                    }
                    break;

                case Type _ when typeof(IMixedRealitySpatialAwarenessDataProvider).IsAssignableFrom(configurationType):
                    var spatialAwarenessSystemProfile = rootProfile.SpatialAwarenessProfile;
                    var spatialObserverConfiguration  = new MixedRealityServiceConfiguration <IMixedRealitySpatialAwarenessDataProvider>(configuration);

                    if (spatialAwarenessSystemProfile.RegisteredServiceConfigurations.All(serviceConfiguration => serviceConfiguration.InstancedType.Type != spatialObserverConfiguration.InstancedType.Type))
                    {
                        Debug.Log($"Added {configuration.Name} to {rootProfile.name}");
                        spatialAwarenessSystemProfile.RegisteredServiceConfigurations = spatialAwarenessSystemProfile.RegisteredServiceConfigurations.AddItem(spatialObserverConfiguration);
                        EditorUtility.SetDirty(spatialAwarenessSystemProfile);
                    }
                    break;
                }
            }

            AssetDatabase.SaveAssets();
            EditorApplication.delayCall += () => AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
        }
        public void Test_02_ConfirmExtensionServiceProviderConfigurationPresent()
        {
            SetupServiceLocator();
            var profile           = MixedRealityToolkit.Instance.ActiveProfile.RegisteredServiceProvidersProfile;
            var dataProviderTypes = new[] { typeof(TestExtensionService1) };
            var newConfig         = new MixedRealityServiceConfiguration <IMixedRealityExtensionService>(typeof(TestExtensionService1), "Test Extension Service 1", 2, testPlatforms, null);

            Debug.Assert(newConfig != null);
            var newConfigs = profile.RegisteredServiceConfigurations.AddItem(newConfig);

            Debug.Assert(newConfigs != null);
            profile.RegisteredServiceConfigurations = newConfigs;
            Assert.IsTrue(profile.ValidateService(dataProviderTypes, newConfigs, false));
        }
Beispiel #3
0
        /// <summary>
        /// Draws the profile for all of the service's interfaces that have custom inspectors, if wanted by inspector and found.
        /// </summary>
        private bool DrawProfile(Type serviceType)
        {
            bool drawProfileField = true;

            foreach (Type interfaceType in serviceType.GetInterfaces())
            {
                IMixedRealityServiceInspector inspectorInstance;
                if (GetServiceInspectorInstance(interfaceType, out inspectorInstance))
                {
                    drawProfileField &= inspectorInstance.DrawProfileField;
                }
            }

            if (!drawProfileField)
            {   // We've been instructed to skip drawing a profile by the inspector
                return(false);
            }

            bool foundAndDrewProfile = false;

            // Draw the base profile stuff
            if (typeof(BaseCoreSystem).IsAssignableFrom(serviceType))
            {
                SerializedObject activeProfileObject = new SerializedObject(MixedRealityToolkit.Instance.ActiveProfile);
                // Would be nice to handle this using some other method
                // Would be nice to handle this with a lookup instead
                if (typeof(IMixedRealityInputSystem).IsAssignableFrom(serviceType))
                {
                    SerializedProperty serviceProfileProp = activeProfileObject.FindProperty("inputSystemProfile");
                    BaseMixedRealityProfileInspector.RenderReadOnlyProfile(serviceProfileProp);
                    EditorGUILayout.Space();
                    foundAndDrewProfile = true;
                }
                else if (typeof(IMixedRealityBoundarySystem).IsAssignableFrom(serviceType))
                {
                    SerializedProperty serviceProfileProp = activeProfileObject.FindProperty("boundaryVisualizationProfile");
                    BaseMixedRealityProfileInspector.RenderReadOnlyProfile(serviceProfileProp);
                    EditorGUILayout.Space();
                    foundAndDrewProfile = true;
                }
                else if (typeof(IMixedRealityDiagnosticsSystem).IsAssignableFrom(serviceType))
                {
                    SerializedProperty serviceProfileProp = activeProfileObject.FindProperty("diagnosticsSystemProfile");
                    BaseMixedRealityProfileInspector.RenderReadOnlyProfile(serviceProfileProp);
                    EditorGUILayout.Space();
                    foundAndDrewProfile = true;
                }
                else if (typeof(IMixedRealitySpatialAwarenessSystem).IsAssignableFrom(serviceType))
                {
                    SerializedProperty serviceProfileProp = activeProfileObject.FindProperty("spatialAwarenessSystemProfile");
                    BaseMixedRealityProfileInspector.RenderReadOnlyProfile(serviceProfileProp);
                    EditorGUILayout.Space();
                    foundAndDrewProfile = true;
                }
                else if (typeof(IMixedRealityCameraSystem).IsAssignableFrom(serviceType))
                {
                    SerializedProperty serviceProfileProp = activeProfileObject.FindProperty("cameraProfile");
                    BaseMixedRealityProfileInspector.RenderReadOnlyProfile(serviceProfileProp);
                    EditorGUILayout.Space();
                    foundAndDrewProfile = true;
                }
                else if (typeof(IMixedRealitySceneSystem).IsAssignableFrom(serviceType))
                {
                    SerializedProperty serviceProfileProp = activeProfileObject.FindProperty("sceneSystemProfile");
                    BaseMixedRealityProfileInspector.RenderReadOnlyProfile(serviceProfileProp);
                    EditorGUILayout.Space();
                    foundAndDrewProfile = true;
                }
            }
            else if (typeof(BaseExtensionService).IsAssignableFrom(serviceType))
            {
                // Make sure the extension service profile isn't null
                if (MixedRealityToolkit.Instance.ActiveProfile.RegisteredServiceProvidersProfile != null)
                {
                    // If this is an extension service, see if it uses a profile
                    MixedRealityServiceConfiguration[] serviceConfigs = MixedRealityToolkit.Instance.ActiveProfile.RegisteredServiceProvidersProfile.Configurations;
                    for (int serviceIndex = 0; serviceIndex < serviceConfigs.Length; serviceIndex++)
                    {
                        MixedRealityServiceConfiguration serviceConfig = serviceConfigs[serviceIndex];
                        if (serviceConfig.ComponentType.Type.IsAssignableFrom(serviceType) && serviceConfig.Profile != null)
                        {
                            // We found the service that this type uses - draw the profile
                            SerializedObject   serviceConfigObject = new SerializedObject(MixedRealityToolkit.Instance.ActiveProfile.RegisteredServiceProvidersProfile);
                            SerializedProperty serviceConfigArray  = serviceConfigObject.FindProperty("configurations");
                            SerializedProperty serviceConfigProp   = serviceConfigArray.GetArrayElementAtIndex(serviceIndex);
                            SerializedProperty serviceProfileProp  = serviceConfigProp.FindPropertyRelative("configurationProfile");
                            BaseMixedRealityProfileInspector.RenderReadOnlyProfile(serviceProfileProp);
                            EditorGUILayout.Space();
                            foundAndDrewProfile = true;
                            break;
                        }
                    }
                }
            }

            return(foundAndDrewProfile);
        }