public void AddNode(BehaviorTreeNodeItem selectedItem) { BehaviorTreeViewWindow btWindow = BehaviorTreeViewWindow.GetWindow(); if (btWindow.BehaviorTreeAsset == null) { Debug.LogError("Open a behavior tree asset before trying to add a node."); return; } BehaviorTreeModel <BehaviorTreeNode> btModel = btWindow.TreeView.TreeModel; var selectedIDsInBT = btWindow.TreeView.GetSelection(); // Case: No node is selected if (selectedIDsInBT.Count == 0) { BehaviorTreeNode nodeToAdd = (BehaviorTreeNode)Activator.CreateInstance( selectedItem.Data, selectedItem.displayName, 0, btModel.GenerateUniqueID()); //Debug.Log("Adding node: " + nodeToAdd.ToString() + " to Root"); btModel.AddElement(nodeToAdd); return; } for (int i = 0; i < selectedIDsInBT.Count; ++i) { //Debug.Log(selectedIDsInBT[i]); BehaviorTreeNode possibleParent = btModel.Find(selectedIDsInBT[i]); if (possibleParent != null) { BehaviorTreeNode nodeToAdd = (BehaviorTreeNode)Activator.CreateInstance( selectedItem.Data, selectedItem.displayName, 0, btModel.GenerateUniqueID()); //Debug.Log("Adding node: " + nodeToAdd.ToString() + " to: " + possibleParent.ToString()); btModel.AddElement(nodeToAdd, possibleParent); } // Just in case the ID wasn't found else { BehaviorTreeNode nodeToAdd = (BehaviorTreeNode)Activator.CreateInstance( selectedItem.Data, selectedItem.displayName, 0, btModel.GenerateUniqueID()); //Debug.Log("Adding node: " + nodeToAdd.ToString() + " to Root"); btModel.AddElement(nodeToAdd); return; } } }
void InitIfNeeded() { if (!_initialized) { if (_treeViewState == null) { _treeViewState = new TreeViewState(); } bool firstInit = _multiColumnHeaderState == null; var headerState = BehaviorTreeView <BehaviorTreeNode> .CreateDefaultMultiColumnHeaderState(behaviorTreeViewRect.width); if (MultiColumnHeaderState.CanOverwriteSerializedFields(_multiColumnHeaderState, headerState)) { MultiColumnHeaderState.OverwriteSerializedFields(_multiColumnHeaderState, headerState); } _multiColumnHeaderState = headerState; var multiColumnHeader = new MultiColumnHeader(headerState); if (firstInit) { multiColumnHeader.ResizeToFit(); } var treeModel = new BehaviorTreeModel <BehaviorTreeNode>(GetData(), BehaviorTreeAsset); if (TreeView != null) { TreeView.UnregisterCallbacks(); TreeView.TreeModel.e_ModelChanged -= SaveAsset; } TreeView = new BehaviorTreeView <BehaviorTreeNode>(_treeViewState, multiColumnHeader, treeModel); TreeView.RegisterCallbacks(); TreeView.TreeModel.e_ModelChanged += SaveAsset; TreeView.multiColumnHeader.canSort = false; TreeView.multiColumnHeader.height = MultiColumnHeader.DefaultGUI.minimumHeight; _searchField = new SearchField(); _searchField.downOrUpArrowKeyPressed += TreeView.SetFocusAndEnsureSelectedItem; _initialized = true; } }
public BehaviorTreeView(TreeViewState state, MultiColumnHeader multiColumnHeader, BehaviorTreeModel <T> model) : base(state, multiColumnHeader) { Init(model); rowHeight = ROW_HEIGHTS; columnIndexForTreeFoldouts = 1; showAlternatingRowBackgrounds = true; showBorder = true; customFoldoutYOffset = (ROW_HEIGHTS - EditorGUIUtility.singleLineHeight) * 0.5f; extraSpaceBeforeIconAndLabel = TOGGLE_WIDTH; Reload(); }
void Init(BehaviorTreeModel <T> model) { TreeModel = model; }
public BehaviorTreeView(TreeViewState state, BehaviorTreeModel <T> model) : base(state) { Init(model); }