public SimpleNode CreateBrunchNode(System.Guid guid = default) { if (default == guid) { guid = System.Guid.NewGuid(); } SimpleNode node = SimpleNodeUtil.CreateNode(SimpleNodeType.BranchNode, guid); node.title = $"branch node - {node.m_guidShortStr}"; node.SetPosition(new Rect(400.0f, 400.0f, NODE_SIZE.x, NODE_SIZE.y)); AddElement(node); return(node); }
public SimpleNode CreateStartNode(System.Guid guid = default) { if (default == guid) { guid = System.Guid.NewGuid(); } SimpleNode node = SimpleNodeUtil.CreateNode(SimpleNodeType.StartNode, guid); node.title = $"start node - {node.m_guidShortStr}"; node.SetPosition(new Rect(400.0f, 400.0f, 200.0f, 200.0f)); AddElement(node); return(node); }
public void InjectGraphData(NodeData[] nodeDatas, NodeLinkData[] nodeLinkDatas) { ClearData(); GridBackground gridBackground = new GridBackground(); gridBackground.StretchToParentSize(); this.styleSheets.Add(Resources.Load <StyleSheet>("SimpleGraphView")); Insert(0, gridBackground); // should load data correctly Dictionary <System.Guid, SimpleNode> tempNodes = new Dictionary <System.Guid, SimpleNode>(); for (int i = 0; i < nodeDatas.Length; i++) { System.Guid nodeGuid = default; if (!System.Guid.TryParse(nodeDatas[i].NodeGuidString, out nodeGuid)) { nodeGuid = System.Guid.NewGuid(); } SimpleNode node = CreateNode((SimpleNodeType)nodeDatas[i].NodeType, nodeGuid); node.SetPosition(new Rect(nodeDatas[i].NodePosition.x, nodeDatas[i].NodePosition.y, node.contentRect.width, node.contentRect.height)); tempNodes.Add(nodeGuid, node); } // how should I load the link for (int i = 0; i < nodeLinkDatas.Length; i++) { SimpleNode inputNode = tempNodes[System.Guid.Parse(nodeLinkDatas[i].InputNodeGuidString)]; SimpleNode outputNode = tempNodes[System.Guid.Parse(nodeLinkDatas[i].OutputNodeGuidString)]; Port inputPort = inputNode.m_inputPorts[nodeLinkDatas[i].InputPortIndex]; Port outputPort = outputNode.m_outputPorts[nodeLinkDatas[i].OutputPortIndex]; Edge edge = inputPort.ConnectTo(outputPort); AddElement(edge); } }