void DrawGraph()
        {
            if (m_Visualizer == null)
            {
                return;
            }

            if (m_Layout == null)
            {
                m_Layout = new ReingoldTilford();
            }

            m_Visualizer.MaxDepth         = m_MaxDepth;
            m_Visualizer.MaxChildrenNodes = m_MaxChildrenNodes;
            m_Visualizer.RootNodeOverride = m_RootNodeOverride;
            m_Visualizer.Refresh();
            m_Layout.CalculateLayout((Graph)m_Visualizer);

            if (m_Renderer == null)
            {
                m_Renderer = new PlanGraphRenderer((renderer, vn) =>
                {
                    if (vn != null && vn.ExpansionNode)
                    {
                        if (vn.parent != null)
                        {
                            // We're looking to go into the children expansion of a node, so select the actual node;
                            // The one that was clicked on was placeholder for all of the children
                            m_RootNodeOverride = (IVisualizerNode)vn.parent;
                        }
                        else
                        {
                            // Navigate back up the hierarchy
                            m_RootNodeOverride = (IVisualizerNode)m_RootNodeOverride.parent;

                            // If there isn't another parent, then we're actually back at the root
                            if (m_RootNodeOverride != null && m_RootNodeOverride.parent == null)
                            {
                                m_RootNodeOverride = null;
                            }
                        }

                        renderer.ResetSelection();
                    }

                    m_GraphSettings.showInspector = vn != null;
                });
            }

            var toolbarHeight = EditorStyles.toolbar.fixedHeight;
            var graphRect     = new Rect(0, toolbarHeight, position.width, position.height - toolbarHeight);

            m_Renderer.Draw(m_Layout, graphRect, m_GraphSettings, m_Visualizer);
        }
Пример #2
0
        void OnGUI()
        {
            // Early out if there is no graphs.
            var selectedGraphs = GetGraphList();

            if (selectedGraphs.Count == 0)
            {
                ShowMessage("No PlayableGraph in the scene");
                return;
            }

            GUILayout.BeginVertical();
            m_CurrentGraph = GetSelectedGraphInToolBar(selectedGraphs, m_CurrentGraph);
            GUILayout.EndVertical();

            if (!m_CurrentGraph.IsValid())
            {
                ShowMessage("Selected PlayableGraph is invalid");
                return;
            }

            var graph = new PlayableGraphVisualizer(m_CurrentGraph);

            graph.Refresh();

            if (graph.IsEmpty())
            {
                ShowMessage("Selected PlayableGraph is empty");
                return;
            }

            if (m_Layout == null)
            {
                m_Layout = new ReingoldTilford();
            }

            m_Layout.CalculateLayout(graph);

            var graphRect = new Rect(0, s_ToolbarHeight, position.width, position.height - s_ToolbarHeight);

            if (m_Renderer == null)
            {
                m_Renderer = new DefaultGraphRenderer();
            }

            m_Renderer.Draw(m_Layout, graphRect, m_GraphSettings);
        }
Пример #3
0
    private void DrawNodesUsingGraphAPI(Rect canvas)
    {
        if (selectedRecording != null && selectedRecording != lastDisplayedRecording)
        {
            MultiValueDictionary <BGoapNode, BGoapNode> childNodes = new MultiValueDictionary <BGoapNode, BGoapNode>();
            BGoapNode root = null;

            foreach (INode <BGoapState> inode in selectedRecording.search)
            {
                if (inode.GetParent() != null)
                {
                    childNodes.Add(inode.GetParent() as BGoapNode, inode as BGoapNode);
                }
                else
                {
                    root = inode as BGoapNode;
                }
            }

            graph = new AStarDebugGraph(childNodes, root, selectedRecording.goal);
            graph.Refresh();
            if (graph.IsEmpty())
            {
                ShowMessage("No graph data");
                return;
            }

            if (layout == null)
            {
                layout = new ReingoldTilford(false);
            }

            layout.CalculateLayout(graph);

            if (renderer == null)
            {
                renderer = new AStarDebugGraphRenderer();
            }

            renderer.Draw(layout, canvas, new GraphSettings()
            {
                maximumNodeSizeInPixels = 200, maximumNormalizedNodeSize = 1f, aspectRatio = 1.61f
            }, fontSize, offset);
        }
    }
    void OnGUI()
    {
        // Create a list of all the playable graphs extracted.
        IList <PlayableGraphInfo> graphInfos = new List <PlayableGraphInfo>();

        PlayableGraphInfo info;

        // If we requested, we extract automatically the PlayableGraphs from all the components
        // that are in the current scene.
        if (m_AutoScanScene)
        {
            // This code could be generalized, maybe if we added a IHasPlayableGraph Interface.
            IList <PlayableDirector> directors = FindObjectsOfType <PlayableDirector>();
            if (directors != null)
            {
                foreach (var director in directors)
                {
                    if (director.playableGraph.IsValid())
                    {
                        info.name  = director.name;
                        info.graph = director.playableGraph;
                        graphInfos.Add(info);
                    }
                }
            }

            IList <Animator> animators = FindObjectsOfType <Animator>();
            if (animators != null)
            {
                foreach (var animator in animators)
                {
                    if (animator.playableGraph.IsValid())
                    {
                        info.name  = animator.name;
                        info.graph = animator.playableGraph;
                        graphInfos.Add(info);
                    }
                }
            }
        }

        if (GraphVisualizerClient.GetGraphs() != null)
        {
            foreach (var clientGraph in GraphVisualizerClient.GetGraphs())
            {
                if (clientGraph.Key.IsValid())
                {
                    info.name  = clientGraph.Value;
                    info.graph = clientGraph.Key;
                    graphInfos.Add(info);
                }
            }
        }

        // Early out if there is no graphs.
        if (graphInfos.Count == 0)
        {
            ShowMessage("No PlayableGraph in the scene");
            return;
        }

        GUILayout.BeginVertical();
        m_CurrentGraphInfo = GetSelectedGraphInToolBar(graphInfos, m_CurrentGraphInfo);
        GUILayout.EndVertical();

        if (!m_CurrentGraphInfo.graph.IsValid())
        {
            ShowMessage("Selected PlayableGraph is invalid");
            return;
        }

        var graph = new PlayableGraphVisualizer(m_CurrentGraphInfo.graph);

        graph.Refresh();

        if (graph.IsEmpty())
        {
            ShowMessage("Selected PlayableGraph is empty");
            return;
        }

        if (m_Layout == null)
        {
            m_Layout = new ReingoldTilford();
        }

        m_Layout.CalculateLayout(graph);

        var graphRect = new Rect(0, s_ToolbarHeight, position.width, position.height - s_ToolbarHeight);

        if (m_Renderer == null)
        {
            m_Renderer = new DefaultGraphRenderer();
        }

        m_Renderer.Draw(m_Layout, graphRect, m_GraphSettings);
    }