public static void ResetGUIState() { EasyGUI.ClearStacks(); EditorGUIUtilityHelper.SetBoldDefaultFont(false); ScriptAttributeUtility.PropertyHandlerCache = null; InspectableAttributeUtility.InspectableHandlerCache = null; }
private float GetWindowYPosition(float requestedYPosition, float windowHeight) { float distanceToBottomBorder = EditorGUIUtilityHelper.GetMainWindowPosition().yMax - requestedYPosition; if (distanceToBottomBorder < windowHeight) { return(EditorGUIUtilityHelper.GetMainWindowPosition().yMax - windowHeight); } return(requestedYPosition); }
/// <summary> /// Centers the window in the main Unity window. This is not the same as centering a window on screen, /// because the Unity window may not be maximized. /// </summary> /// <param name="window">The window to center.</param> [PublicAPI] public static void CenterOnMainWin(this EditorWindow window) { Rect main = EditorGUIUtilityHelper.GetMainWindowPosition(); Rect pos = window.position; float centerWidth = (main.width - pos.width) * 0.5f; float centerHeight = (main.height - pos.height) * 0.5f; pos.x = main.x + centerWidth; pos.y = main.y + centerHeight; window.position = pos; }
private float GetWindowXPosition(float requestedXPosition, float windowWidth) { // If the window width is smaller than the distance from cursor to the right border of the window, the // window will not appear because the cursor is outside of the window and OnGUI will never be called. float screenWidth = EditorGUIUtilityHelper.GetScreenWidth(); requestedXPosition -= 8f; // This will make the window appear so that foldout arrows are precisely below the cursor. float distanceToRightBorder = screenWidth - requestedXPosition; if (windowWidth > distanceToRightBorder) { requestedXPosition = screenWidth - windowWidth; } return(requestedXPosition); }
/// <summary>Resizes the window to the needed size.</summary> /// <param name="window">The window to change the size of.</param> /// <param name="width">The width to set. If the value is -1f, the width will not be changed.</param> /// <param name="height">The height to set. If the value is -1f, the height will not be changed.</param> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown if width or height are negative numbers and not -1f. /// </exception> /// <example><code> /// public class DummyWindow : EditorWindow /// { /// private void OnCreate(Rect buttonRect) /// { /// var windowSize = new Vector2(100f, 100f); /// ShowAsDropDown(buttonRect, windowSize); /// } /// /// private void OnGUI() /// { /// float optimalWidth = CalculateOptimalWidth(); /// float optimalHeight = Math.Min(_contentHeight, DropdownStyle.MaxWindowHeight); /// this.Resize(optimalWidth, optimalHeight); /// } /// } /// </code></example> [PublicAPI] public static void Resize(this EditorWindow window, float width = -1f, float height = -1f) { EnsureTheValueIsNotNegative(nameof(width), width); EnsureTheValueIsNotNegative(nameof(height), height); bool changeWidth = width != -1f; bool changeHeight = height != -1f; Rect positionToAdjust = window.position; if (changeWidth) { positionToAdjust.width = width; } if (changeHeight) { positionToAdjust.height = height; } window.minSize = new Vector2(changeWidth ? width : window.minSize.x, changeHeight ? height : window.minSize.y); window.maxSize = new Vector2(changeWidth ? width : window.maxSize.x, changeHeight ? height : window.maxSize.y); if (changeWidth) { float screenWidth = EditorGUIUtilityHelper.GetScreenWidth(); if (positionToAdjust.xMax >= screenWidth) { positionToAdjust.x -= positionToAdjust.xMax - screenWidth; } } if (changeHeight) { // MainWindow is more reliable than Screen.currentResolution.height, especially for the multi-display setup. float mainWinYMax = EditorGUIUtilityHelper.GetMainWindowPosition().yMax; if (positionToAdjust.yMax >= mainWinYMax) { positionToAdjust.y -= positionToAdjust.yMax - mainWinYMax; } } window.position = positionToAdjust; }
private static void OnGUI(string searchContext) { using var _ = EditorGUIUtilityHelper.LabelWidthBlock(220f); ProjectSettings.SearchbarMinItemsCount = EditorGUILayout.IntField(new GUIContent(SearchbarLabel, SearchbarTooltip), ProjectSettings.SearchbarMinItemsCount, GUILayout.MaxWidth(300f)); ProjectSettings.UseBuiltInNames = EditorGUILayout.Toggle(new GUIContent(BuiltInLabel, BuiltInTooltip), ProjectSettings.UseBuiltInNames); }