/// <inheritdoc /> public WindowsDictationDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile, IMixedRealityInputSystem parentService) : base(name, priority, profile, parentService) { #if UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN if (dictationRecognizer == null) { try { dictationRecognizer = new DictationRecognizer(); } catch (UnityException e) { switch (e.Message) { case string message when message.Contains("Speech recognition is not supported on this machine."): Debug.LogWarning($"Skipping {nameof(WindowsDictationDataProvider)} registration.\n{e.Message}"); break; default: throw; } } } #endif // UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN }
/// <summary> /// Constructor. /// </summary> /// <param name="name"></param> /// <param name="priority"></param> /// <param name="profile"></param> public WindowsDictationDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile) : base(name, priority, profile) { #if UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN if (dictationRecognizer == null) { dictationRecognizer = new DictationRecognizer(); } #endif // UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN }
/// <inheritdoc /> public WindowsSpeechDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile, IMixedRealityInputSystem parentService) : base(name, priority, profile, parentService) { if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile == null) { throw new Exception("Missing required input system profile!"); } if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile == null) { throw new Exception("Missing required speech commands profile!"); } if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile.SpeechCommands == null) { throw new Exception("Null speech commands in the speech commands profile!"); } #if UNITY_WSA && UNITY_EDITOR if (!UnityEditor.PlayerSettings.WSA.GetCapability(UnityEditor.PlayerSettings.WSACapability.Microphone)) { UnityEditor.PlayerSettings.WSA.SetCapability(UnityEditor.PlayerSettings.WSACapability.Microphone, true); } #endif #if UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN var newKeywords = new string[Commands.Length]; for (int i = 0; i < Commands.Length; i++) { newKeywords[i] = Commands[i].Keyword; } RecognitionConfidenceLevel = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile.SpeechRecognitionConfidenceLevel; if (keywordRecognizer == null) { try { keywordRecognizer = new KeywordRecognizer(newKeywords, (ConfidenceLevel)RecognitionConfidenceLevel); } catch (UnityException e) { switch (e.Message) { case string message when message.Contains("Speech recognition is not supported on this machine."): Debug.LogWarning($"Skipping {nameof(WindowsSpeechDataProvider)} registration.\n{e.Message}"); break; default: throw; } } } #endif // UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN }
/// <inheritdoc /> protected BaseControllerDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile, IMixedRealityInputSystem parentService) : base(name, priority, profile, parentService) { if (profile.IsNull()) { throw new UnassignedReferenceException($"A {nameof(profile)} is required for {name}"); } controllerMappingProfiles = profile.ControllerMappingProfiles; if (controllerMappingProfiles == null || controllerMappingProfiles.Length == 0) { throw new UnassignedReferenceException($"{nameof(controllerMappingProfiles)} has no defined controller mappings for {name}"); } }
/// <summary> /// Constructor. /// </summary> /// <param name="name"></param> /// <param name="priority"></param> /// <param name="profile"></param> public WindowsSpeechDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile) : base(name, priority, profile) { if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile == null) { throw new Exception("Missing required input system profile!"); } if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile == null) { throw new Exception("Missing required speech commands profile!"); } if (MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile.SpeechCommands == null) { throw new Exception("Null speech commands in the speech commands profile!"); } #if UNITY_WSA && UNITY_EDITOR if (!UnityEditor.PlayerSettings.WSA.GetCapability(UnityEditor.PlayerSettings.WSACapability.Microphone)) { UnityEditor.PlayerSettings.WSA.SetCapability(UnityEditor.PlayerSettings.WSACapability.Microphone, true); } #endif #if UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN var newKeywords = new string[Commands.Length]; for (int i = 0; i < Commands.Length; i++) { newKeywords[i] = Commands[i].Keyword; } RecognitionConfidenceLevel = MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile.SpeechCommandsProfile.SpeechRecognitionConfidenceLevel; if (keywordRecognizer == null) { keywordRecognizer = new KeywordRecognizer(newKeywords, (ConfidenceLevel)RecognitionConfidenceLevel); } #endif // UNITY_STANDALONE_WIN || UNITY_WSA || UNITY_EDITOR_WIN }
/// <summary> /// Constructor. /// </summary> /// <param name="name"></param> /// <param name="priority"></param> /// <param name="profile"></param> public UnityJoystickDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile) : base(name, priority, profile) { }
/// <summary> /// Constructor. /// </summary> /// <param name="name"></param> /// <param name="priority"></param> /// <param name="profile"></param> protected BaseSpeechDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile) : base(name, priority, profile) { }
/// <inheritdoc /> protected BaseSpeechDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile, IMixedRealityInputSystem parentService) : base(name, priority, profile, parentService) { }
/// <summary> /// Constructor. /// </summary> /// <param name="dataProviderType"></param> /// <param name="dataProviderName"></param> /// <param name="priority"></param> /// <param name="runtimePlatform"></param> /// <param name="profile"></param> public ControllerDataProviderConfiguration(SystemType dataProviderType, string dataProviderName, uint priority, SupportedPlatforms runtimePlatform, BaseMixedRealityControllerDataProviderProfile profile) { this.dataProviderType = dataProviderType; this.dataProviderName = dataProviderName; this.priority = priority; this.runtimePlatform = runtimePlatform; this.profile = profile; }
protected override void OnEnable() { base.OnEnable(); serializedObject.Update(); hasSetupDefaults = serializedObject.FindProperty(nameof(hasSetupDefaults)); controllerMappingProfiles = serializedObject.FindProperty(nameof(controllerMappingProfiles)); dataProviderProfile = (BaseMixedRealityControllerDataProviderProfile)serializedObject.targetObject; if (!hasSetupDefaults.boolValue) { var defaultControllerOptions = dataProviderProfile.GetDefaultControllerOptions(); Debug.Assert(defaultControllerOptions != null, $"Missing default controller definitions for {dataProviderProfile.name}"); var profileRootPath = AssetDatabase.GetAssetPath(dataProviderProfile); profileRootPath = $"{Directory.GetParent(Directory.GetParent(profileRootPath).FullName).FullName}/DataProviders"; controllerMappingProfiles.ClearArray(); for (int i = 0; i < defaultControllerOptions.Length; i++) { var defaultControllerOption = defaultControllerOptions[i]; var controllerMappingAsset = CreateInstance(nameof(MixedRealityControllerMappingProfile)).CreateAsset($"{profileRootPath}/", $"{defaultControllerOption.Description}Profile", false) as MixedRealityControllerMappingProfile; Debug.Assert(controllerMappingAsset != null); var mappingProfileSerializedObject = new SerializedObject(controllerMappingAsset); mappingProfileSerializedObject.Update(); var controllerTypeProperty = mappingProfileSerializedObject.FindProperty("controllerType").FindPropertyRelative("reference"); var handednessProperty = mappingProfileSerializedObject.FindProperty("handedness"); var useCustomInteractionsProperty = mappingProfileSerializedObject.FindProperty("useCustomInteractions"); var interactionMappingProfilesProperty = mappingProfileSerializedObject.FindProperty("interactionMappingProfiles"); if (defaultControllerOption.ControllerType.Type.GUID != Guid.Empty) { controllerTypeProperty.stringValue = defaultControllerOption.ControllerType.Type.GUID.ToString(); } else { Debug.LogError($"{defaultControllerOption.ControllerType} requires a {nameof(GuidAttribute)}"); } handednessProperty.intValue = (int)defaultControllerOption.Handedness; useCustomInteractionsProperty.boolValue = defaultControllerOption.UseCustomInteractions; SetDefaultInteractionMapping(); mappingProfileSerializedObject.ApplyModifiedProperties(); controllerMappingProfiles.InsertArrayElementAtIndex(i); var mappingProfile = controllerMappingProfiles.GetArrayElementAtIndex(i); mappingProfile.objectReferenceValue = controllerMappingAsset; mappingProfile.serializedObject.ApplyModifiedProperties(); void SetDefaultInteractionMapping() { if (Activator.CreateInstance(new SystemType(controllerTypeProperty.stringValue)) is BaseController detectedController) { interactionMappingProfilesProperty.ClearArray(); switch ((Handedness)handednessProperty.intValue) { case Handedness.Left: CreateDefaultMappingProfiles(detectedController.DefaultLeftHandedInteractions); break; case Handedness.Right: CreateDefaultMappingProfiles(detectedController.DefaultRightHandedInteractions); break; default: CreateDefaultMappingProfiles(detectedController.DefaultInteractions); break; } } void CreateDefaultMappingProfiles(MixedRealityInteractionMapping[] defaultMappings) { var mappingProfileRootPath = AssetDatabase.GetAssetPath(controllerMappingAsset); mappingProfileRootPath = mappingProfileRootPath.Replace("DataProviderProfile", string.Empty); for (int j = 0; j < defaultMappings.Length; j++) { var interactionMappingProfileAsset = CreateInstance(nameof(MixedRealityInteractionMappingProfile)).CreateAsset($"{mappingProfileRootPath}/", $"{defaultMappings[j].Description}Profile", false) as MixedRealityInteractionMappingProfile; Debug.Assert(interactionMappingProfileAsset != null); var mapping = defaultMappings[j]; var interactionMappingProfileSerializedObject = new SerializedObject(interactionMappingProfileAsset); interactionMappingProfileSerializedObject.Update(); var interactionMappingProperty = interactionMappingProfileSerializedObject.FindProperty("interactionMapping"); var descriptionProperty = interactionMappingProperty.FindPropertyRelative("description"); //var stateChangeTypeProperty = interactionMappingProperty.FindPropertyRelative("stateChangeType"); var inputNameProperty = interactionMappingProperty.FindPropertyRelative("inputName"); var axisTypeProperty = interactionMappingProperty.FindPropertyRelative("axisType"); var inputTypeProperty = interactionMappingProperty.FindPropertyRelative("inputType"); var keyCodeProperty = interactionMappingProperty.FindPropertyRelative("keyCode"); var axisCodeXProperty = interactionMappingProperty.FindPropertyRelative("axisCodeX"); var axisCodeYProperty = interactionMappingProperty.FindPropertyRelative("axisCodeY"); var inputProcessorsProperty = interactionMappingProperty.FindPropertyRelative("inputProcessors"); descriptionProperty.stringValue = mapping.Description; //stateChangeTypeProperty.intValue = (int)mapping.StateChangeType; inputNameProperty.stringValue = mapping.InputName; axisTypeProperty.intValue = (int)mapping.AxisType; inputTypeProperty.intValue = (int)mapping.InputType; keyCodeProperty.intValue = (int)mapping.KeyCode; axisCodeXProperty.stringValue = mapping.AxisCodeX; axisCodeYProperty.stringValue = mapping.AxisCodeY; for (int k = 0; k < mapping.InputProcessors.Count; k++) { inputProcessorsProperty.InsertArrayElementAtIndex(k); var processorProperty = inputProcessorsProperty.GetArrayElementAtIndex(k); var processor = mapping.InputProcessors[k]; var processorAsset = processor.GetOrCreateAsset($"{mappingProfileRootPath}/", false); processorProperty.objectReferenceValue = processorAsset; } interactionMappingProfileSerializedObject.ApplyModifiedProperties(); interactionMappingProfilesProperty.InsertArrayElementAtIndex(j); var interactionsProperty = interactionMappingProfilesProperty.GetArrayElementAtIndex(j); interactionsProperty.objectReferenceValue = interactionMappingProfileAsset; } } } } hasSetupDefaults.boolValue = true; serializedObject.ApplyModifiedProperties(); } mappingProfileList = new ReorderableList(serializedObject, controllerMappingProfiles, true, false, true, true) { elementHeight = EditorGUIUtility.singleLineHeight * 1.5f }; mappingProfileList.drawElementCallback += DrawConfigurationOptionElement; mappingProfileList.onAddCallback += OnConfigurationOptionAdded; mappingProfileList.onRemoveCallback += OnConfigurationOptionRemoved; }
/// <summary> /// Controller Mapping function to test for a controller mapping /// </summary> /// <param name="profile"></param> /// <param name="mappingTypesToValidate">Array of controller mappings to validate</param> /// <param name="prompt">Unit Test helper, to control whether the UI prompt is offered or not</param> /// <returns></returns> public static bool ValidateControllerProfiles(this BaseMixedRealityControllerDataProviderProfile profile, Type[] mappingTypesToValidate, bool prompt = true) { #if UNITY_EDITOR if (Application.isPlaying || EditorPrefs.GetBool(IgnoreKey, false)) { return(false); } #endif //UNITY_EDITOR if (MixedRealityToolkit.HasActiveProfile) { var errorsFound = false; var mappingConfigurationSource = profile.ControllerMappingProfiles; if (mappingConfigurationSource != null) { if (mappingTypesToValidate != null && mappingTypesToValidate.Length > 0) { var typesValidated = new bool[mappingTypesToValidate.Length]; for (int i = 0; i < mappingTypesToValidate.Length; i++) { foreach (var mappingProfile in mappingConfigurationSource) { if (mappingProfile.ControllerType == null) { continue; } if (mappingProfile.ControllerType == mappingTypesToValidate[i]) { typesValidated[i] = true; } } } for (var i = 0; i < typesValidated.Length; i++) { if (!typesValidated[i]) { errorsFound = true; } } if (errorsFound) { var errorDescription = new StringBuilder(); errorDescription.AppendLine("The following Controller Types were not found in the current Mixed Reality Configuration profile:\n"); for (int i = 0; i < typesValidated.Length; i++) { if (!typesValidated[i]) { errorDescription.AppendLine($" [{mappingTypesToValidate[i]}]"); } } errorDescription.AppendLine($"\nYou will need to either create a profile and add it to your Controller mappings, or assign the default from the 'DefaultProfiles' folder in the associated package"); #if UNITY_EDITOR if (prompt) { if (EditorUtility.DisplayDialog("Controller Mappings not found", errorDescription.ToString(), "Ignore", "Later")) { EditorPrefs.SetBool(IgnoreKey, true); } } #endif //UNITY_EDITOR } else { return(true); } } } } return(false); }
/// <summary> /// Constructor. /// </summary> /// <param name="name"></param> /// <param name="priority"></param> /// <param name="profile"></param> public BaseControllerDataProvider(string name, uint priority, BaseMixedRealityControllerDataProviderProfile profile) : base(name, priority) { }