void BindBehaviourTreeEvent(bool bind) { if (Runner == null) { return; } if (bind) { Runner.OnBehaviourTreeBegin += OnBehaviourTreeBegin; Runner.OnBehaviourTreeFrame += OnBehaviourTreeFrame; for (int i = 0; i < TreeCanvas.ElementCount; i++) { BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i); if (node == null) { continue; } node.RuntimeNode = Runner.FindRuntimeNode(node.Self.BTId); } } else { Runner.OnBehaviourTreeBegin -= OnBehaviourTreeBegin; Runner.OnBehaviourTreeFrame -= OnBehaviourTreeFrame; for (int i = 0; i < TreeCanvas.ElementCount; i++) { BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i); if (node == null) { continue; } node.RuntimeNode = null; } } }
public void EditNodes(EditDelegate <BehaviourNodeGUI> editor) { for (int i = 0; i < TreeCanvas.ElementCount; i++) { BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i); if (node != null) { editor(node); } } }
public void SelectNodes(FilterDelegate <BehaviourNodeGUI> selector) { for (int i = 0; i < TreeCanvas.ElementCount; i++) { BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i); if (node != null) { node.IsSelected = selector(node); } } }
private void OnBehaviourTreeFrame(BehaviourTreeRunner btree) { if (btree == Runner) { for (int i = 0; i < TreeCanvas.ElementCount; i++) { BehaviourNodeGUI node = TreeCanvas.GetElement <BehaviourNodeGUI>(i); if (node != null) { node.SyncRuntimeState(btree); } } } }
void ExportTreeData() { List <BTData> nodes = new List <BTData>(); List <PaintElement> children = new List <PaintElement>(); int rootId = 0; for (int i = 0; i < TreeCanvas.ElementCount; i++) { BehaviourNodeGUI bnode = TreeCanvas.GetElement <BehaviourNodeGUI>(i); if (bnode == null) { continue; } if (TreeGraph.GetParent(0, bnode) == mRootGUI) { rootId = bnode.Self.BTId; } BTData data = bnode.ExportNodeData(nodes); children.Clear(); TreeGraph.GetAllChildren(0, bnode, children); GlobalUtil.Sort(children, (x, y) => x.LocalRect.center.x <= y.LocalRect.center.x ? -1 : 1); data.m_Children = new int[children.Count]; for (int j = 0; j < children.Count; j++) { BehaviourNodeGUI child = children[j] as BehaviourNodeGUI; data.m_Children[j] = child == null ? 0 : child.Self.BTId; } } BehaviourAsset.m_RootNodeId = rootId; GlobalUtil.Sort(nodes, (x, y) => x.m_Id - y.m_Id); BehaviourAsset.m_Datas = nodes.ToArray(); BehaviourAsset.m_Sorted = true; BehaviourTreeAsset.Comment[] comments = new BehaviourTreeAsset.Comment[CommentCanvas.ElementCount]; for (int i = 0; i < comments.Length; i++) { comments[i] = new BehaviourTreeAsset.Comment(); BehaviourCommentGUI com = CommentCanvas.GetElement <BehaviourCommentGUI>(i); if (com != null) { comments[i].m_Rect = com.LocalRect; comments[i].m_Comment = com.Comment ?? ""; } } BehaviourAsset.m_Comments = comments; EditorUtility.SetDirty(BehaviourAsset); }