Exemplo n.º 1
0
        private Rect GetWindowRect(Vector2 windowPosition, float windowHeight)
        {
            // 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 = EditorDrawHelper.GetScreenWidth();

            windowPosition.x -= 8f; // This will make the window appear so that foldout arrows are precisely below the cursor.
            float distanceToRightBorder = screenWidth - windowPosition.x;

            if (_optimalWidth > distanceToRightBorder)
            {
                distanceToRightBorder = _optimalWidth;
                windowPosition.x      = screenWidth - _optimalWidth;
            }

            // If given less than 100f, the window will re-position to the top left corner. If given 0f on MacOS,
            // the window may not appear at all. Thus, the minimal value is 100f.
            const float minHeightOnStart = 100f;

            windowHeight = windowHeight < 100f ? minHeightOnStart : windowHeight;

            float distanceToBottomBorder = EditorDrawHelper.GetMainWindowPosition().yMax - windowPosition.y;

            if (distanceToBottomBorder < windowHeight)
            {
                windowPosition.y = EditorDrawHelper.GetMainWindowPosition().yMax - windowHeight;
            }

            var windowSize = new Vector2(distanceToRightBorder, windowHeight);

            return(new Rect(windowPosition, windowSize));
        }
Exemplo n.º 2
0
 void OnGUI()
 {
     if (mExcel != null)
     {
         EditorDrawHelper.DrawTableTab(mExcel, ref selectIndex);
         mTable = mExcel.Tables[selectIndex];
         EditorDrawHelper.DrawTable(mTable);
         DrawButton();
     }
 }
Exemplo n.º 3
0
        /// <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 = EditorDrawHelper.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 void DrawContent()
        {
            DrawInFixedRectIfNeeded(() =>
            {
                float contentHeight = EditorDrawHelper.DrawVertically(_selectionTree.Draw, _preventExpandingHeight,
                                                                      DropdownStyle.BackgroundColor);

                if (_contentHeight == 0f || Event.current.type == EventType.Repaint)
                {
                    _contentHeight = contentHeight;
                }

                EditorDrawHelper.DrawBorders(position.width, position.height, DropdownStyle.BorderColor);
            });
        }
Exemplo n.º 5
0
    public void DrawButton()
    {
        EditorGUILayout.BeginHorizontal();
        EditorDrawHelper.DrawButton("Add", delegate()
        {
            mTable.NumberOfRows++;
            Show(mExcel);
        });

        EditorDrawHelper.DrawButton("Save", delegate()
        {
            string path = Application.dataPath + "/Test/Test3.xlsx";
            ExcelHelper.SaveExcel(mExcel, path);
            EditorUtility.DisplayDialog("Save Success", path, "ok");
        });
        EditorGUILayout.EndHorizontal();
    }
Exemplo n.º 6
0
    public void DrawButton()
    {
        EditorGUILayout.BeginHorizontal();
        EditorDrawHelper.DrawButton("Add", delegate()
        {
            mTable.NumberOfRows++;
            Show(mExcel);
        });

        EditorDrawHelper.DrawButton("Save", delegate()
        {
            string path = System.IO.Path.Combine(Application.streamingAssetsPath, "Test3.xlsx");
            ExcelHelper.SaveExcel(mExcel, path);
            EditorUtility.DisplayDialog("Save Success", path, "ok");
        });
        EditorGUILayout.EndHorizontal();
    }
Exemplo n.º 7
0
        /// <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 = EditorDrawHelper.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 = EditorDrawHelper.GetMainWindowPosition().yMax;

                if (positionToAdjust.yMax >= mainWinYMax)
                {
                    positionToAdjust.y -= positionToAdjust.yMax - mainWinYMax;
                }
            }

            window.position = positionToAdjust;
        }
Exemplo n.º 8
0
        private void DrawContent()
        {
            using (new FixedRect(_preventExpandingHeight, position.width))
            {
                using (new EditorDrawHelper.VerticalBlock(_preventExpandingHeight,
                                                          DropdownStyle.BackgroundColor, out float contentHeight))
                {
                    _selectionTree.Draw();

                    if (Event.current.type == EventType.Repaint)
                    {
                        _contentHeight = contentHeight;
                    }
                }

                EditorDrawHelper.DrawBorders(position.width, position.height, DropdownStyle.BorderColor);
            }
        }
Exemplo n.º 9
0
        /// <summary>Draws elements with scrollbar if the list is large enough.</summary>
        /// <param name="drawContent">
        /// Action that takes a visible rect as an argument. Visible rect is the rect where GUI elements are in the
        /// window borders and are shown on screen.
        /// </param>
        public void DrawWithScrollbar(Action <Rect> drawContent)
        {
            EditorDrawHelper.DrawVertically(windowRect =>
            {
                if (Event.current.type == EventType.Repaint)
                {
                    _windowRect = windowRect;
                }

                DrawInScrollView(() =>
                {
                    Rect newWholeListRect = EditorDrawHelper.DrawVertically(() => { drawContent(VisibleRect); });

                    if (_wholeListRect.height == 0f || Event.current.type == EventType.Repaint)
                    {
                        _visible       = _wholeListRect.height > _windowRect.height;
                        _wholeListRect = newWholeListRect;
                    }
                });
            });

            ScrollToNodeIfNeeded();
        }
Exemplo n.º 10
0
 public void Draw()
 {
     EditorDrawHelper.WhileShowingMixedValue(
         _serializedTypeRef.TypeNameHasMultipleDifferentValues,
         DrawTypeSelectionControl);
 }