예제 #1
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();
                }
            }
        }