I am following the ui toolkit treeview tutorial to build a custom editor to inspecte a scriptable object.
The code work but when the add buttom add a item to tree view the new item is not show up, I need to manually click the scriptable object in the project window to make the new item appear in tree view.
here is the code.
public override VisualElement CreateInspectorGUI()
{
VisualElement root = new VisualElement();
Manager targetManager = serializedObject.targetObject as Manager;
VisualTree.CloneTree(root);
var treeView = root.Q<MultiColumnTreeView>();
treeView.SetRootItems(targetManager.TreeViewData);
treeView.columns["Tag"].makeCell = BuildTreeViewCell;
treeView.columns["Tag"].bindCell = (VisualElement ele, int index) =>
(ele.Q<Label>() as Label).text = treeView.GetItemDataForIndex<Node>(index).tagName;
var addChildButton = root.Q<Button>("AddChild");
addChildButton.clicked += () => {
var textField = root.Q<TextField>();
if(string.IsNullOrEmpty(textField.value)) return;
serializedObject.Update();
targetManager.TagTree.AddTagByFullTagName(textField.value);
serializedObject.ApplyModifiedProperties();
treeView.RefreshItems();
treeView.Rebuild();
textField.value = "";
};
return root;
}
VisualElement BuildTreeViewCell()
{
var cell = new VisualElement();
cell.style.flexDirection = FlexDirection.Row;
cell.Add(new Label());
return cell;
}
What did i miss?