//--------------------------------------------------------------------------------------------------------------- public EditorConnection(EditorNode a, EditorNode b, connectDir dir=connectDir.both, bool force=false) { this.nodeA = a; this.nodeB = b; this.dir = dir; this.forceConnection = force; }
void ToggleSupressConnection(EditorNode a, EditorNode b) { EditorConnection c = edges.Find(x=> x.containsNodes(a, b)); if(c != null) { c.supressConnection = !c.supressConnection; } }
void SetNodeOnHover(EditorNode node) { if(node != nodeOnHover) { nodeOnHover = node; } }
void onMouseUp(Event e) { if(e.button == 0) { if(e.control && nodeOnHover != null) { if(nodeOnHandle != null) { CreateConnection(nodeOnHover, nodeOnHandle, connectDir.both, true); } } else if(e.shift) { EditorNode toDelete = nodeOnHover; SetNodeOnHover(null); stateChanger.Add(()=> { if(toDelete != null) { DeleteNodeConnections(toDelete.ID); DeleteNode(toDelete); } }); } else if(nodeOnHandle != null) { stateChanger.Add(()=> { AutoConnect(nodeOnHandle); }); } } connectMode = false; nodeOnHandle = null; }
void onMouseDown(Event e) { if(e.button == 0) { if(e.shift) { if(connectionOnHover != null) { connectionOnHover.NextMode(); isDirty = true; } } else if(e.control) { connectMode = true; } else if(nodeOnHover == null) { connectionOnHover = null; stateChanger.Add(()=> { nodeOnHover = CreateNode(currGroundP); }); e.Use(); } } if(nodeOnHover != null) { nodeOnHandle = nodeOnHover; } }
void DeleteNode(EditorNode node) { if(node != null) { node.DestroyObj(); nodes.Remove(node); isDirty = true; } }
void DeleteConnection(EditorNode a, EditorNode b) { EditorConnection c = edges.Find(x=> x.containsNodes(a, b)); if(c != null) { edges.Remove(c); isDirty = true; } }
EditorNode CreateNode(Vector3 p, bool autoconnect=true) { if(p != NULLPOS) { EditorNode node = new EditorNode(getFreeNodeID(), p); nodes.Add(node); if(autoconnect) AutoConnect(node); isDirty = true; return node; } return null; }
EditorConnection CreateConnection(EditorNode a, EditorNode b, graphConnection gc) { EditorConnection c = CreateConnection(a, b, gc.dir, gc.forced); if(c != null) c.supressConnection = gc.supressed; return c; }
EditorConnection CreateConnection(EditorNode a, EditorNode b, connectDir dir, bool forced) { if(a != b && a != null && b != null) { if(areConnected(a, b)) { EditorConnection c = edges.Find(x=> x.containsNodes(a, b)); if(!c.forceConnection) { c.supressConnection = c.magnitude <= data.autoConnectionDist; } else c.supressConnection = !c.supressConnection; c.forceConnection = true; isDirty = true; return c; } else { EditorConnection c = new EditorConnection(a, b, dir, forced); c.supressConnection = false; edges.Add(c); isDirty = true; return c; } } return null; }
//--------------------------------------------------------------------------------------------------------------- /// <summary> /// autoconnect a newly placed node to all nodes around it /// </summary> void AutoConnect(EditorNode node) { if(node != null) { foreach(EditorNode n in nodes) { if(n != node && n != null && !areConnected(n, node)) { float mag = Vector3.Distance(n.position, node.position); if(mag <= data.autoConnectionDist) { CreateConnection(n, node, connectDir.both, false); } } } } }
bool areConnected(EditorNode nodeA, EditorNode nodeB) { return edges.Exists( x=> x.containsNodes(nodeA, nodeB) ); }
public bool containsNode(EditorNode node) { return node != null && (nodeA == node || nodeB == node); }
public bool containsNodes(EditorNode a, EditorNode b) { return a != null && b != null && ((nodeA == a && nodeB == b) || (nodeA == b && nodeB == a)); }