コード例 #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);
            }
        }
コード例 #2
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();
            }
        }