public void CannotShowSameGraphTwice()
    {
        var graph1 = CreatePlayableGraph("test1");

        GraphVisualizerClient.Show(graph1);
        var graphs = GraphVisualizerClient.GetGraphs().ToArray();

        Assert.That(graphs.Length, Is.EqualTo(1));

        graph1.Destroy();
    }
Example #2
0
        private List <PlayableGraph> GetGraphList()
        {
            var selectedGraphs = new List <PlayableGraph>();

            foreach (var clientGraph in GraphVisualizerClient.GetGraphs())
            {
                if (clientGraph.IsValid())
                {
                    selectedGraphs.Add(clientGraph);
                }
            }

            if (selectedGraphs.Count == 0)
            {
                selectedGraphs = m_Graphs.ToList();
            }

            return(selectedGraphs);
        }
    public void CanClearGraphs()
    {
        var graph1 = CreatePlayableGraph("test1");
        var graph2 = CreatePlayableGraph("test2");

        GraphVisualizerClient.Show(graph1);
        GraphVisualizerClient.Show(graph2);
        var graphs = GraphVisualizerClient.GetGraphs().ToArray();

        Assert.That(graphs.Length, Is.EqualTo(2));

        GraphVisualizerClient.ClearGraphs();
        graphs = GraphVisualizerClient.GetGraphs().ToArray();

        Assert.That(graphs.Length, Is.EqualTo(0));

        graph1.Destroy();
        graph2.Destroy();
    }
    public void CanShowGraph()
    {
        var graph1 = CreatePlayableGraph("test1");
        var graph2 = CreatePlayableGraph("test2");

        GraphVisualizerClient.Show(graph1);
        var graphs = GraphVisualizerClient.GetGraphs().ToArray();

        Assert.That(graphs.Length, Is.EqualTo(1));
        Assert.That(graphs[0].GetEditorName(), Is.EqualTo(graph1.GetEditorName()));

        GraphVisualizerClient.Show(graph2);
        graphs = GraphVisualizerClient.GetGraphs().ToArray();

        Assert.That(graphs.Length, Is.EqualTo(2));
        Assert.That(graphs[0].GetEditorName(), Is.EqualTo(graph1.GetEditorName()));
        Assert.That(graphs[1].GetEditorName(), Is.EqualTo(graph2.GetEditorName()));

        graph1.Destroy();
        graph2.Destroy();
    }
    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);
    }