public void DeleteNode(Node node) { Undo.RegisterCompleteObjectUndo(this, "delete node"); int NodeIdx = nodes.IndexOf(node); nodes.Remove(node); for (int i = connections.Count - 1; i >= 0; --i) { PlugConnection con = connections[i]; if (con.inNode == NodeIdx || con.outNode == NodeIdx) { // these lead to idx out of bouds exception here //if (con.inNode == NodeIdx) { // GetOutPlug(con).connected = false; //} //if (con.outNode == NodeIdx) { // GetInPlug(con).connected = false; //} connections.RemoveAt(i); } if (con.inNode > NodeIdx) { con.inNode -= 1; } if (con.outNode > NodeIdx) { con.outNode -= 1; } } }
private void OnPlugClicked(Node node, Plug plug) { if (plug.type == Plug.PlugType.In && outPlug != null) { if (node == outNode) { Debug.Log("Cannot connect plugs of the same node"); ClearPlugSelection(); return; } Undo.RecordObject(this, "add connection"); PlugConnection newConnection = new PlugConnection( nodes.IndexOf(outNode), outNode.OutPlugs.IndexOf(outPlug), nodes.IndexOf(node), node.InPlugs.IndexOf(plug) ); if (connections.Contains(newConnection)) { Debug.Log("Connection already exists"); } else { connections.Add(newConnection); outPlug.connected = true; plug.connected = true; } ClearPlugSelection(); } else if (plug.type == Plug.PlugType.Out) { outNode = node; outPlug = plug; } }
public Plug GetInPlug(PlugConnection connection) { return(nodes[connection.inNode].InPlugs[connection.inPlug]); }
public Plug GetOutPlug(PlugConnection connection) { return(nodes[connection.outNode].OutPlugs[connection.outPlug]); }