public bool ExecuteGraphInput(string p_inputName, NodeFlowData p_flowData) { InputNode inputNode = GetNodesByType <InputNode>().Find(n => n.Model.inputName == p_inputName); if (inputNode != null) { inputNode.Execute(p_flowData); return(true); } Debug.LogWarning("There is no input with name " + p_inputName); return(false); }
void DrawOutline(Rect p_rect) { if (SelectionManager.IsSelected(Graph.Nodes.IndexOf(this))) { GUI.color = Color.green; GUI.Box(new Rect(p_rect.x - 2, p_rect.y - 2, p_rect.width + 4, p_rect.height + 4), "", DashEditorCore.Skin.GetStyle("NodeSelected")); } if (IsExecuting || executeTime > 0) { if (!IsExecuting) { executeTime -= .2f; } GUI.color = Color.cyan; GUI.Box(new Rect(p_rect.x - 2, p_rect.y - 2, p_rect.width + 4, p_rect.height + 4), "", DashEditorCore.Skin.GetStyle("NodeSelected")); } if (SelectionManager.IsSelecting(Graph.Nodes.IndexOf(this))) { GUI.color = Color.yellow; GUI.Box(new Rect(p_rect.x - 2, p_rect.y - 2, p_rect.width + 4, p_rect.height + 4), "", DashEditorCore.Skin.GetStyle("NodeSelected")); } if (hasErrorsInExecution) { GUI.color = Color.red; GUI.Box(new Rect(p_rect.x - 2, p_rect.y - 2, p_rect.width + 4, p_rect.height + 4), "", DashEditorCore.Skin.GetStyle("NodeSelected")); GUI.DrawTexture(new Rect(p_rect.x + 2, p_rect.y - 22, 16, 16), IconManager.GetIcon("error_icon")); } int labelOffset = 0; if (this is InputNode) { InputNode node = this as InputNode; if (DashEditorCore.EditorConfig.editingController != null && DashEditorCore.EditorConfig.editingController.autoStart && DashEditorCore.EditorConfig.editingController.autoStartInput == node.Model.inputName) { GUI.color = Color.white; GUIStyle style = new GUIStyle(); style.normal.textColor = Color.green; style.fontStyle = FontStyle.Bold; style.fontSize = 20; style.alignment = TextAnchor.UpperCenter; GUI.Label(new Rect(p_rect.x, p_rect.y + rect.height, rect.width, 20), "[START]", style); labelOffset++; } } if (this is InputNode) { InputNode node = this as InputNode; if (DashEditorCore.EditorConfig.editingController != null && DashEditorCore.EditorConfig.editingController.autoOnEnable && DashEditorCore.EditorConfig.editingController.autoOnEnableInput == node.Model.inputName) { GUI.color = Color.white; GUIStyle style = new GUIStyle(); style.normal.textColor = Color.green; style.fontStyle = FontStyle.Bold; style.fontSize = 20; style.alignment = TextAnchor.UpperCenter; GUI.Label(new Rect(p_rect.x, p_rect.y + rect.height + labelOffset * 25, rect.width, 20), "[ONENABLE]", style); labelOffset++; } } if (Graph.previewNode == this) { GUI.color = Color.white; GUIStyle style = new GUIStyle(); style.normal.textColor = Color.magenta; style.fontStyle = FontStyle.Bold; style.fontSize = 20; style.alignment = TextAnchor.UpperCenter; GUI.Label(new Rect(p_rect.x, p_rect.y + rect.height + labelOffset * 25, rect.width, 20), "[PREVIEW]", style); } GUI.color = Color.white; }
public static SubGraphNode PackNodesToSubGraph(DashGraph p_graph, List <NodeBase> p_nodes) { Vector2 center = Vector2.zero; p_nodes.ForEach(n => center += n.rect.center); center /= p_nodes.Count; SubGraphNode subGraphNode = (SubGraphNode)CreateNode(p_graph, typeof(SubGraphNode), center); List <NodeBase> newNodes = DuplicateNodes(subGraphNode.SubGraph, p_nodes); List <NodeConnection> inputs = new List <NodeConnection>(); List <NodeConnection> outputs = new List <NodeConnection>(); p_nodes.ForEach(node => { // Check for inputs inputs = inputs.Concat(p_graph.Connections.FindAll(c => { bool valid = c.inputNode == node; p_nodes.ForEach(n => valid = valid && n != c.outputNode); return(valid); })).ToList(); outputs = outputs.Concat(p_graph.Connections.FindAll(c => { bool valid = c.outputNode == node; p_nodes.ForEach(n => valid = valid && n != c.inputNode); return(valid); })).ToList(); }); NodeBase previousNode = null; int index = 0; foreach (var connection in inputs) { if (previousNode != connection.inputNode) { InputNode inputNode = (InputNode)CreateNode(subGraphNode.SubGraph, typeof(InputNode), connection.inputNode.rect.position - new Vector2(200, index * 100)); subGraphNode.SubGraph.Connect(newNodes[p_nodes.IndexOf(connection.inputNode)], connection.inputIndex, inputNode, 0); p_graph.Connect(subGraphNode, index++, connection.outputNode, connection.outputIndex); previousNode = connection.inputNode; } else { p_graph.Connect(subGraphNode, index - 1, connection.outputNode, connection.outputIndex); } } previousNode = null; index = 0; foreach (var connection in outputs) { if (previousNode != connection.outputNode) { OutputNode outputNode = (OutputNode)CreateNode(subGraphNode.SubGraph, typeof(OutputNode), connection.outputNode.rect.position + new Vector2(300, index * 100)); subGraphNode.SubGraph.Connect(outputNode, 0, newNodes[p_nodes.IndexOf(connection.outputNode)], connection.outputIndex); p_graph.Connect(connection.inputNode, connection.inputIndex, subGraphNode, index++); previousNode = connection.outputNode; } else { p_graph.Connect(connection.inputNode, connection.inputIndex, subGraphNode, index - 1); } } p_nodes.ForEach(n => p_graph.DeleteNode(n)); return(subGraphNode); }