private void OnEnable() { //initialization this.levelHierarchyConfiguration = AssetFinder.SafeSingleAssetFind <LevelHierarchyConfiguration>("t:" + typeof(LevelHierarchyConfiguration).Name); this.levelZonesSceneConfiguration = AssetFinder.SafeSingleAssetFind <LevelZonesSceneConfiguration>("t:" + typeof(LevelZonesSceneConfiguration).Name); this.chunkZonesSceneConfiguration = AssetFinder.SafeSingleAssetFind <ChunkZonesSceneConfiguration>("t:" + typeof(ChunkZonesSceneConfiguration).Name); //END var root = this.rootVisualElement; var searchBar = new ToolbarSearchField(); searchBar.style.height = 15; searchBar.style.justifyContent = Justify.Center; searchBar.RegisterValueChangedCallback(this.OnSearchChange); searchBar.focusable = true; searchBar.Focus(); root.Add(searchBar); var scrollView = new ScrollView(ScrollViewMode.Vertical); root.Add(scrollView); var boundingBox = new Box(); scrollView.Add(boundingBox); //HEADER Layout_HeadderLine(boundingBox, VisualElementWithStyle(new Label("Scene path"), HeaderLabelStyle()), VisualElementWithStyle(new Label("Scene ref"), HeaderLabelStyle())); //CONTENT this.DoDisplayLevels(boundingBox); }
public void Build(VisualElement root) { var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>( "Packages/com.nementic.selection-utility/Editor/UIE_SelectionPopup.uss"); root.styleSheets.Add(styleSheet); var toolbar = new Toolbar(); var searchField = new ToolbarSearchField(); searchField.viewDataKey = "ToolbarSearchFieldData"; searchField.value = searchString; searchField.RegisterCallback <ChangeEvent <string> >(OnSearchChanged); toolbar.Add(searchField); root.Add(toolbar); list = new ListView { itemHeight = rowHeight, makeItem = MakeItem, bindItem = BindItem }; list.onSelectionChanged += OnListSelectionChanged; list.selectionType = SelectionType.Multiple; list.viewDataKey = "ListViewDataKey"; root.Add(list); BuildIconCache(); RefreshListWithFilter(searchField.value); }
public void OnEnable() { VisualElement root = rootVisualElement; var visualTree = Resources.Load <VisualTreeAsset>("GameSettings_Main"); visualTree.CloneTree(root); var styleSheet = Resources.Load <StyleSheet>("GameSettings_Style"); root.styleSheets.Add(styleSheet); ToolbarSearchField _toolbarSearchField = rootVisualElement.Q <ToolbarSearchField>("SearchField"); _toolbarSearchField.RegisterValueChangedCallback(OnSearchFieldChange); _toolbarSearchField.name = "SearchField"; _toolbarSearchField.AddToClassList("ListSearchField"); rootVisualElement.Q <VisualElement>("LeftPanel").style.maxWidth = leftPanelMaxWidth; includeSS = root.Q <Toggle>("IncludeSSToggle"); includeSS.SetValueWithoutNotify(ScriptableSettingsManager.ShowRuntimeScriptableSingleton); includeSS.RegisterValueChangedCallback(OnIncludeSSToggle); PopulateTags(false); PopulatePresetList(); }
private void DrawToolbar() { EditorGUILayout.BeginHorizontal("toolbar", GUILayout.ExpandWidth(true)); { if (GUILayout.Button(isExpandAll ? "Collapse All" : "Expand All", EditorStyles.toolbarButton, GUILayout.Width(Styles.ToolbarBtnWidth))) { isExpandAll = !isExpandAll; if (isExpandAll) { assetPackerTreeView.ExpandAll(); } else { assetPackerTreeView.CollapseAll(); } } Rect menuRect = GUILayoutUtility.GetRect(Contents.RunModeContent, EditorStyles.toolbarButton); if (EditorGUI.DropdownButton(menuRect, Contents.RunModeContent, FocusType.Passive, EditorStyles.toolbarButton)) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent(RunMode.AssetDatabase.ToString()), runMode == RunMode.AssetDatabase, () => { PlayerSettingsUtility.RemoveScriptingDefineSymbol(ASSET_BUNDLE_SYMBOL); }); menu.AddItem(new GUIContent(RunMode.AssetBundle.ToString()), runMode == RunMode.AssetBundle, () => { PlayerSettingsUtility.AddScriptingDefineSymbol(ASSET_BUNDLE_SYMBOL); }); menu.DropDown(menuRect); } GUILayout.FlexibleSpace(); if (searchField == null) { searchField = new ToolbarSearchField((text) => { if (searchText != text) { searchText = text; SetTreeModel(); } }, (category) => { int newIndex = Array.IndexOf(SearchCategories, category); if ((int)searchCategory != newIndex) { searchCategory = (SearchCategory)newIndex; SetTreeModel(); } }); searchField.Categories = SearchCategories; searchField.CategoryIndex = 0; } searchField.OnGUILayout(); } EditorGUILayout.EndHorizontal(); }
public void Initialize(VisualElement rootVisualElement) { m_Root = UIElementHelpers.LoadTemplate(kBasePath, "StartLiveLinkWindow"); m_Root.style.flexGrow = 1; m_SearchField = m_Root.Q <ToolbarSearchField>(kNamePrefix + "body__search"); m_SearchField.RegisterValueChangedCallback(evt => FilterConfigurations()); m_EmptyMessage = m_Root.Q <VisualElement>(kNamePrefix + "body__empty-message"); m_ConfigurationsListView = m_Root.Q <ListView>(kNamePrefix + "body__configurations-list"); m_ConfigurationsListView.makeItem = CreateBuildConfigurationItemVisualElement; m_ConfigurationsListView.bindItem = BindBuildConfigurationItem; m_ConfigurationsListView.itemsSource = m_FilteredBuildConfigurationViewModels; m_ConfigurationsListView.selectionType = SelectionType.Single; #if UNITY_2020_1_OR_NEWER m_ConfigurationsListView.onSelectionChange += OnConfigurationListViewSelectionChange; m_ConfigurationsListView.onItemsChosen += chosenConfigurations => EditBuildConfiguration((BuildConfigurationViewModel)chosenConfigurations.First()); #else m_ConfigurationsListView.onSelectionChanged += OnConfigurationListViewSelectionChanged; m_ConfigurationsListView.onItemChosen += chosenConfiguration => EditBuildConfiguration((BuildConfigurationViewModel)chosenConfiguration); #endif m_AddNewButton = m_Root.Q <Button>(kNamePrefix + "body__new-build-button"); m_AddNewButton.clicked += ShowNewBuildNameInput; m_NewBuildName = m_Root.Q <VisualElement>(kNamePrefix + "new-build-name"); m_NewBuildNameTextField = m_NewBuildName.Q <TextField>(); m_NewBuildNameSubmit = m_NewBuildName.Q <Button>(kNamePrefix + "new-build-name__submit"); m_NewBuildNameTextField.RegisterCallback <KeyDownEvent>(OnNewBuildKeyDown); m_NewBuildNameTextField.RegisterCallback <BlurEvent>(OnNewBuildFocusChanged); m_NewBuildName.Hide(); m_BuildMessage = m_Root.Q <VisualElement>(kNamePrefix + "build-message"); m_BuildMessage.Hide(); m_ActionButtons = m_Root.Q <VisualElement>(kNamePrefix + "footer"); m_StartModeDropdown = new PopupField <StartMode>(sStartModes, StartMode.RunLatestBuild, FormatStartMode, FormatStartMode) { style = { flexGrow = 1 } }; m_StartModeDropdown.RegisterValueChangedCallback(OnSelectedStartModeChanged); m_ActionButtons.Q <VisualElement>(kNamePrefix + "footer__build-mode-container").Add(m_StartModeDropdown); m_StartButton = m_ActionButtons.Q <Button>(kNamePrefix + "footer__start-button"); m_StartButton.clicked += () => { m_FooterMessage.Hide(); Start(m_StartModeDropdown.value, m_SelectedConfiguration); }; m_FooterMessage = m_Root.Q <VisualElement>(kNamePrefix + "message"); m_FooterMessage.Hide(); rootVisualElement.Add(m_Root); }
public AllGraphsController(LibraryTabElement libraryTab) { m_searchField = libraryTab.Q <ToolbarSearchField>(SEARCH_FIELD); m_searchField.RegisterValueChangedCallback(x => { OnSearchQueryChanged(x.newValue); }); m_allGraphsGroup = libraryTab.Q <VisualElement>(ALL_GRAPHS_GROUP); m_libraryTab = libraryTab; PopulateGroups(); }
void CreateSearchField(string ussClass) { m_SearchField = new ToolbarSearchField { value = string.IsNullOrEmpty(BaseState.SearchFilter) ? string.Empty : BaseState.SearchFilter }; m_SearchField.AddToClassList(ussClass); m_SearchField.Q("unity-cancel").AddToClassList(UssClasses.DotsEditorCommon.SearchFieldCancelButton); m_SearchField.RegisterValueChangedCallback(OnFilterChanged); UIElementHelper.ToggleVisibility(m_SearchField, BaseState.IsSearchFieldVisible); }
public StylePropertyDebugger(VisualElement debuggerSelection) { selectedElement = debuggerSelection; m_Toolbar = new Toolbar(); Add(m_Toolbar); var searchField = new ToolbarSearchField(); searchField.AddToClassList("unity-style-debugger-search"); searchField.RegisterValueChangedCallback(e => { m_SearchFilter = e.newValue; BuildFields(); }); m_Toolbar.Add(searchField); var showAllToggle = new ToolbarToggle(); showAllToggle.AddToClassList("unity-style-debugger-toggle"); showAllToggle.text = "Show all"; showAllToggle.RegisterValueChangedCallback(e => { m_ShowAll = e.newValue; BuildFields(); }); m_Toolbar.Add(showAllToggle); var sortToggle = new ToolbarToggle(); sortToggle.AddToClassList("unity-style-debugger-toggle"); sortToggle.text = "Sort"; sortToggle.RegisterValueChangedCallback(e => { m_Sort = e.newValue; BuildFields(); }); m_Toolbar.Add(sortToggle); m_CustomPropertyFieldsContainer = new VisualElement(); Add(m_CustomPropertyFieldsContainer); m_FieldsContainer = new VisualElement(); Add(m_FieldsContainer); if (selectedElement != null) { BuildFields(); } AddToClassList("unity-style-debugger"); }
public DependencyListView(List <SerializedProperty> itemsSource, int itemHeight, SerializedObject serializedObject) { SetupQueryEngine(); m_SerializedObject = serializedObject; m_OriginalItems = itemsSource; m_FilteredItems = new List <SerializedProperty>(); m_ItemSize = itemHeight; var listViewContainer = new VisualElement(); listViewContainer.AddToClassList(k_ListView); listViewContainer.style.flexGrow = 1; listView = new ListView(m_FilteredItems, itemHeight, MakeItem, BindItem); listView.name = k_ListInternalView; listView.showAlternatingRowBackgrounds = AlternatingRowBackground.ContentOnly; listView.style.flexGrow = 1; listView.RegisterCallback <KeyUpEvent>(OnKeyUpEvent); listView.selectionType = SelectionType.Multiple; listView.itemsChosen += OnDoubleClick; listView.style.maxHeight = Mathf.Max(m_OriginalItems.Count * m_ItemSize + 100, listView.style.maxHeight.value.value); var searchField = new ToolbarSearchField(); searchField.name = "dependency-listview-toolbar-searchfield"; searchField.RegisterValueChangedCallback(evt => { m_CurrentSearchString = evt.newValue; FilterItems(evt.newValue); }); var textField = searchField.Q <TextField>(); if (textField != null) { textField.maxLength = 1024; m_SearchFieldReady = true; } searchField.AddToClassList(k_SearchFieldItem); Add(searchField); header = MakeHeader(); UpdateHeader(); listViewContainer.Add(header); listViewContainer.Add(listView); Add(listViewContainer); FilterItems(searchField.value); }
public void UpdateSearch() { ToolbarSearchField searchField = root.Q <ToolbarSearchField>(UXMLNames.SearchField); string newVal = searchField.value; if (newVal != searchString) { searchString = searchField.value; AssignData(); ResetPathField(); } searchString = searchField.value; }
public SearchBar([CanBeNull] Action <string> searchEvent = null) { // Setup delayed search event to throttle requests. m_SearchEventTimer = new Timer(_ => EditorApplication.delayCall += () => { m_SearchEventFlag = false; Search(m_LatestSearchValue); }); AddToClassList(UssClassName); styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(k_StylePath)); m_SearchField = new ToolbarSearchField(); m_Placeholder = new Label { text = StringAssets.search, pickingMode = PickingMode.Ignore }; m_SearchField.AddToClassList(SearchFieldUssClassName); m_Placeholder.AddToClassList(PlaceholderUssClassName); Add(m_SearchField); Add(m_Placeholder); // Setup search event if (searchEvent != null) { Search += searchEvent; } // Setup events to hide/show placeholder. var textField = m_SearchField.Q <TextField>(className: ToolbarSearchField.textUssClassName); textField.RegisterCallback <FocusInEvent>(e => { m_Focused = true; UpdatePlaceholderVisibility(); }); textField.RegisterCallback <FocusOutEvent>(e => { m_Focused = false; UpdatePlaceholderVisibility(); }); m_SearchField.RegisterValueChangedCallback(SearchEventThrottle); // Set initial placeholder hide/show status. ShowPlaceholder(); }
void Initialize(EntitySelectionProxy proxy) { m_Context.SetContext(proxy); m_Root.Clear(); var header = new PropertyElement(); header.AddContext(m_Context); header.SetTarget(new EntityHeader(m_Context)); m_Root.Add(header); m_SearchField = header.Q <ToolbarSearchField>(); m_SearchField.RegisterValueChangedCallback(evt => { m_Filters.Clear(); var value = evt.newValue.Trim(); var matches = value.Split(' '); foreach (var match in matches) { m_Filters.Add(match); } SearchChanged(); }); m_Settings = m_Root.Q <ToolbarMenu>(); // TODO: Remove once we have menu items. m_Settings.Hide(); m_ComponentsRoot = new VisualElement(); m_Root.Add(m_ComponentsRoot); Resources.Templates.Inspector.ComponentsRoot.AddStyles(m_ComponentsRoot); m_ComponentsRoot.AddToClassList("entity-inspector__components-root"); m_ComponentsRoot.RegisterCallback <GeometryChangedEvent>(OnGeometryChanged); m_TagsRoot = new TagComponentContainer(m_Context); m_ComponentsRoot.Add(m_TagsRoot); m_InspectorVisitor = new EntityInspectorVisitor(m_ComponentsRoot, m_TagsRoot, m_Context); PropertyContainer.Visit(m_Context.EntityContainer, m_InspectorVisitor); m_Root.ForceUpdateBindings(); }
public ScrewItHotSubtreeView() { Root = new VisualElement { style = { flexGrow = 1 } }; m_ThreadSelection = new ToolbarMenu { text = "Select Thread" }; m_ToolbarItems.Add(m_ThreadSelection); m_FunctionSearchField = new ToolbarSearchField(); m_ToolbarItems.Add(m_FunctionSearchField); var updateBtn = new ToolbarButton { text = "Update", style = { unityTextAlign = TextAnchor.MiddleLeft } }; updateBtn.clicked += () => RefreshData(m_CurrentThread); m_ToolbarItems.Add(updateBtn); m_ColumnHeader = new MultiColumnHeader(CreateHeaderState()) { canSort = false }; m_SubtreeTreeView = new HotSubtreeTreeView(new TreeViewState(), m_ColumnHeader); m_SubtreeTreeView.Reload(); var treeContainer = new IMGUIContainer { style = { flexGrow = 1 } }; treeContainer.onGUIHandler = () => m_SubtreeTreeView.OnGUI(treeContainer.contentRect); m_ColumnHeader.ResizeToFit(); Root.Add(treeContainer); }
public static void BuildContainer(DataConfigEditor editor, VisualElement container, SerializedObject so) { var structComponents = new VisualElement(); var removeStructComponents = new VisualElement(); container.Clear(); var searchField = new ToolbarSearchField(); searchField.AddToClassList("search-field"); searchField.RegisterValueChangedCallback((evt) => { var search = evt.newValue.ToLower(); Search(search, structComponents); Search(search, removeStructComponents); }); container.Add(searchField); { var header = new Label("Components:"); header.AddToClassList("header"); container.Add(header); container.Add(structComponents); var usedComponents = new System.Collections.Generic.HashSet <System.Type>(); var source = so.FindProperty("structComponents"); BuildInspectorProperties(editor, usedComponents, source, structComponents, noFields: false); container.Add(CreateButton(editor, usedComponents, source, structComponents, noFields: false)); } { var header = new Label("Remove Components:"); header.AddToClassList("header"); container.Add(header); container.Add(removeStructComponents); var usedComponents = new System.Collections.Generic.HashSet <System.Type>(); var source = so.FindProperty("removeStructComponents"); BuildInspectorProperties(editor, usedComponents, source, removeStructComponents, noFields: true); container.Add(CreateButton(editor, usedComponents, source, removeStructComponents, noFields: true)); } editor.BuildUsedTemplates(container, so); }
protected override void Rebuild(VisualElement root) { if (s_invokables == null) { s_invokables = GameConsole.Invokables.ToArray(); } _searchField = root.Q <ToolbarSearchField>("searchField"); _searcher.FilterDisabled = false; _searchField.RegisterValueChangedCallback((e) => OnSearchValueChanged(e.newValue)); _listView = root.Q <ListView>("invokablesContainer"); _listView.selectionType = SelectionType.None; _listView.itemHeight = 18; _listView.makeItem = CreateElement; _listView.bindItem = (v, i) => Bind((CommandVisualElement)v, i); _listView.itemsSource = _displayedInvokables; _listView.style.flexGrow = 1; OnSearchValueChanged(_searchField.value); }
public SearchSuggest() { AddToClassList("search-suggest"); textEntry = new ToolbarSearchField { name = "search-suggest-input" }; MatchedSuggestOption = new List <SuggestOption>(); ConfigureOptionList(); textEntry.style.flexGrow = 1; matchingSuggestOptions = suggestOption => suggestOption.DisplayName.ToLower().Contains(textEntry.value.ToLower()); RegisterCallback <AttachToPanelEvent>(OnAttached); RegisterCallback <DetachFromPanelEvent>(OnDetached); Add(textEntry); }
private void CreateToolbar() { _toolbar = new Toolbar(); _toolbarBreadcrumbs = new ToolbarBreadcrumbs(); _toolbar.Add(_toolbarBreadcrumbs); var spacer = new ToolbarSpacer { flex = true }; _toolbar.Add(spacer); var saveBtn = new Button(_view.Save) { text = "Save" }; _toolbar.Add(saveBtn); var executeBtn = new Button(Execute) { text = "Execute All" }; _toolbar.Add(executeBtn); var search = new ToolbarSearchField(); _toolbar.Add(search); var clearBtn = new Button(Clear) { text = "Clear" }; _toolbar.Add(clearBtn); rootVisualElement.Add(_toolbar); }
public TaggedAnimationClipSelector() { UIElementsUtils.ApplyStyleSheet("BoundaryClipWindow.uss", this); AddToClassList("clipSelector"); m_FilterString = string.Empty; m_FilterField = new ToolbarSearchField(); m_FilterField.RegisterValueChangedCallback(OnFilterChanged); Add(m_FilterField); var selectionArea = new VisualElement(); selectionArea.AddToClassList("row"); { m_RevertImage = new Image(); var revertClick = new Clickable(() => Changes = false); m_RevertImage.AddManipulator(revertClick); m_RevertImage.AddToClassList("revertIcon"); selectionArea.Add(m_RevertImage); m_CurrentSelectionLabel = new Label(); m_CurrentSelectionLabel.AddToClassList("selectionLabel"); selectionArea.Add(m_CurrentSelectionLabel); } Add(selectionArea); m_View = new ListView(); m_View.itemHeight = 18; m_View.makeItem = MakeItem; m_View.bindItem = BindItem; m_View.selectionType = SelectionType.None; m_View.AddToClassList("clipList"); Add(m_View); UpdateLabel(); }
public override VisualElement CreateInspectorGUI() { (StyleSheet styleSheet, VisualTreeAsset uxml) = StyleExtensions.GetStyleSheetAndUXML("PackageUpdater"); packageItemUXML = StyleExtensions.GetUXML("PackageItem"); root = new VisualElement(); root.styleSheets.Add(styleSheet); root.styleSheets.Add(StyleExtensions.GetStyleSheet("VertxShared")); uxml.CloneTree(root); packageRoot = root.Q("Packages Root"); addRoot = root.Q("Add Root"); addContainer = addRoot.Q("Add Container"); search = addContainer.Q <ToolbarSearchField>("Search"); search.RegisterCallback <ChangeEvent <string> >(Search); if (updatingPackages.arraySize == 0) { AddHelpBox(); } else { for (int i = 0; i < updatingPackages.arraySize; i++) { AddTrackedPackage(i); } } //----------------------------------------------------- addButton = addRoot.Q <Button>("Add Button"); addButton.SetEnabled(false); addButton.clickable.clicked += PopulateAdd; listView = addRoot.Q <ListView>("Add Contents"); // List view configuration listView.makeItem = () => { Label button = new Label(); button.AddToClassList("addPackageItemButton"); return(button); }; listView.bindItem = (element, i) => { string packageName = (string)listView.itemsSource[i]; ((Label)element).text = packageName; }; #if UNITY_2020_1_OR_NEWER listView.onItemsChosen += objects => { int c = untrackedPackages.Count; foreach (var o in objects) { //Add package so it can be tracked by the Package Updater. string packageName = (string)o; int index = updatingPackages.arraySize++; updatingPackages.GetArrayElementAtIndex(index).FindPropertyRelative(ignoreProp).stringValue = null; AddTrackedPackage(index, packageName); serializedObject.ApplyModifiedProperties(); listView.Clear(); addContainer.AddToClassList(hiddenStyle); c--; } //Disable the add button if there will be no more packages. if (c <= 0) { DisableAddButton(); } else { EnableAddButton(); } }; #else listView.onItemChosen += o => { //Disable the add button if there will be no more packages. if (untrackedPackages.Count <= 1) { DisableAddButton(); } else { EnableAddButton(); } //Add package so it can be tracked by the Package Updater. string packageName = (string)o; int index = updatingPackages.arraySize++; AddTrackedPackage(index, packageName); serializedObject.ApplyModifiedProperties(); listView.Clear(); addContainer.AddToClassList(hiddenStyle); }; #endif addContainer.AddToClassList(hiddenStyle); //----------------------------------------------------- updateButton = root.Q <Button>("Update Button"); updateButton.SetEnabled(false); updateButton.clickable.clicked += DoUpdate; var helpBox = root.Q <HelpBox>("Auto Update Help Box"); helpBox.Q <Label>(className: HelpBox.uSSLabelClassName).text = NUtilitiesPreferences.AutoUpdatePackages ? "Auto-Update is enabled." : "Auto-Update is disabled."; helpBox.RegisterCallback <MouseUpEvent>(evt => SettingsService.OpenUserPreferences(NUtilitiesPreferences.PreferencesPath)); ValidateAddButton(); ValidatePackages(); return(root); }
VisualElement CreateToolbar() { var toolbar = new VisualElement { style = { flexDirection = FlexDirection.Row, flexGrow = 0, backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.75f) } }; var options = new VisualElement { style = { alignContent = Align.Center } }; toolbar.Add(options); toolbar.Add(new Button(ExploreAsset) { text = "Explore Asset", }); toolbar.Add(new Button(ClearGraph) { text = "Clear" }); toolbar.Add(new Button(ResetGroups) { text = "Reset Groups" }); toolbar.Add(new Button(ResetAllNodes) { text = "Reset Nodes" }); var ts = new ToolbarSearchField(); ts.RegisterValueChangedCallback(x => { if (string.IsNullOrEmpty(x.newValue)) { m_GraphView.FrameAll(); return; } m_GraphView.ClearSelection(); // m_GraphView.graphElements.ForEach(y => { // BROKEN, Case 1268337 m_GraphView.graphElements.ToList().ForEach(y => { if (y is Node node && y.title.IndexOf(x.newValue, System.StringComparison.OrdinalIgnoreCase) >= 0) { m_GraphView.AddToSelection(node); } }); m_GraphView.FrameSelection(); }); toolbar.Add(ts); AlignmentToggle = new Toggle(); AlignmentToggle.text = "Horizontal Layout"; AlignmentToggle.value = false; AlignmentToggle.RegisterValueChangedCallback(x => { ResetAllNodes(); }); toolbar.Add(AlignmentToggle); //SharedToggle = new Toggle(); //SharedToggle.text = "Show shared groups (WIP)"; //SharedToggle.value = false; //SharedToggle.RegisterValueChangedCallback(x => { // ResetAllNodes(); //}); //toolbar.Add(SharedToggle); return(toolbar); }
public StoryPreview() { var types = Utility.GetSonTypes(typeof(StoryDataBase)); // 工具栏 Toolbar toolbar = new Toolbar() { style = { marginBottom = 5, marginTop = 5, marginLeft = 5, marginRight = 5, } }; // 不同类型的Story ToolbarMenu toolbarMenu = new ToolbarMenu() { text = "All" }; toolbarMenu.menu.AppendAction("All", (e) => { CurrentType = null; toolbarMenu.text = "All"; }, a => CurrentType == null ? DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal); foreach (var type in types) { toolbarMenu.menu.AppendAction(type.Name, (e) => { CurrentType = type; toolbarMenu.text = type.Name; }, a => CurrentType == type ? DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal); } toolbar.Add(toolbarMenu); // 显示所有选择的Story selectedStoryToggle = new ToolbarToggle(); selectedStoryToggle.RegisterValueChangedCallback((e) => { IsSelected = e.newValue; }); selectedStoryToggle.text = "Selected"; toolbar.Add(selectedStoryToggle); ToolbarSearchField toolbarSearch = new ToolbarSearchField { style = { width = 100, flexDirection = FlexDirection.Row, alignSelf = Align.FlexEnd, } }; toolbarSearch.RegisterValueChangedCallback((e) => { CurrentMatching = e.newValue; }); toolbar.Add(toolbarSearch); // 预览区 m_scrollView = new VisualElement(/*ScrollViewMode.VerticalAndHorizontal*/) { style = { marginLeft = 10, marginTop = 10, marginRight = 10, marginBottom = 10, // Example of an horizontal container that wraps its contents // over several lines depending on available space flexWrap = Wrap.Wrap, flexDirection = FlexDirection.Row, } }; Button confirmBtn = new Button(OnConfirmClick) { text = "Confirm", style = { alignSelf = Align.FlexEnd, } }; this.Add(toolbar); this.Add(m_scrollView); this.Add(confirmBtn); }
public void OnEnable() { m_GraphView = new AssetGraphView { name = "Asset Dependency Graph", }; #region Toolbar var toolbar = new VisualElement { style = { flexDirection = FlexDirection.Row, flexGrow = 0, backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.75f) } }; var options = new VisualElement { style = { alignContent = Align.Center } }; toolbar.Add(options); toolbar.Add(new Button(ExploreAsset) { text = "Explore Asset", }); toolbar.Add(new Button(ClearGraph) { text = "Clear" }); toolbar.Add(new Button(ResetAllGroups) { text = "Reset" }); codeToggle = new Toggle(); codeToggle.text = "Hide Scripts"; codeToggle.value = true; codeToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(codeToggle); MaterialToggle = new Toggle(); MaterialToggle.text = "Hide Materials"; MaterialToggle.value = false; MaterialToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(MaterialToggle); textureToggle = new Toggle(); textureToggle.text = "Hide Textures"; textureToggle.value = true; textureToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(textureToggle); shaderToggle = new Toggle(); shaderToggle.text = "Hide Shaders"; shaderToggle.value = true; shaderToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(shaderToggle); audioClipToggle = new Toggle(); audioClipToggle.text = "Hide Audioclips"; audioClipToggle.value = false; audioClipToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(audioClipToggle); animationClipToggle = new Toggle(); animationClipToggle.text = "Hide Animationclips"; animationClipToggle.value = false; animationClipToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(animationClipToggle); CustomToggle = new Toggle(); CustomToggle.text = "Hide Custom"; CustomToggle.value = true; CustomToggle.RegisterValueChangedCallback(x => { FilterAssetGroups(); }); toolbar.Add(CustomToggle); var ts = new ToolbarSearchField(); ts.RegisterValueChangedCallback(x => { if (string.IsNullOrEmpty(x.newValue)) { m_GraphView.FrameAll(); return; } m_GraphView.ClearSelection(); // m_GraphView.graphElements.ForEach(y => { // BROKEN, Case 1268337 m_GraphView.graphElements.ToList().ForEach(y => { if (y is Node node && y.title.IndexOf(x.newValue, System.StringComparison.OrdinalIgnoreCase) >= 0) { m_GraphView.AddToSelection(node); } }); m_GraphView.FrameSelection(); }); toolbar.Add(ts); AlignmentToggle = new Toggle(); AlignmentToggle.text = "Horizontal Layout"; AlignmentToggle.value = false; AlignmentToggle.RegisterValueChangedCallback(x => { ResetAllGroups(); }); toolbar.Add(AlignmentToggle); #endregion #if !UNITY_2019_1_OR_NEWER rootVisualElement = this.GetRootVisualContainer(); #endif rootVisualElement.Add(toolbar); rootVisualElement.Add(m_GraphView); m_GraphView.StretchToParentSize(); toolbar.BringToFront(); }
public void OnEnable() { var root = this.rootVisualElement; root.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Examples/Editor/todolist.uss")); var toolbar = new Toolbar(); root.Add(toolbar); var btn1 = new ToolbarButton { text = "Button" }; toolbar.Add(btn1); var spc = new ToolbarSpacer(); toolbar.Add(spc); var tgl = new ToolbarToggle { text = "Toggle" }; toolbar.Add(tgl); var spc2 = new ToolbarSpacer() { name = "flexSpacer1", flex = true }; toolbar.Add(spc2); var menu = new ToolbarMenu { text = "Menu" }; menu.menu.AppendAction("Default is never shown", a => {}, a => DropdownMenuAction.Status.None); menu.menu.AppendAction("Normal menu", a => {}, a => DropdownMenuAction.Status.Normal); menu.menu.AppendAction("Hidden is never shown", a => {}, a => DropdownMenuAction.Status.Hidden); menu.menu.AppendAction("Checked menu", a => {}, a => DropdownMenuAction.Status.Checked); menu.menu.AppendAction("Disabled menu", a => {}, a => DropdownMenuAction.Status.Disabled); menu.menu.AppendAction("Disabled and checked menu", a => {}, a => DropdownMenuAction.Status.Disabled | DropdownMenuAction.Status.Checked); toolbar.Add(menu); var spc3 = new ToolbarSpacer() { name = "flexSpacer2", flex = true }; toolbar.Add(spc3); var popup = new ToolbarMenu { text = "Popup", variant = ToolbarMenu.Variant.Popup }; popup.menu.AppendAction("Popup", a => {}, a => DropdownMenuAction.Status.Normal); toolbar.Add(popup); var popupSearchField = new ToolbarPopupSearchField(); popupSearchField.RegisterValueChangedCallback(OnSearchTextChanged); popupSearchField.menu.AppendAction( "Popup Search Field", a => m_popupSearchFieldOn = !m_popupSearchFieldOn, a => m_popupSearchFieldOn ? DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal); toolbar.Add(popupSearchField); var searchField = new ToolbarSearchField(); searchField.RegisterValueChangedCallback(OnSearchTextChanged); toolbar.Add(searchField); var popupWindow = new PopupWindow(); popupWindow.text = "New Task"; root.Add(popupWindow); m_TextInput = new TextField() { name = "input", viewDataKey = "input", isDelayed = true }; popupWindow.Add(m_TextInput); m_TextInput.RegisterCallback <ChangeEvent <string> >(AddTask); var button = new Button(AddTask) { text = "Save task" }; popupWindow.Add(button); var box = new Box(); m_TasksContainer = new ScrollView(); m_TasksContainer.showHorizontal = false; box.Add(m_TasksContainer); root.Add(box); if (m_Tasks != null) { foreach (string task in m_Tasks) { m_TasksContainer.Add(CreateTask(task)); } } }
void CreateVisualTree() { string[] guids = AssetDatabase.FindAssets("t:GameAssets"); //foreach (string guid in guids) //{ // //Debug.Log("ScriptObj: " + AssetDatabase.GUIDToAssetPath(guid)); //} if (guids != null && guids.Length > 0) { //allGameAssets = ScriptableObject.CreateInstance<GameAssets>(); allGameAssets = (GameAssets)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guids[0]), typeof(GameAssets)); } else { if (AssetDatabase.IsValidFolder("Assets/Export")) { //Debug.Log("Exists"); } else { string ret; ret = AssetDatabase.CreateFolder("Assets", "Export"); if (AssetDatabase.GUIDToAssetPath(ret) != "") { Debug.Log("Folder asset created"); } else { Debug.Log("Couldn't find the GUID for the path"); } } AssetDatabase.Refresh(); if (AssetDatabase.IsValidFolder("Assets/Export/Assets")) { //Debug.Log("Exists"); } else { string ret; ret = AssetDatabase.CreateFolder("Assets/Export", "Assets"); if (AssetDatabase.GUIDToAssetPath(ret) != "") { Debug.Log("Folder asset created"); } else { Debug.Log("Couldn't find the GUID for the path"); } } if (AssetDatabase.IsValidFolder("Assets/Export/Assets/Data")) { //Debug.Log("Exists"); } else { string ret; ret = AssetDatabase.CreateFolder("Assets/Export/Assets", "Data"); if (AssetDatabase.GUIDToAssetPath(ret) != "") { Debug.Log("Folder asset created"); } else { Debug.Log("Couldn't find the GUID for the path"); } } AssetDatabase.Refresh(); allGameAssets = ScriptableObject.CreateInstance <GameAssets>(); AssetDatabase.CreateAsset(allGameAssets, "Assets/Export/Data/allGameAssets.asset"); } var visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/Editor/EditorComponents/AssetManager.uxml"); var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Editor/LevelEditorWindow.uss"); assetManager = visualTree.CloneTree(); addAssetContainer = assetManager.Q <Box>("addAssetContainer"); //search field var popupSearchField = new ToolbarSearchField(); popupSearchField.AddToClassList("asset-manager-searchfield"); popupSearchField.RegisterValueChangedCallback(OnSearchTextChanged); assetTypeSelection = new EnumField(AssetType.Texture); assetTypeSelection.RegisterValueChangedCallback(AssetTypeChange); assetSelectionField = new ObjectField { objectType = typeof(UnityEngine.Texture) }; addAssetButton = new Button(); addAssetButton.text = "Add Asset"; addAssetButton.RegisterCallback <MouseUpEvent>(AddAsset); saveAssetsButton = new Button(); saveAssetsButton.text = "Export All Assets"; saveAssetsButton.RegisterCallback <MouseUpEvent>(SaveAssets); assetListBox = new Box(); assetListBox.style.height = 777; assetListBoxContainer = new ScrollView(); assetListBoxContainer.showHorizontal = false; assetListBox.Add(assetListBoxContainer); addAssetContainer.Add(popupSearchField); addAssetContainer.Add(assetTypeSelection); addAssetContainer.Add(assetSelectionField); addAssetContainer.Add(addAssetButton); addAssetContainer.Add(assetListBox); addAssetContainer.Add(saveAssetsButton); #region LoadAssetsFromAssetData foreach (Texture t in allGameAssets.gameTextures) { assetListBoxContainer.Add(CreateAsset(t.name)); } foreach (AudioClip ac in allGameAssets.gameAudioClips) { assetListBoxContainer.Add(CreateAsset(ac.name)); } foreach (Font f in allGameAssets.gameFonts) { assetListBoxContainer.Add(CreateAsset(f.name)); } #endregion }
/// <summary> /// UI Element Browser Bar /// </summary> void BrowserBar(VisualElement root) { #region Browser Bar //Browser Bar Toolbar toolbar = new Toolbar(); toolbar.style.justifyContent = Justify.SpaceBetween; root.Add(toolbar); // Back Button backButton = AddToolbarButton(EditorGUIUtility.isProSkin ? GetTexture("Back") : GetTexture("Back_Alt"), Back, 5); backButton.tooltip = "Back"; backButton.SetEnabled(false); toolbar.Add(backButton); // Forward Button forwardButton = AddToolbarButton(EditorGUIUtility.isProSkin ? GetTexture("Forward") : GetTexture("Forward_Alt"), Forward, 0); forwardButton.tooltip = "Forward"; forwardButton.SetEnabled(false); toolbar.Add(forwardButton); homeButton = AddToolbarButton(EditorGUIUtility.isProSkin ? GetTexture("Home") : GetTexture("Home_Alt"), Home, 2); homeButton.tooltip = "Home"; toolbar.Add(homeButton); ToolbarButton AddToolbarButton(Texture texture, Action action, float marginLeft) { ToolbarButton toolbarButton = new ToolbarButton(action) { style = { marginLeft = marginLeft, width = 20, borderLeftWidth = marginLeft == 0 ? 0 : 1, borderColor = new Color(0.57f, 0.57f, 0.57f), borderTopLeftRadius = 2, alignItems = Align.Center, paddingBottom = 0, paddingLeft = 0, paddingRight = 0, } }; toolbarButton.Add(new Image { image = texture, style = { marginTop = 4, height = 10, width = 10 } }); return(toolbarButton); } // Search Bar ToolbarSearchField toolbarSearchField = new ToolbarSearchField(); toolbarSearchField.SetValueWithoutNotify(searchString); //ToolbarSearchField's buttons have broken hover and action pseudo-states so we have to fix that StyleSheet fixSheet = LoadAssetOfType <StyleSheet>("InbuiltFixStyles", SearchFilter.Packages); toolbarSearchField.styleSheets.Add(fixSheet); toolbarSearchField.style.flexGrow = 1; toolbarSearchField.RegisterCallback <ChangeEvent <string> >(evt => { searchString = evt.newValue; DoSearch(); }); TextField textField = toolbarSearchField.Q <TextField>(); textField.RegisterCallback <FocusEvent>(evt => { if (searchRoot.visible || string.IsNullOrEmpty(searchString)) { return; } //If there's a search string and we're in the search box we should enable the search container. searchRoot.visible = true; //If there isn't any search (ie. the previously cached search was never built, perform the search) if (searchStringsCache.Count == 0) { DoSearch(); } }); //The internal text field has a fixed width so we have to remove that StyleLength width = textField.style.width; width.keyword = StyleKeyword.Auto; textField.style.width = width; //The cancel button is improperly aligned so we have to fix that Button cancelButton = toolbarSearchField.Q <Button>("unity-cancel"); cancelButton.style.width = 15; //The search button doesn't expand automatically, so we have to fix that Button searchButton = toolbarSearchField.Q <Button>("unity-search"); searchButton.style.flexGrow = 1; //Set the Search Field to be 1/2 width toolbar.RegisterCallback <GeometryChangedEvent>(evt => toolbarSearchField.style.marginLeft = evt.newRect.width / 2f - 70); toolbar.Add(toolbarSearchField); #endregion }
public void OnEnable() { #region UXML and USS set-up // Each editor window contains a root VisualElement object VisualElement root = rootVisualElement; // Import UXML and USS StyleSheet acToolsStyles = AssetDatabase.LoadAssetAtPath <StyleSheet>(ACToolsEditorUI.UniversalStyleSheet); VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>("Assets/_ACTools/_Data Manager/Editor/Window/DataManagerWindow.uxml"); StyleSheet styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/_ACTools/_Data Manager/Editor/Window/DataManagerWindow.uss"); // Adds style sheets to root. root.styleSheets.Add(acToolsStyles); root.styleSheets.Add(styleSheet); // Clones the visual tree and adds it to the root. VisualElement tree = visualTree.CloneTree(); tree.AddToClassList("ACTools_template-container"); root.Add(tree); #endregion #region Toolbar // Sets up the add fields, buttons, and events. #region Create Menu createMenu = tree.Q <ToolbarMenu>("CreateMenu"); createMenu.Q <TextElement>("").AddToClassList("ACTools_toolbar-icon_cross"); CreateDataType += CreateNewDataType.CreateDataType; CreateDataType += CreateDataTypeFromCVSWindow.ShowWindow; createMenu.menu.InsertAction(0, NewDataTypeButtonName, CreateDataType); createMenu.menu.InsertAction(1, CVSDataTypeButtonName, CreateDataType); #endregion #region Search Field searchField = tree.Q <ToolbarSearchField>("SearchTypes"); searchField.Q <Button>("unity-search").clickable.clicked += SearchDataManagerWindow; #endregion #region Refresh Button refreshButton = tree.Q <ToolbarButton>("RefreshButton"); refreshButton.clickable.clicked += RefreshDataManagerAction; VisualElement refreshIcon = new VisualElement(); refreshIcon.AddToClassList("ACTools_toolbar-icon_refresh"); refreshButton.Add(refreshIcon); #endregion #endregion #region Main Row // Sets selected values to null; DataTypeSelected = false; ItemSelected = false; #region Left Column // Gets the left column. leftColumnItems = tree.Q <VisualElement>("LC_Items"); DrawLeftColumnItems(); #endregion #region Right Column // Gets the middle column. rightColumnItems = tree.Q <VisualElement>("RC_Items"); DrawRightColumnItems(); #endregion #endregion }
public void OnEnable() { m_GraphView = new AssetGraphView { name = "Asset Dependency Graph", }; var toolbar = new VisualElement { style = { flexDirection = FlexDirection.Row, flexGrow = 0, backgroundColor = new Color(0.25f, 0.25f, 0.25f, 0.75f) } }; var options = new VisualElement { style = { alignContent = Align.Center } }; toolbar.Add(options); toolbar.Add(new Button(ExploreAsset) { text = "Explore Asset", }); toolbar.Add(new Button(ClearGraph) { text = "Clear" }); var ts = new ToolbarSearchField(); ts.RegisterValueChangedCallback(x => { if (string.IsNullOrEmpty(x.newValue)) { m_GraphView.FrameAll(); return; } m_GraphView.ClearSelection(); // m_GraphView.graphElements.ForEach(y => { // BROKEN, Case 1268337 m_GraphView.graphElements.ToList().ForEach(y => { if (y is Node node && y.title.IndexOf(x.newValue, StringComparison.OrdinalIgnoreCase) >= 0) { m_GraphView.AddToSelection(node); } }); m_GraphView.FrameSelection(); }); toolbar.Add(ts); #if !UNITY_2019_1_OR_NEWER rootVisualElement = this.GetRootVisualContainer(); #endif rootVisualElement.Add(toolbar); rootVisualElement.Add(m_GraphView); m_GraphView.StretchToParentSize(); toolbar.BringToFront(); }
public override VisualElement CreateInspectorGUI() { var container = new VisualElement(); container.styleSheets.Add(EditorUtilities.Load <StyleSheet>("Editor/Core/DataConfigs/styles.uss", isRequired: true)); this.rootElement = container; var target = this.target as ME.ECS.Debug.EntityDebugComponent; if (target.world != null && target.world.isActive == true) { this.debug = new ME.ECS.Debug.EntityProxyDebugger(target.entity, target.world); this.temp.components = this.debug.GetComponentsList(); this.temp.sharedComponents = this.debug.GetSharedComponentsList(); container.schedule.Execute(this.Update).Every((long)(target.world.GetTickTime() * 1000f)); var searchField = new ToolbarSearchField(); searchField.AddToClassList("search-field"); searchField.RegisterValueChangedCallback((evt) => { var search = evt.newValue.ToLower(); DataConfigEditor.Search(search, this.componentsContainer); DataConfigEditor.Search(search, this.sharedComponentsContainer); }); container.Add(searchField); { var entityElement = new VisualElement(); this.entityContainer = entityElement; entityElement.name = "EntityContainer"; entityElement.AddToClassList("entity-container"); var id = new Label("ID:"); id.AddToClassList("entity-container-item"); id.AddToClassList("entity-container-item-label"); entityElement.Add(id); var idValue = new Label(); idValue.AddToClassList("entity-container-item"); idValue.AddToClassList("entity-container-item-value"); idValue.name = "EntityId"; this.entityId = idValue; entityElement.Add(idValue); var gen = new Label("Generation:"); gen.AddToClassList("entity-container-item"); gen.AddToClassList("entity-container-item-label"); entityElement.Add(gen); var genValue = new Label(); genValue.AddToClassList("entity-container-item"); genValue.AddToClassList("entity-container-item-value"); genValue.name = "EntityGen"; this.entityGen = genValue; entityElement.Add(genValue); var version = new Label("Version:"); version.AddToClassList("entity-container-item"); version.AddToClassList("entity-container-item-label"); entityElement.Add(version); var versionValue = new Label(); versionValue.AddToClassList("entity-container-item"); versionValue.AddToClassList("entity-container-item-value"); versionValue.name = "EntityVersion"; this.entityVersion = versionValue; entityElement.Add(versionValue); container.Add(entityElement); var changedWarning = new Label("Selected entity is no longer available: generation has been changed."); this.entityContainerWarning = changedWarning; changedWarning.name = "EntityChanged"; changedWarning.AddToClassList("entity-changed-warning"); changedWarning.AddToClassList("hidden"); container.Add(changedWarning); } this.content = new VisualElement(); this.content.name = "Content"; container.Add(this.content); if (target.entity.IsAlive() == true) { this.BuildLists(this.content); } } else { var element = new Label("No active world found"); element.AddToClassList("world-not-found"); this.rootElement.Add(element); } return(this.rootElement); }
public override void OnOpen() { var styleSheet = BuilderPackageUtilities.LoadAssetAtPath <StyleSheet>(k_UssPath); editorWindow.rootVisualElement.styleSheets.Add(styleSheet); editorWindow.rootVisualElement.focusable = true; editorWindow.rootVisualElement.AddToClassList(k_BaseClass); editorWindow.rootVisualElement.AddManipulator(m_NavigationManipulator = new KeyboardNavigationManipulator(Apply)); var searchField = new ToolbarSearchField(); searchField.AddToClassList(k_SearchField); searchField.RegisterCallback <AttachToPanelEvent>(evt => { ((VisualElement)evt.target)?.Focus(); }); searchField.RegisterCallback <KeyDownEvent>(evt => { switch (evt.keyCode) { case KeyCode.UpArrow: case KeyCode.DownArrow: case KeyCode.PageDown: case KeyCode.PageUp: evt.StopPropagation(); m_ScrollView.Focus(); break; case KeyCode.Return: case KeyCode.KeypadEnter: evt.StopPropagation(); if (string.IsNullOrWhiteSpace(searchField.value) || m_SelectedIndex < 0) { m_ScrollView.Focus(); return; } onSelectionChanged?.Invoke(m_Items[m_SelectedIndex].value); editorWindow.Close(); break; } }); editorWindow.rootVisualElement.RegisterCallback <KeyDownEvent>(evt => { searchField.Focus(); }); searchField.RegisterValueChangedCallback(OnSearchChanged); editorWindow.rootVisualElement.Add(searchField); m_ScrollView = new ScrollView(); m_ScrollView.RegisterCallback <GeometryChangedEvent, ScrollView>((evt, sv) => { if (m_SelectedIndex >= 0) { sv.ScrollTo(sv[m_SelectedIndex]); } }, m_ScrollView); var selectionWasSet = false; for (var i = 0; i < m_Items.Count; ++i) { var property = m_Items[i]; var element = GetPooledItem(property, i); m_ScrollView.Add(element); if (selectionWasSet) { continue; } if (property.itemType != ItemType.Item || property.value != m_CurrentActiveValue) { continue; } m_SelectedIndex = i; element.pseudoStates |= PseudoStates.Checked; selectionWasSet = true; } editorWindow.rootVisualElement.RegisterCallback <KeyDownEvent>(evt => { if (evt.keyCode == KeyCode.F && evt.actionKey) { searchField.Focus(); } }, TrickleDown.TrickleDown); editorWindow.rootVisualElement.Add(m_ScrollView); }
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); } }