Beispiel #1
0
 private void Initialize()
 {
     if (nodes.Find(n => n is OutputNode) == null)
     {
         AddNode(BaseNode.CreateFromType <OutputNode>(Vector2.one * 100));
     }
 }
Beispiel #2
0
        public override void OnCreated()
        {
            var pos     = nodeTarget.position.position + new Vector2(300, 0);
            var endView = owner.AddNode(BaseNode.CreateFromType(typeof(ForEnd), pos));
            var group   = new Group("For Loop", pos);

            group.innerNodeGUIDs.Add(nodeTarget.GUID);
            group.innerNodeGUIDs.Add(endView.nodeTarget.GUID);
            owner.AddGroup(group);
            owner.Connect(endView.inputPortViews[0], outputPortViews.FirstOrDefault(p => p.portName == "Output"));
        }
Beispiel #3
0
        public override void OnCreated()
        {
            // TODO: create all other ndoes
            var pos     = nodeTarget.position.position + new Vector2(300, 0);
            var endView = owner.AddNode(BaseNode.CreateFromType(typeof(ForeachEnd), pos));
            var group   = new Group("Foreach", pos);

            group.innerNodeGUIDs.Add(nodeTarget.GUID);
            group.innerNodeGUIDs.Add(endView.nodeTarget.GUID);
            owner.AddGroup(group);
        }
Beispiel #4
0
        public UniBaseNode CreateUniBaseNode(INode node)
        {
            var nodeType  = node.GetType();
            var dataType  = NodeDataMap.GetValue(nodeType);
            var graphNode = BaseNode.CreateFromType(dataType, node.Position) as UniBaseNode;

            //register node into all nodes list
            AddNode(graphNode);

            if (graphNode != null)
            {
                return(graphNode);
            }

            Debug.LogError($"NULL Node bind with UniNode : {node}");
            return(null);
        }
        public UniBaseNode CreateNode(INode node)
        {
            var nodeType  = node.GetType();
            var dataType  = nodeDataMap.GetValue(nodeType);
            var graphNode = BaseNode.CreateFromType(dataType, node.Position) as UniBaseNode;

            if (graphNode == null)
            {
                Debug.LogError($"NULL Node bind with UniNode : {node}");
                return(null);
            }

            graphNode.Initialize(node);

            //register node into all nodes list
            AddNode(graphNode);

            //register only uni nodes
            uniNodes[node.Id] = graphNode;

            //sourceGraph.Save();
            return(graphNode);
        }
Beispiel #6
0
 void CreateNodeOfType(Type type, Vector2 position)
 {
     RegisterCompleteObjectUndo($"Added {type} node");
     AddNode(BaseNode.CreateFromType(type, position));
 }
