Ejemplo n.º 1
0
        /// <summary>
        /// Draw variables.
        /// </summary>
        void DrawVariables()
        {
            float height      = BlackboardGUIUtility.GetHeight(m_Blackboard);
            bool  listIsEmpty = height == 0f;

            Rect rect = GUILayoutUtility.GetRect(10f, (listIsEmpty ? 21f : height) + 7f, new GUILayoutOption[] { GUILayout.ExpandWidth(true) });

            // Draw background
            rect.xMin += 4f;
            rect.xMax -= 4f;
            if (Event.current.type == EventType.Repaint)
            {
                s_Styles.boxBackground.Draw(rect, false, false, false, false);
            }

            rect.yMin += 2f;
            rect.yMax -= 3f;
            var rect2 = rect;

            // The blackboard is empty?
            if (listIsEmpty)
            {
                rect2.height = 21f;
                rect2.x     += 6f;
                EditorGUI.LabelField(rect2, "List is Empty");
            }
            else
            {
                BlackboardGUIUtility.DrawVariables(rect2, m_Blackboard);
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Unity callback used to draw controls in the window.
        /// Draws the toolbar, the gui parent and the blackboard view.
        /// </summary>
        void OnGUI()
        {
            // Debug.Log(Event.current);

            // Create style?
            if (s_Styles == null)
            {
                s_Styles = new BehaviourWindow.Styles();
            }

            // Refresh active objects during UndoRedoPerformed command
            if (!EditorApplication.isPlaying && Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed")
            {
                // Reload tree
                var tree = BehaviourWindow.activeTree;
                if (tree != null)
                {
                    tree.LoadNodes();
                    // Force node selection update
                    activeNodeID = activeNodeID;
                }

                // Update the active parent
                var lastSelectedParent = activeParent;
                var selectedState      = Selection.activeObject as InternalStateBehaviour;
                if (lastSelectedParent == null || (selectedState != null && selectedState.parent != lastSelectedParent))
                {
                    var selectedParent = selectedState as ParentBehaviour;
                    if (selectedParent != null)
                    {
                        activeParent = selectedParent;
                    }
                }

                Refresh();
                // Repaint();
                return;
            }

            // Refresh window?
            if (InternalStateBehaviour.refresh)
            {
                // Workaround for the missing revert prefab button Unity callback...
                Refresh();
            }

            // Draw toolbar
            DoStatusBarGUI();
            DrawSearch();

            // Draw the gui parent and the blackboard view
            GUI.BeginGroup(new Rect(0, EditorStyles.toolbar.fixedHeight - 2 + 25, position.width, position.height), "");
            {
                if (m_ParentGUI != null && activeParent != null)
                {
                    // Get the blackboard
                    InternalBlackboard activeBlackboard = EditorUtility.InstanceIDToObject(m_ActiveBlackboardID) as InternalBlackboard;

                    // Get the blackboard view rect and height
                    float blackboardHeight     = BlackboardGUIUtility.GetHeight(activeBlackboard) + 2f;
                    float blackboardViewHeight = GetBlackboardViewHeight(blackboardHeight);
                    Rect  blackboardViewRect   = new Rect(0f, position.height - blackboardViewHeight - 17f, 260f, blackboardViewHeight);
                    // Show Scroll View?
                    if (BehaviourMachinePrefs.showScrollView)
                    {
                        blackboardViewRect.y -= 16f;
                    }

                    // Get event type
                    EventType eventType = Event.current.type;
                    // Should ignore event?
                    if (ShouldIgnoreEvent(blackboardViewRect))
                    {
                        Event.current.type = EventType.Ignore;
                    }

                    m_ParentGUI.OnGUIBeforeWindows();
                    BeginWindows();
                    m_ParentGUI.OnGUIWindows();
                    EndWindows();
                    m_ParentGUI.OnGUIAfterWindows();

                    // Restore event?
                    if (Event.current.type != EventType.Used)
                    {
                        Event.current.type = eventType;
                    }

                    // Draw variables
                    if (activeBlackboard != null)
                    {
                        DrawBlackboardView(blackboardViewRect, activeBlackboard, blackboardHeight);
                    }
                }
                // Show notification message
                else if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    ShowNotification(new GUIContent("Select a Game Object and right click in this window"));
                }
            }



            GUI.EndGroup();

            // Show context menu?
            if (Event.current.type == EventType.ContextClick)
            {
                OnContextMenu();
                Event.current.Use();
            }
        }