private void CreateNode() { foreach (var nodeData in _containerCache.nodedata) { //pass pos //var tempNode = _targetGraphView.CreateNode(nodeData.MapText, nodeData.Position); var tempNode = _targetGraphView.CreateRoomNode(nodeData.roomType, nodeData.Position, false); tempNode.GUID = nodeData.NodeGUID; foreach (PortData inportdata in nodeData.inputPorts) { _targetGraphView.AddInputPort(tempNode, inportdata.portName); } foreach (PortData outportdata in nodeData.outputPorts) { _targetGraphView.AddChoicePort(tempNode, outportdata.portName); } _targetGraphView.AddElement(tempNode); } //foreach (var node in Nodes) //{ // var outPort = _containerCache.linkdata.Where(x => x.FromNodeGuid == node.GUID).ToList(); // outPort.ForEach(outp => _targetGraphView.AddChoicePort(node, outp.outPortName)); // var inPort = _containerCache.linkdata.Where(x => x.TargetNodeGuid == node.GUID).ToList(); // inPort.ForEach(inp => _targetGraphView.AddInputPort(node, inp.inPortName)); //} }
private void GenerateToolBar() { var toolbar = new Toolbar(); toolbar.styleSheets.Add(Resources.Load <StyleSheet>("MapGraph")); ////FileName TextField //var fileNameTextField = new TextField("File Name"); //fileNameTextField.SetValueWithoutNotify(_filename); //fileNameTextField.MarkDirtyRepaint(); //fileNameTextField.RegisterValueChangedCallback(evt => _filename = evt.newValue); //toolbar.Add(fileNameTextField); ////// var textbox = new TextElement { text = _filename }; textbox.style.color = Color.red; var objloader = new ObjectField("Data") { objectType = typeof(MapContainer), allowSceneObjects = false }; objloader.RegisterValueChangedCallback(evt => { var saveUtility = GraphSaveUtility.GetInstance(_graphView); //saveUtility.SaveGraph(_filename); if (evt.newValue == null) { _filename = ""; textbox.text = _filename; return; } else { saveUtility.LoadGraph((MapContainer)evt.newValue); _filename = evt.newValue.name; textbox.text = _filename; } }); toolbar.Add(objloader); objloader.style.alignSelf = Align.FlexEnd; //toolbar.Add(textbox); //////// toolbar.Add(new Button(() => RequestDataOperation(true)) { text = "Save Data" }); toolbar.Add(new Button(() => RequestDataOperation(false)) { text = "Load Data" }); ////Create Node Button //var nodeCreateButton = new Button(clickEvent: () => //{ // _graphView.CreateNode("Map Node"); //}); //nodeCreateButton.text = "Create Node"; //toolbar.Add(nodeCreateButton); var roomloader = new ObjectField("RoomData") { objectType = typeof(RoomData), allowSceneObjects = false }; toolbar.Add(roomloader); //Create RoomNode Button var nodeCreateButton = new Button(clickEvent: () => { _graphView.CreateRoomNode((RoomData)roomloader.value, Vector2.zero, true); }) { text = "Create Node" }; toolbar.Add(nodeCreateButton); rootVisualElement.Add(toolbar); }