public void DeleteNode(DataflowNode node, GameObject go) { for (int i = 0; i < node.inputs.Count; i++) { if (node.inputs[i].link != null) { if (node.inputs[i].uiLink) { Destroy(node.inputs[i].uiLink.gameObject); } } } for (int i = 0; i < node.outputs.Count; i++) { for (int l = 0; l < node.outputs[i].links.Count; l++) { if (!node.outputs[i].links[l].noDefaultValue) { node.outputs[i].links[l].transform.GetChild(0).gameObject.SetActive(true); } if (node.outputs[i].links[l].uiLink) { Destroy(node.outputs[i].links[l].uiLink.gameObject); } } } dataflow.DeleteNode(node); Destroy(go); }
public void OpenDataflow(Dataflow d) { //Nodes List <DataflowNode> nodes = new List <DataflowNode>(); for (int n = 0; n < d.nodes.Count; n++) { DrawNode(d.nodes[n]); } //Links for (int n = 0; n < d.nodes.Count; n++) { DataflowNode node = d.nodes[n]; for (int i = 0; i < node.outputs.Count; i++) { for (int l = 0; l < node.outputs[i].links.Count; l++) { DataflowOutput output = node.outputs[i]; DataflowInput input = node.outputs[i].links[l]; UINodeLink uiNodeLink = Instantiate(Resources.Load <UINodeLink>("Link"), panel); uiNodeLink.outputAnchor = output.transform.GetChild(1).GetComponent <RectTransform>(); uiNodeLink.inputAnchor = input.transform.GetChild(1).GetComponent <RectTransform>(); input.uiLink = uiNodeLink; } } } dataflow = d; RefreshDataflowDropdown(); RefreshDroneDropdown(); }
public Dataflow ToDataflow() { Dataflow d = new Dataflow(name); foreach (var n in nodes) { DataflowNode node = d.AddNode(n.name, n.posx, n.posy); node.activator.valueFloat = n.activator.valueFloat; node.activator.valueBoolean = n.activator.valueBoolean; node.activator.ready = n.activator.ready; for (int i = 0; i < node.inputs.Count; i++) { node.inputs[i].valueFloat = n.inputs[i].valueFloat; node.inputs[i].valueBoolean = n.inputs[i].valueBoolean; node.inputs[i].ready = n.inputs[i].ready; } foreach (var c in n.configs) { node.configs[c.name].value = c.value; } } foreach (var l in links) { if (l.outputId < d.nodes[l.outputNodeId].outputs.Count && l.inputId < d.nodes[l.inputNodeId].inputs.Count) //Check for different save versions (inputs/outputs changed) { d.AddLink(d.nodes[l.outputNodeId].outputs[l.outputId], l.inputId < 0 ? d.nodes[l.inputNodeId].activator : d.nodes[l.inputNodeId].inputs[l.inputId]); } } return(d); }
public void OnEndDrag(PointerEventData eventData) { //Update dragged position - for DataflwoNode only DataflowNode node = UIDataflowEditor.instance.dataflow.nodes.Find(n => n.transform == rt); if (node != null) { node.posx = (int)rt.anchoredPosition.x; node.posy = (int)rt.anchoredPosition.y; } rt = null; }
public DataflowNode AddNode(string name, int posx = 0, int posy = 0) { string[] path = name.Split('.'); DataflowNode n = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance((path[0] == "DataflowNodes" ? "" : "DataflowNodes.") + name) as DataflowNode; n.name = name; n.dataflow = this; n.posx = posx; n.posy = posy; n.activator = new DataflowInput() { name = "activator", type = IOType.Activator, node = n }; nodes.Add(n); return(n); }
public void DeleteNode(DataflowNode n) { for (int i = 0; i < n.inputs.Count; i++) { if (n.inputs[i].link != null) { DeleteLink(n.inputs[i]); } } for (int i = 0; i < n.outputs.Count; i++) { for (int l = 0; l < n.outputs[i].links.Count; l++) { DeleteLink(n.outputs[i].links[l]); } } nodes.Remove(n); }
public void DrawNode(DataflowNode node) { RectTransform nodeRT = Instantiate(nodePrefab, panel).GetComponent <RectTransform>(); nodeRT.anchoredPosition = new Vector2(node.posx, node.posy); nodeRT.GetChild(0).GetChild(0).GetComponent <Text>().text = node.name.Split('.')[1]; nodeRT.GetChild(0).GetChild(0).GetChild(0).GetComponent <Button>().onClick.AddListener(delegate { DeleteNode(node, nodeRT.gameObject); }); node.transform = nodeRT; //Activator DrawInput(node.activator, nodeRT, nodeRT.GetChild(0).GetChild(0)); //Inputs for (int i = 0; i < node.inputs.Count; i++) { DrawInput(node.inputs[i], nodeRT, nodeRT.GetChild(1).GetChild(0)); } //Outputs for (int i = 0; i < node.outputs.Count; i++) { RectTransform outputRT = Instantiate(outputPrefab, nodeRT.GetChild(1).GetChild(1)).GetComponent <RectTransform>(); outputRT.GetChild(0).GetComponent <Text>().text = node.outputs[i].name; //outputRT.GetComponent<BoundTooltipTrigger>().text = node.outputs[i].name; outputRT.GetComponent <UINodeOutput>().output = node.outputs[i]; node.outputs[i].transform = outputRT; //Icon type Image icon = outputRT.GetChild(1).GetComponent <Image>(); switch (node.outputs[i].type) { case Dataflow.IOType.Number: icon.color = Color.green; break; case Dataflow.IOType.Boolean: icon.color = Color.yellow; break; case Dataflow.IOType.Activator: icon.color = Color.red; break; case Dataflow.IOType.TargetsList: icon.color = Color.gray; break; case Dataflow.IOType.CoordinatesList: icon.color = Color.white; break; case Dataflow.IOType.Target: icon.color = Color.blue; break; } } //Configs foreach (var c in node.configs) { RectTransform configRT = Instantiate(configPrefab, nodeRT.GetChild(0).GetChild(1)).GetComponent <RectTransform>(); configRT.GetChild(0).GetComponent <Text>().text = c.Key; if (c.Value.type == Dataflow.ConfigType.Boolean) { Destroy(configRT.GetChild(1).GetChild(0).gameObject); Destroy(configRT.GetChild(1).GetChild(1).gameObject); Toggle toggle = configRT.GetChild(1).GetChild(2).GetComponent <Toggle>(); if (c.Value.value.ToLower() == "true") { toggle.isOn = true; } if (c.Value.value.ToLower() == "false") { toggle.isOn = false; } toggle.onValueChanged.AddListener(delegate { c.Value.value = toggle.isOn ? "true" : "false"; }); } else if (c.Value.values == null) { Destroy(configRT.GetChild(1).GetChild(1).gameObject); Destroy(configRT.GetChild(1).GetChild(2).gameObject); InputField inputField = configRT.GetChild(1).GetChild(0).GetComponent <InputField>(); switch (c.Value.type) { case Dataflow.ConfigType.Float: inputField.contentType = InputField.ContentType.DecimalNumber; inputField.text = "0.0"; break; case Dataflow.ConfigType.Integer: inputField.contentType = InputField.ContentType.IntegerNumber; inputField.text = "0"; break; case Dataflow.ConfigType.String: inputField.contentType = InputField.ContentType.Standard; break; } if (c.Value.value.Length > 0) { inputField.text = c.Value.value; } inputField.onEndEdit.AddListener(delegate { c.Value.value = inputField.text; }); } else { Destroy(configRT.GetChild(1).GetChild(0).gameObject); Destroy(configRT.GetChild(1).GetChild(2).gameObject); Dropdown dropdown = configRT.GetChild(1).GetChild(1).GetComponent <Dropdown>(); dropdown.ClearOptions(); dropdown.AddOptions(c.Value.values); dropdown.value = c.Value.values.IndexOf(c.Value.value); dropdown.onValueChanged.AddListener(delegate { c.Value.value = c.Value.values[dropdown.value]; }); } c.Value.transform = configRT; } }