public void CreateGUI() { try { settings = settings ? settings : ItemEditorSettings.GetOrCreate(); useDatabase = settings.useDatabase; VisualElement root = rootVisualElement; var visualTree = settings.treeUxml; visualTree.CloneTree(root); var styleSheet = settings.treeUss; root.styleSheets.Add(styleSheet); searchField = root.Q <ToolbarSearchField>("search-input"); searchField.RegisterValueChangedCallback(new EventCallback <ChangeEvent <string> >(evt => { DoSearchDropdown(evt.newValue); })); searchDropdown = root.Q <UnityEngine.UIElements.ListView>("search-dropdown"); searchDropdown.makeItem = () => new Label() { enableRichText = true }; searchDropdown.onSelectionChange += OnSearchListSelected; root.RegisterCallback <PointerDownEvent>(evt => { if (!string.IsNullOrEmpty(searchField.value) && !searchDropdown.Contains(evt.target as VisualElement)) { searchField.value = string.Empty; } }); DoSearchDropdown(); searchSelector = root.Q <DropdownField>("search-selector"); searchSelector.RegisterValueChangedCallback(evt => { keyType = (SearchKeyType)searchSelector.choices.IndexOf(evt.newValue); }); funcTab = root.Q <TabbedBar>(); funcTab.Refresh(new string[] { "道具", "模板" }, OnFuncTab); funcTab.onRightClick = OnRightFuncTab; Button refresh = root.Q <Button>("refresh-button"); refresh.clicked += Refresh; Button newButton = root.Q <Button>("new-button"); newButton.clicked += OnNewClick; deleteButton = root.Q <Button>("delete-button"); deleteButton.clicked += OnDeleteClick; RefreshDeleteButton(); oldItem = root.Q <ObjectField>("old-item"); oldItem.objectType = typeof(ItemBase); Button oldButton = root.Q <ToolbarButton>("copy-button"); oldButton.clicked += OnCopyClick; oldButton = root.Q <ToolbarButton>("copy-all-button"); oldButton.clicked += OnCopyAllClick; listLabel = root.Q <Label>("list-label"); templateSelector = root.Q <DropdownField>("template-dropdown"); templateSelector.RegisterValueChangedCallback(OnTemplateSelected); RefreshTemplateSelector(); itemList = root.Q <UnityEngine.UIElements.ListView>("item-list"); itemList.selectionType = SelectionType.Multiple; itemList.makeItem = () => { var label = new Label(); label.AddManipulator(new ContextualMenuManipulator(evt => { if (label.userData is ItemNew item) { evt.menu.AppendAction("定位", a => EditorGUIUtility.PingObject(item)); evt.menu.AppendAction("删除", a => DeleteItem(item)); } })); return(label); }; itemList.bindItem = (e, i) => { (e as Label).text = !string.IsNullOrEmpty(items[i].Name) ? items[i].Name : "(未命名道具)"; e.userData = items[i]; }; itemList.onSelectionChange += (os) => OnListItemSelected(os.Select(x => x as ItemNew)); RefreshItems(); templateList = root.Q <UnityEngine.UIElements.ListView>("template-list"); templateList.selectionType = SelectionType.Multiple; templateList.makeItem = () => { var label = new Label(); label.AddManipulator(new ContextualMenuManipulator(evt => { if (label.userData is ItemTemplate template) { evt.menu.AppendAction("定位", a => EditorGUIUtility.PingObject(template)); evt.menu.AppendAction("删除", a => DeleteTemplate(template)); } })); return(label); }; templateList.bindItem = (e, i) => { (e as Label).text = !string.IsNullOrEmpty(templates[i].Name) ? templates[i].Name : "(未命名模板)"; e.userData = templates[i]; }; templateList.onSelectionChange += (os) => OnListTemplateSelected(os.Select(x => x as ItemTemplate)); RefreshTemplates(); rightPanel = root.Q <ScrollView>("right-panel"); itemContainer = root.Q("item-container"); templateContainer = root.Q("template-container"); Undo.undoRedoPerformed += RefreshModules; funcTab.SetSelected(1); root.RegisterCallback(new EventCallback <KeyDownEvent>(evt => { if (hasFocus && evt.keyCode == KeyCode.Delete) { OnDeleteClick(); } })); } catch (Exception ex) { Debug.LogException(ex); } }
public void CreateGUI() { try { settings = settings ? settings : BehaviourTreeSettings.GetOrCreate(); VisualElement root = rootVisualElement; var visualTree = settings.treeUxml; visualTree.CloneTree(root); var styleSheet = settings.treeUss; root.styleSheets.Add(styleSheet); treeView = root.Q <BehaviourTreeView>(); treeView.nodeSelectedCallback = OnNodeSelected; treeView.nodeUnselectedCallback = OnNodeUnselected; treeView.undoRecordsChangedCallback = UpdateUndoEnable; inspectorTaber = root.Q <TabbedBar>("inspector-tab"); inspectorTaber.Refresh(new string[] { "检视器", "快速插入" }, OnInspectorTab, 4); inspectorLabel = root.Q <Label>("inspector-label"); showInspector = true; inspectorView = root.Q <InspectorView>(); variables = root.Q <IMGUIContainer>("variables"); variables.onGUIHandler = DrawVariables; assetsMenu = root.Q <ToolbarMenu>("assets"); assetsMenu.menu.AppendAction("新建", (a) => CreateNewTree("new behaviour tree")); exeMenu = root.Q <ToolbarMenu>("exe-select"); UpdateAssetDropdown(); treeName = root.Q <Label>("tree-name"); variableTaber = root.Q <TabbedBar>("variable-tab"); variableTaber.Refresh(new string[] { "共享变量", "全局变量" }, OnVariableTab, 4); serializedGlobal = new SerializedObject(Application.isPlaying && BehaviourManager.Instance ? BehaviourManager.Instance.GlobalVariables : ZetanUtility.Editor.LoadAsset <GlobalVariables>()); undo = root.Q <ToolbarButton>("undo"); undo.clicked += OnUndoClick; redo = root.Q <ToolbarButton>("redo"); redo.clicked += OnRedoClick; UpdateUndoVisible(); UpdateUndoEnable(); inspectorTaber.SetSelected(1); variableTaber.SetSelected(1); if (tree == null) { ChangeTreeBySelection(); } else { SelectTree(tree); } } catch (Exception e) { Debug.LogException(e); } }