Пример #1
0
        /// <summary>
        /// Draw the plus button to add new variables.
        /// </summary>
        void DrawFooter()
        {
            Rect rect = GUILayoutUtility.GetRect(4f, c_FooterHeight, new GUILayoutOption[] { GUILayout.ExpandWidth(true) });

            rect.xMin += 4f;
            rect.xMax -= 4f;
            rect       = new Rect(rect.x + rect.width - 33f, rect.y, 33f, rect.height);

            // Draw background
            if (Event.current.type == EventType.Repaint)
            {
                s_Styles.footerBackground.Draw(rect, false, false, false, false);
            }

            // Draw plus button
            rect = new Rect(rect.x + 4f, rect.y - 4f, 25f, c_FooterHeight);
            if (GUI.Button(rect, s_Styles.iconToolbarPlus, s_Styles.preButton))
            {
                BlackboardGUIUtility.OnAddContextMenu(m_Blackboard);
            }
        }
Пример #2
0
        /// <summary>
        /// Draw the blackboard view.
        /// <param name="rect">The position to draw the variables.</param>
        /// <param name="blackboard">The blackboard to be drawn.</param>
        /// <param name="blackboardHeight">The size needed to show all variables in the blackboard.</param>
        /// </summary>
        void DrawBlackboardView(Rect rect, InternalBlackboard blackboard, float blackboardHeight)
        {
            // Draw header
            Rect headerRect = new Rect(rect.x, rect.y, rect.width, blackboardHeaderHeight);

            if (GUI.Button(headerRect, new GUIContent("Variables [" + blackboard.GetSize().ToString() + "]", "Click to expand/collapse"), s_Styles.blackboardHeader))
            {
                if (Event.current.mousePosition.x >= headerRect.xMax - c_BlackboardHeaderButtonWidth)
                {
                    BlackboardGUIUtility.OnAddContextMenu(blackboard);
                    m_BlackboardViewIsExpanded = true;
                }
                else
                {
                    m_BlackboardViewIsExpanded = !m_BlackboardViewIsExpanded;
                }
            }

            // Draw plus button
            headerRect.y   += 2f;
            headerRect.xMin = headerRect.width - c_BlackboardHeaderButtonWidth;
            GUI.Label(headerRect, s_Styles.iconToolbarPlus);

            // The blackboard is expanded
            if (m_BlackboardViewIsExpanded && rect.height - headerRect.height > 0f)
            {
                rect.yMin += headerRect.height;

                // Draw background
                if (Event.current.type == EventType.Repaint)
                {
                    s_Styles.blackboardBox.Draw(rect, false, false, false, false);
                }

                // Do scroll bar?
                bool doScroll = blackboardHeight > rect.height;

                // Scroll bar logic
                if (doScroll)
                {
                    // Create a gui group
                    rect.yMin += 2f;
                    rect.yMax -= 2f;
                    GUI.BeginGroup(rect);
                    rect.y = rect.x = 0f;

                    // Get scroll event
                    if (Event.current.type == EventType.ScrollWheel)
                    {
                        m_BlackboardScroll += Event.current.delta.y * 10f;
                        Event.current.Use();
                    }

                    // Update rect
                    rect.y     -= m_BlackboardScroll;
                    rect.width -= 12f;
                }

                // Draw variables
                BlackboardGUIUtility.DrawVariables(rect, blackboard);

                // Draw scroll bar
                if (doScroll)
                {
                    rect.y     += m_BlackboardScroll;
                    rect.width += 12f;
                    var scrollPosition = new Rect(rect.x + rect.width - 16f, rect.y, 16f, rect.height);
                    m_BlackboardScroll = GUI.VerticalScrollbar(scrollPosition, m_BlackboardScroll, rect.height, 0f, blackboardHeight);
                    GUI.EndGroup();
                }
            }
        }