Exemple #1
0
        protected virtual void BuildCreateNodeMenu(ContextualMenuPopulateEvent evt)
        {
            foreach (var nodeMenuItem in NodeProvider.GetNodeMenuEntries())
            {
                var     mousePos      = (evt.currentTarget as VisualElement).ChangeCoordinatesTo(contentViewContainer, evt.localMousePosition);
                Vector2 nodePosition  = mousePos;
                string  souceNodeName = GraphNodeType.MNode.ToString(); // Reverse direction
                string  actionName    = $"Create/{(nodeMenuItem.type == typeof(ConvertNode) ? nodeMenuItem.path.Split('$')[0].Split('.').LastOrDefault() : nodeMenuItem.type == typeof(SourceNode) ? ($"{nodeMenuItem.path}{souceNodeName}") : nodeMenuItem.path)}";

                evt.menu.AppendAction(actionName,
                                      (e) =>
                {
                    if (nodeMenuItem.type.IsAssignableFrom(typeof(ConvertNode)))
                    {
                        CreateConverterNodeOfClass(nodeMenuItem.path, nodePosition);
                    }
                    else if (nodeMenuItem.type.IsAssignableFrom(typeof(SourceNode)))
                    {
                        AddSourceNode(typeof(int), !isM2V, nodePosition, GraphNodeType.MNode.ToString(), true);
                    }
                    else
                    {
                        CreateNodeOfType(nodeMenuItem.type, nodePosition);
                    }
                }, DropdownMenuAction.AlwaysEnabled
                                      );
            }
        }
Exemple #2
0
    public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
    {
        evt.menu.AppendSeparator();

        foreach (var nodeMenuItem in NodeProvider.GetNodeMenuEntries())
        {
            Vector2 nodePosition = evt.mousePosition - (Vector2)viewTransform.position;
            evt.menu.AppendAction("Create/" + nodeMenuItem.Key,
                                  (e) => CreateNodeOfType(nodeMenuItem.Value, nodePosition),
                                  DropdownMenu.MenuAction.AlwaysEnabled
                                  );
        }

        base.BuildContextualMenu(evt);
    }
    public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
    {
        evt.menu.AppendSeparator();

        foreach (var nodeMenuItem in NodeProvider.GetNodeMenuEntries())
        {
            var     mousePos     = (evt.currentTarget as VisualElement).ChangeCoordinatesTo(contentViewContainer, evt.localMousePosition);
            Vector2 nodePosition = mousePos;
            evt.menu.AppendAction("Create/" + nodeMenuItem.Key,
                                  (e) => CreateNodeOfType(nodeMenuItem.Value, nodePosition),
                                  DropdownMenuAction.AlwaysEnabled
                                  );
        }

        base.BuildContextualMenu(evt);
    }
    IEnumerator GenerateScreenshots()
    {
        var          t        = Resources.Load <Texture>("DocumentationGraph");//.FirstOrDefault(g => { Debug.Log(g); return g is MixtureGraph;}) as MixtureGraph;
        MixtureGraph docGraph = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(t)).FirstOrDefault(g => g is MixtureGraph) as MixtureGraph;

        // Setup doc graph properties:
        docGraph.scale    = Vector3.one;
        docGraph.position = new Vector3(0, toolbarHeight, 0);
        docGraph.nodes.RemoveAll(n => !(n is OutputNode));

        // yield return null;

        var window = EditorWindow.CreateWindow <MixtureGraphWindow>();

        window.Show();
        window.Focus();

        window.minSize = new Vector2(1024, 1024);
        window.maxSize = new Vector2(1024, 1024);

        var nodeViews = new List <BaseNodeView>();

        foreach (var node in NodeProvider.GetNodeMenuEntries(docGraph))
        {
            if (node.path.Contains("Experimental"))
            {
                continue;
            }

            // Skip non-mixture nodes:
            if (!node.type.FullName.Contains("Mixture"))
            {
                continue;
            }

            // We'll suport loops after
            if (node.type == typeof(ForeachStart) || node.type == typeof(ForStart))
            {
                continue;
            }

            window.InitializeGraph(docGraph);
            var graphView = window.view;
            var newNode   = BaseNode.CreateFromType(node.type, new Vector2(0, toolbarHeight));
            var nodeView  = graphView.AddNode(newNode);
            nodeViews.Add(nodeView);
            graphView.Add(nodeView);
            SetupNodeIfNeeded(nodeView);

            graphView.MarkDirtyRepaint();
            graphView.UpdateViewTransform(new Vector3(0, 0, 0), Vector3.one * graphView.scale);
            graphView.Focus();

            MixtureGraphProcessor.RunOnce(docGraph);

            yield return(new WaitForEndOfFrame());

            if (window == null)
            {
                yield break;
            }

            TakeAndSaveNodeScreenshot(window, nodeView);

            GenerateNodeMarkdownDoc(nodeView);

            graphView.RemoveNodeView(nodeView);
            graphView.graph.RemoveNode(nodeView.nodeTarget);

            graphView.MarkDirtyRepaint();
            yield return(new WaitForEndOfFrame());
        }

        nodeViews.Sort((n1, n2) => n1.nodeTarget.name.CompareTo(n2.nodeTarget.name));

        GenerateNodeIndexFiles(nodeViews);

        foreach (var node in docGraph.nodes.ToList())
        {
            if (!(node is OutputNode))
            {
                docGraph.RemoveNode(node);
            }
        }

        window.Close();
    }