public ActionGraphView() { Presenter = new ActionGraphPresenter(this); Nodes.OnRightClick.Reassign(data => { var node = Nodes.AllNodes.FirstOrDefault ( n => n.PhysicalRect.Contains( (data.MousePos * Nodes.ZoomLevel) )) as ActionGraphEditorNode; if (node != null) { Presenter.OnNodeRightClick(node, data.MousePos); } else { Presenter.OnRightClick(data.MousePos); } return(true); }); Nodes.OnConnection.Reassign((data => { if (data.Target != null) { if (GraphNode.CanMakeConnection(data.Source, data.Target)) { Presenter.OnConnectChildNode(GraphNode.MakeConnection(data.Source, data.Target)); return(true); } } return(false); })); Nodes.OnConnection.AddPost(data => { if (data.Target == null) { Presenter.OnDropFailed(data.Source, data.MousePos); } }); Nodes.OnDeleteNode.AddPost(data => { Presenter.OnNodeDeleted(data.Node as ActionGraphEditorNode); Nodes.AllNodes.Remove(data.Node); }); Nodes.OnSlotClicked.Reassign(data => { Presenter.OnNodeConnectorClicked(data.Source, data.Source.Owner.GetSlotPosition(data.Source)); return(true); }); }
private void ConnectNodeEditor(GraphNode parent, ActionGraphNode child) { ActionGraphEditorNode foundNode; if (NodeLookup.TryGetValue(child, out foundNode)) { if (GraphNode.CanMakeConnection(parent, foundNode)) { GraphNode.MakeConnection(parent, foundNode); } } else { Debug.LogError($"Couldn't find editor node for {child.name}", child); } }
public GraphNodeEditor() { AllNodes = new List <GraphNode>(); OnDeleteNode.Reassign(data => { foreach (GraphNode baseNode in AllNodes) { baseNode.RemoveConnection(data.Node); } AllNodes.Remove(data.Node); data.Node.OnDelete(); return(true); }); OnSelectNode.Reassign(data => { data.Node.SetSelected(true); SelectedNodes.Add(data.Node); return(true); }); OnDeselectNode.Reassign(data => { data.Node.SetSelected(false); SelectedNodes.Remove(data.Node); return(true); }); OnConnection.Reassign(data => { if (data.Target != null) { if (GraphNode.CanMakeConnection(data.Source, data.Target)) { GraphNode.MakeConnection(data.Source, data.Target); return(true); } return(false); } return(false); }); }