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; }
/// <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; }