private void ShowNodeContextMenu(BehaviourTreeEditorNode node) { GenericMenu menu = new GenericMenu(); if (node.connectedTo.Any()) { foreach (var info in node.connectedTo) { menu.AddItem ( new GUIContent($"Disconnect.../{info.Node.Name}"), false, () => View.DisconnectNodes(node, info.Node as BehaviourTreeEditorNode) ); } } else { menu.AddDisabledItem(new GUIContent("Disconnect...")); } menu.AddItem(new GUIContent("Delete"), false, () => View.DeleteNode(node)); menu.AddItem(new GUIContent("Set as Root"), false, () => { Undo.RecordObject(TreeAsset, "Set root node"); TreeAsset.RootNode = node.TreeNode; }); menu.ShowAsContext(); }
public void OnNodeDisconnected(BehaviourTreeEditorNode parent, BehaviourTreeEditorNode child) { if (parent.TreeNode.IsParentNode()) { parent.TreeNode.AsParentNode().GetChildNodes().Remove(child.TreeNode); } }
public void TryBeginConnection(BehaviourTreeEditorNode source, Vector2 position) { if (source.TreeNode.IsParentNode()) { Nodes.StartConnection(source, position); } }
internal GraphNode OnNodeAdded(BehaviourTree asset, BehaviourTreeNode node) { var newNode = new BehaviourTreeEditorNode(asset, node, Presenter); Nodes.AddNode(newNode); return(newNode); }
private void DeleteFromAsset(BehaviourTreeEditorNode node) { Undo.RecordObject(TreeAsset, $"Removed {node.Name}"); foreach (BehaviourTreeNode treeNode in TreeAsset.Nodes) { if (treeNode.IsParentNode()) { treeNode.AsParentNode().GetChildNodes().Remove(node.TreeNode); } } TreeAsset.Nodes.Remove(node.TreeNode); }
internal void RecreateNodes(ref BehaviourTreeEditorPresenter.Model model) { if (NodeLookup != null) { NodeLookup.Clear(); } else { NodeLookup = new Dictionary <BehaviourTreeNode, BehaviourTreeEditorNode>(); } Nodes.ClearNodes(); Nodes.ScrollPos = model.TreeAsset.EditorPos; foreach (var node in model.TreeAsset.Nodes) { var editorNode = new BehaviourTreeEditorNode(model.TreeAsset, node, Presenter); NodeLookup[node] = editorNode; Nodes.AddNode(editorNode); } foreach (var node in Nodes.AllNodes.Select(n => n as BehaviourTreeEditorNode)) { if (node != null && node.TreeNode.IsParentNode()) { var childNodes = node.TreeNode.AsParentNode().GetChildNodes(); if (childNodes != null) { foreach (var childNode in childNodes) { var foundNode = NodeLookup[childNode]; if (GraphNode.CanMakeConnection(node, foundNode)) { GraphNode.MakeConnection(node, foundNode); } } } } } }
public void DisconnectNodes(BehaviourTreeEditorNode parent, BehaviourTreeEditorNode toRemove) { // parent.RemoveConnection(toRemove); Presenter.OnNodeDisconnected(parent, toRemove); }
public void DeleteNode(BehaviourTreeEditorNode node) { Nodes.OnDeleteNode.Post().Node = node; }
public void TryBeginConnection(BehaviourTreeEditorNode source, Vector2 position) { // if (source.TreeNode.IsParentNode()) // Nodes.StartConnection(source, position); throw new NotImplementedException("TODO!"); }
public void OnNodeDeleted(BehaviourTreeEditorNode node) { DeleteFromAsset(node); }
public void OnEmptyDotClicked(BehaviourTreeEditorNode source, Vector2 position) { View.TryBeginConnection(source, position); }
public void OnNodeRightClick(BehaviourTreeEditorNode node, Vector2 mousePos) { ShowNodeContextMenu(node); }