public static void Show(MixedRealityControllerMapping controllerMapping, SerializedProperty interactionsList, Handedness handedness = Handedness.None) { if (window != null) { window.Close(); } window = null; window = CreateInstance <ControllerPopupWindow>(); window.thisWindow = window; window.titleContent = new GUIContent($"{controllerMapping.Description} - Input Action Assignment"); window.currentControllerMapping = controllerMapping; window.currentInteractionList = interactionsList; isMouseInRects = new bool[interactionsList.arraySize]; if (!File.Exists($"{Application.dataPath}{EditorWindowOptionsPath}")) { var empty = new ControllerInputActionOptions { Controllers = new List <ControllerInputActionOption> { new ControllerInputActionOption { Controller = 0, Handedness = Handedness.None, InputLabelPositions = new[] { new Vector2(0, 0) }, IsLabelFlipped = new [] { false } } } }; File.WriteAllText($"{Application.dataPath}{EditorWindowOptionsPath}", JsonUtility.ToJson(empty)); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); } else { controllerInputActionOptions = JsonUtility.FromJson <ControllerInputActionOptions>(File.ReadAllText($"{Application.dataPath}{EditorWindowOptionsPath}")); if (controllerInputActionOptions.Controllers.Any(option => option.Controller == controllerMapping.SupportedControllerType && option.Handedness == handedness)) { window.currentControllerOption = controllerInputActionOptions.Controllers.FirstOrDefault(option => option.Controller == controllerMapping.SupportedControllerType && option.Handedness == handedness); if (window.currentControllerOption != null && window.currentControllerOption.IsLabelFlipped == null) { window.currentControllerOption.IsLabelFlipped = new bool[interactionsList.arraySize]; } } } var windowSize = new Vector2(controllerMapping.HasCustomInteractionMappings ? 896f : 768f, 512f); window.maxSize = windowSize; window.minSize = windowSize; window.CenterOnMainWin(); window.ShowUtility(); defaultLabelWidth = EditorGUIUtility.labelWidth; defaultFieldWidth = EditorGUIUtility.fieldWidth; }
public static void Show(SupportedControllerType controllerType, SerializedProperty interactionsList, Handedness handedness = Handedness.None, bool isLocked = false) { window = (ControllerPopupWindow)GetWindow(typeof(ControllerPopupWindow)); window.Close(); window = (ControllerPopupWindow)CreateInstance(typeof(ControllerPopupWindow)); window.thisWindow = window; var handednessTitleText = handedness != Handedness.None ? $"{handedness} Hand " : string.Empty; window.titleContent = new GUIContent($"{controllerType} {handednessTitleText}Input Action Assignment"); window.currentControllerType = controllerType; window.currentHandedness = handedness; window.isLocked = isLocked; window.currentInteractionList = interactionsList; isMouseInRects = new bool[interactionsList.arraySize]; if (!File.Exists($"{MixedRealityEditorSettings.MixedRealityToolkit_AbsoluteFolderPath}{EditorWindowOptionsPath}")) { var empty = new ControllerInputActionOptions { Controllers = new List <ControllerInputActionOption> { new ControllerInputActionOption { Controller = SupportedControllerType.None, Handedness = Handedness.None, InputLabelPositions = new[] { new Vector2(0, 0) }, IsLabelFlipped = new [] { false } } } }; File.WriteAllText($"{MixedRealityEditorSettings.MixedRealityToolkit_AbsoluteFolderPath}{EditorWindowOptionsPath}", JsonUtility.ToJson(empty)); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); } else { controllerInputActionOptions = JsonUtility.FromJson <ControllerInputActionOptions>(File.ReadAllText($"{MixedRealityEditorSettings.MixedRealityToolkit_AbsoluteFolderPath}{EditorWindowOptionsPath}")); if (controllerInputActionOptions.Controllers.Any(option => option.Controller == controllerType && option.Handedness == handedness)) { window.currentControllerOption = controllerInputActionOptions.Controllers.FirstOrDefault(option => option.Controller == controllerType && option.Handedness == handedness); if (window.currentControllerOption != null && window.currentControllerOption.IsLabelFlipped == null) { window.currentControllerOption.IsLabelFlipped = new bool[interactionsList.arraySize]; } } } window.ShowUtility(); var windowSize = new Vector2(controllerType == SupportedControllerType.GenericOpenVR || controllerType == SupportedControllerType.GenericUnity ? 896f : 768f, 512f); window.maxSize = windowSize; window.minSize = windowSize; window.CenterOnMainWin(); defaultLabelWidth = EditorGUIUtility.labelWidth; defaultFieldWidth = EditorGUIUtility.fieldWidth; }
public static void Show(BaseMixedRealityControllerMappingProfile profile, SupportedControllerType controllerType, SerializedProperty interactionsList, Handedness handedness = Handedness.None, bool isLocked = false) { var handednessTitleText = handedness != Handedness.None ? $"{handedness} Hand " : string.Empty; if (window != null) { window.Close(); } window = (ControllerPopupWindow)CreateInstance(typeof(ControllerPopupWindow)); window.titleContent = new GUIContent($"{controllerType} {handednessTitleText}Input Action Assignment"); window.isLocked = isLocked; window.mappingProfile = profile; window.currentHandedness = handedness; window.currentControllerType = controllerType; window.currentInteractionList = interactionsList; window.currentControllerTexture = ControllerMappingLibrary.GetControllerTexture(profile, controllerType, handedness); isMouseInRects = new bool[interactionsList.arraySize]; var asset = AssetDatabase.LoadAssetAtPath <TextAsset>(EditorWindowOptionsPath); if (asset == null) { var empty = new ControllerInputActionOptions { Controllers = new List <ControllerInputActionOption> { new ControllerInputActionOption { Controller = SupportedControllerType.None, Handedness = Handedness.None, InputLabelPositions = new[] { new Vector2(0, 0) }, IsLabelFlipped = new [] { false } } } }; File.WriteAllText(Path.GetFullPath(EditorWindowOptionsPath), JsonUtility.ToJson(empty, true)); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); } else { controllerInputActionOptions = JsonUtility.FromJson <ControllerInputActionOptions>(asset.text); if (controllerInputActionOptions.Controllers.Any(option => option.Controller == controllerType && option.Handedness == handedness)) { window.currentControllerOption = controllerInputActionOptions.Controllers.FirstOrDefault(option => option.Controller == controllerType && option.Handedness == handedness); if (window.currentControllerOption.IsLabelFlipped == null) { window.currentControllerOption.IsLabelFlipped = new bool[interactionsList.arraySize]; } if (window.currentControllerOption.InputLabelPositions == null) { window.currentControllerOption.InputLabelPositions = new Vector2[interactionsList.arraySize]; } } } var windowSize = new Vector2(window.IsCustomController || window.currentControllerTexture == null ? 896f : 768f, 512f); window.ShowUtility(); window.maxSize = windowSize; window.minSize = windowSize; window.CenterOnMainWin(); defaultLabelWidth = EditorGUIUtility.labelWidth; defaultFieldWidth = EditorGUIUtility.fieldWidth; }
/// <summary> /// Shows the controller pop out window using the provided profile and serialized interaction mapping property /// </summary> /// <param name="profile"></param> /// <param name="interactionMappingProfiles"></param> public static void Show(MixedRealityControllerMappingProfile profile, SerializedProperty interactionMappingProfiles) { var handednessTitleText = profile.Handedness != Handedness.None ? $"{profile.Handedness} Hand " : string.Empty; if (window != null) { window.Close(); } if (profile.ControllerType?.Type == null) { Debug.LogError($"No controller type defined for {profile.name}"); return; } window = (ControllerPopupWindow)CreateInstance(typeof(ControllerPopupWindow)); window.currentControllerName = profile.ControllerType?.Type?.Name; window.currentControllerName = profile.ControllerType?.Type?.Name; window.titleContent = new GUIContent($"{window.currentControllerName} {handednessTitleText}Input Action Assignment"); window.controllerDataProviderProfile = profile; window.currentInteractionProfiles = interactionMappingProfiles; window.currentControllerTexture = ControllerMappingLibrary.GetControllerTexture(profile); isMouseInRects = new bool[interactionMappingProfiles.arraySize]; var asset = AssetDatabase.LoadAssetAtPath <TextAsset>(EditorWindowOptionsPath); if (asset.IsNull()) { var empty = new ControllerInputActionOptions { Controllers = new List <ControllerInputActionOption> { new ControllerInputActionOption { Controller = null, Handedness = Handedness.None, InputLabelPositions = new[] { new Vector2(0, 0) }, IsLabelFlipped = new [] { false } } } }; File.WriteAllText(Path.GetFullPath(EditorWindowOptionsPath), JsonUtility.ToJson(empty, true)); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); } else { controllerInputActionOptions = JsonUtility.FromJson <ControllerInputActionOptions>(asset.text); // if the controller option doesn't exist, then make a new one. if (!controllerInputActionOptions.Controllers.Any(option => option.Controller == window.currentControllerName && option.Handedness == window.Handedness)) { var newOption = new ControllerInputActionOption { Controller = window.currentControllerName, Handedness = window.Handedness, InputLabelPositions = new Vector2[interactionMappingProfiles.arraySize], IsLabelFlipped = new bool[interactionMappingProfiles.arraySize] }; controllerInputActionOptions.Controllers.Add(newOption); } window.currentControllerOption = controllerInputActionOptions.Controllers.FirstOrDefault(option => option.Controller == window.currentControllerName && option.Handedness == window.Handedness); if (window.currentControllerOption.IsLabelFlipped == null) { window.currentControllerOption.IsLabelFlipped = new bool[interactionMappingProfiles.arraySize]; } if (window.currentControllerOption.InputLabelPositions == null) { window.currentControllerOption.InputLabelPositions = new Vector2[interactionMappingProfiles.arraySize]; } } var windowSize = new Vector2(window.IsCustomController || window.currentControllerTexture == null ? 896f : 768f, 512f); window.ShowUtility(); window.maxSize = windowSize; window.minSize = windowSize; window.CenterOnMainWin(); }
/// <summary> /// Displays the controller mapping window for the specified controller mapping /// </summary> /// <param name="controllerMapping"> The controller mapping being modified</param> /// <param name="interactionsList"> The underlying serialized property being modified</param> /// <param name="handedness"> The handedness of the controller </param> /// <param name="mappedControllers"> The list of controller types affected by this mapping</param> public static void Show(MixedRealityControllerMapping controllerMapping, SerializedProperty interactionsList, Handedness handedness = Handedness.None, List <string> mappedControllers = null) { if (window != null) { window.Close(); } window = null; if (!MixedRealityToolkit.IsInitialized) { throw new InvalidOperationException("Mixed Reality Toolkit hasn't been initialized yet! Open a scene with a Mixed Reality Toolkit to initialize it before editing the controller mappings."); } window = CreateInstance <ControllerPopupWindow>(); window.thisWindow = window; window.titleContent = new GUIContent($"{controllerMapping.Description} - Input Action Assignment"); window.mappedControllerList = mappedControllers; window.currentControllerMapping = controllerMapping; window.currentInteractionList = interactionsList; isMouseInRects = new bool[interactionsList.arraySize]; string editorWindowOptionsPath = ResolveEditorWindowOptionsPath(); if (!File.Exists(editorWindowOptionsPath)) { var empty = new ControllerInputActionOptions { Controllers = new List <ControllerInputActionOption> { new ControllerInputActionOption { Controller = 0, Handedness = Handedness.None, InputLabelPositions = new[] { new Vector2(0, 0) }, IsLabelFlipped = new [] { false } } } }; File.WriteAllText(editorWindowOptionsPath, JsonUtility.ToJson(empty, true)); AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); } else { controllerInputActionOptions = JsonUtility.FromJson <ControllerInputActionOptions>(File.ReadAllText(editorWindowOptionsPath)); if (controllerInputActionOptions.Controllers.Any(option => option.Controller == controllerMapping.SupportedControllerType && option.Handedness == handedness)) { window.currentControllerOption = controllerInputActionOptions.Controllers.FirstOrDefault(option => option.Controller == controllerMapping.SupportedControllerType && option.Handedness == handedness); if (window.currentControllerOption != null && window.currentControllerOption.IsLabelFlipped == null) { window.currentControllerOption.IsLabelFlipped = new bool[interactionsList.arraySize]; } } } var windowSize = new Vector2(controllerMapping.HasCustomInteractionMappings ? 896f : 768f, 512f); window.maxSize = windowSize; window.minSize = windowSize; window.CenterOnMainWin(); window.ShowUtility(); defaultLabelWidth = EditorGUIUtility.labelWidth; defaultFieldWidth = EditorGUIUtility.fieldWidth; }