private void OnGUI() { if (flippedLabelStyle == null) { flippedLabelStyle = new GUIStyle("Label") { alignment = TextAnchor.UpperRight, stretchWidth = true }; } if (!IsCustomController && currentControllerTexture != null) { GUILayout.BeginHorizontal(); GUI.DrawTexture(ControllerRectPosition, currentControllerTexture); GUILayout.EndHorizontal(); } try { RenderInteractionList(currentInteractionList, IsCustomController); } catch (Exception) { thisWindow.Close(); } }
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; }