Beispiel #7
0
        private void AddSelectionsToSubGraph(Vector2 position)
        {
            RegisterCompleteObjectUndo("SubGraph");

            var cGraph = graph as ConvertGraph;

            var newGraph = ScriptableObject.CreateInstance <SubGraph>();
            var newNode  = BaseNode.CreateFromType(typeof(SubGraphNode), position) as SubGraphNode;

            var selectedNodeSet   = new HashSet <string>();
            var selectedNodeViews = new List <GraphNodeView>();

            int inputIndex = 0, outputIndex = 0;
            var inputEdges  = new List <Tuple <SerializableEdge, string> >();
            var outputEdges = new List <Tuple <SerializableEdge, string> >();
            var edgeMap     = new Dictionary <string, List <SerializableEdge> >();

            for (int i = 0; i < selection.Count; i++)
            {
                ISelectable selectItem = selection[i];
                if (selectItem is ConvertNodeView graphNodeView)
                {
                    selectedNodeViews.Add(graphNodeView);
                    selectedNodeSet.Add(graphNodeView.nodeTarget.GUID);
                }
                else if (selectItem is SourceNodeView sourceNodeView)
                {
                    Debug.LogWarning("You can't subgraph your source node");
                    selection.Clear();
                    return;
                }
            }

            for (int i = 0; i < selectedNodeViews.Count; i++)
            {
                GraphNodeView selectItem = selectedNodeViews[i];
                var           cNode      = selectItem.nodeTarget as ConvertNode;

                edgeMap.Clear();
                var iEdges = cNode.GetInputEdges();
                foreach (var edge in iEdges)
                {
                    if (!edgeMap.ContainsKey(edge.outputNodeGUID))
                    {
                        edgeMap[edge.outputNodeGUID] = new List <SerializableEdge>();
                    }
                    edgeMap[edge.outputNodeGUID].Add(edge);
                }


                var inputNodes = cNode.GetInputNodes();
                foreach (var inputNode in inputNodes)
                {
                    if (!selectedNodeSet.Contains(inputNode.GUID))
                    {
                        var parameterInfos = cNode.ParameterInfos;
                        var index          = inputIndex;
                        foreach (var parameterInfo in parameterInfos)
                        {
                            if (!parameterInfo.IsOut)
                            {
                                newNode.AddInputPorData(new SerialPortData
                                {
                                    displayName = parameterInfo.Name,
                                    displayType = new TypeInfo(parameterInfo.ParameterType),
                                    identifier  = inputIndex.ToString(),
                                    guid        = $"{inputNode.GUID}-{(inputIndex - index).ToString()}",
                                    position    = new Vector2(cNode.position.x - (24 + 8) * 10, cNode.position.y + inputIndex * 24 * 10),
                                });
                                inputIndex++;
                            }
                        }

                        var list = edgeMap[inputNode.GUID];
                        for (int j = 0; j < list.Count; j++)
                        {
                            inputEdges.Add(new Tuple <SerializableEdge, string>(list[j], (Convert.ToInt32(list[j].inputPortIdentifier) + index).ToString()));
                        }

                        // PLAN Default Nodes (empty input)
                    }
                }


                edgeMap.Clear();
                var oEdges = cNode.GetOutputEdges();
                foreach (var edge in oEdges)
                {
                    if (!edgeMap.ContainsKey(edge.inputNodeGUID))
                    {
                        edgeMap[edge.inputNodeGUID] = new List <SerializableEdge>();
                    }
                    edgeMap[edge.inputNodeGUID].Add(edge);
                }

                var outputNodes = cNode.GetOutputNodes();
                foreach (var outputNode in outputNodes)
                {
                    if (!selectedNodeSet.Contains(outputNode.GUID))
                    {
                        int index          = outputIndex;
                        var parameterInfos = cNode.ParameterInfos;
                        foreach (var parameterInfo in parameterInfos)
                        {
                            if (parameterInfo.IsOut)
                            {
                                newNode.AddOutputPorData(new SerialPortData
                                {
                                    displayName = parameterInfo.Name,
                                    displayType = new TypeInfo(parameterInfo.ParameterType.GetElementType()),
                                    identifier  = outputIndex.ToString(),
                                    guid        = $"{outputNode.GUID}-{(outputIndex - index).ToString()}",
                                    position    = new Vector2(cNode.position.x + (24 + 8 * 10), cNode.position.y + outputIndex * 24 * 10),
                                });
                                outputIndex++;
                            }
                        }
                        var list = edgeMap[outputNode.GUID];
                        for (int j = 0; j < list.Count; j++)
                        {
                            outputEdges.Add(new Tuple <SerializableEdge, string>(list[j], (Convert.ToInt32(list[j].outputPortIdentifier) + index).ToString()));
                        }
                    }
                }
            }

            string path = EditorUtility.SaveFilePanel(
                "Save your convert graph",
                "",
                "NewConverterSubGraph",
                "asset"
                );

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            path = $"Assets{path.Substring(Application.dataPath.Length)}";
            AssetDatabase.CreateAsset(newGraph, path);

            newNode.subGraphGUID = AssetDatabase.AssetPathToGUID(path);
            AddNode(newNode);

            var delayConnectEdgeViews = new List <EdgeView>();

            for (int i = 0; i < inputEdges.Count; i++)
            {
                var inputEdge     = inputEdges[i].Item1;
                var oldOutputNode = inputEdge.outputNode;
                var outputPort    = oldOutputNode.GetPort(inputEdge.outputPort.fieldName, inputEdge.outputPortIdentifier);
                var inputPort     = newNode.GetPort(nameof(newNode.inputValue), inputEdges[i].Item2.ToString());
                var newEdge       = SerializableEdge.CreateNewEdge(newGraph, inputPort, outputPort);

                if (nodeViewsPerNode.ContainsKey(oldOutputNode) && nodeViewsPerNode.ContainsKey(newNode))
                {
                    var edgeView = new EdgeView()
                    {
                        userData = newEdge,
                        input    = nodeViewsPerNode[newNode].GetPortViewFromFieldName(newEdge.inputFieldName, newEdge.inputPortIdentifier),
                        output   = nodeViewsPerNode[oldOutputNode].GetPortViewFromFieldName(newEdge.outputFieldName, newEdge.outputPortIdentifier)
                    };
                    Connect(edgeView);
                }
            }

            for (int i = 0; i < outputEdges.Count; i++)
            {
                var outputEdge   = outputEdges[i].Item1;
                var oldInputNode = outputEdge.inputNode;
                var inputPort    = oldInputNode.GetPort(outputEdge.inputPort.fieldName, outputEdge.inputPortIdentifier);
                var outputPort   = newNode.GetPort(nameof(newNode.outputValue), outputEdges[i].Item2.ToString());
                var newEdge      = SerializableEdge.CreateNewEdge(newGraph, inputPort, outputPort);

                if (nodeViewsPerNode.ContainsKey(oldInputNode) && nodeViewsPerNode.ContainsKey(newNode))
                {
                    var edgeView = new EdgeView()
                    {
                        userData = newEdge,
                        input    = nodeViewsPerNode[oldInputNode].GetPortViewFromFieldName(newEdge.inputFieldName, newEdge.inputPortIdentifier),
                        output   = nodeViewsPerNode[newNode].GetPortViewFromFieldName(newEdge.outputFieldName, newEdge.outputPortIdentifier)
                    };
                    delayConnectEdgeViews.Add(edgeView);
                }
            }

            string copyDatas = SerialzieSubGraphElements(selection.OfType <GraphElement>(), inputEdges.Select(v => v.Item1).Concat(outputEdges.Select(v => v.Item1)));

            for (int i = 0; i < selectedNodeViews.Count; i++)
            {
                RemoveNodeWithEdges(selectedNodeViews[i]);
            }

            // Reconnect
            for (int i = 0; i < delayConnectEdgeViews.Count; i++)
            {
                Connect(delayConnectEdgeViews[i]);
            }

            if (CanPasteSerializedDataCallback(copyDatas))
            {
                var subGraphWindow = EditorWindow.GetWindow <SubGraphWindow>();
                subGraphWindow.serialData   = copyDatas;
                subGraphWindow.oldGUIDs     = selectedNodeViews.Select(s => s.nodeTarget.GUID).ToList();
                subGraphWindow.subGraphNode = newNode;
                subGraphWindow.InitializeGraph(newGraph);
            }
        }
    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();
    }