コード例 #1
0
        private static void OnGui()
        {
            if (!IsToolbarAllowed || OnToolbarGui == null)
            {
                return;
            }

            var screenWidth = EditorGUIUtility.currentViewWidth;
            var toolbarRect = new Rect(0, 0, screenWidth, Style.rowHeight);

            //calculations known from UnityCsReference
            toolbarRect.xMin += FromToolsOffset;
            toolbarRect.xMax  = (screenWidth - FromStripOffset) / 2;
            //additional rect styling
            toolbarRect.xMin += Style.spacing;
            toolbarRect.xMax -= Style.spacing;
            toolbarRect.yMin += Style.topPadding;
            toolbarRect.yMax -= Style.botPadding;

            if (toolbarRect.width <= 0)
            {
                return;
            }

            //begin drawing in calculated area
            using (new GUILayout.AreaScope(toolbarRect))
            {
                using (new GUILayout.HorizontalScope())
                {
                    OnToolbarGui?.Invoke();
                }
            }
        }
コード例 #2
0
        private static void OnGui()
        {
            const float fromToolsOffsetX = 400.0f;

#if UNITY_2019_1_OR_NEWER
            const float fromStripOffsetX = 150.0f;
#else
            const float fromStripOffsetX = 100.0f;
#endif

            if (OnToolbarGui == null)
            {
                return;
            }

            var screenWidth = EditorGUIUtility.currentViewWidth;
            var toolbarRect = new Rect(0, 0, screenWidth, Style.height);
            //calculations known from UnityCsReference
            toolbarRect.xMin += fromToolsOffsetX;
            toolbarRect.xMax  = (screenWidth - fromStripOffsetX) / 2;
            //additional rect styling
            toolbarRect.xMin += Style.spacing;
            toolbarRect.xMax -= Style.spacing;
            toolbarRect.yMin += Style.topPadding;
            toolbarRect.yMax -= Style.botPadding;

            if (toolbarRect.width <= 0)
            {
                return;
            }

            //begin drawing in calculated area
            using (var area = new GUILayout.AreaScope(toolbarRect))
            {
                using (var group = new GUILayout.HorizontalScope())
                {
                    OnToolbarGui?.Invoke();
                }
            }
        }