void OnEnable() { m_TransactionManager = new ReadOnlyTransactionManager(); m_TransactionAssetField = new ObjectField("Transaction Database"); m_TransactionAssetField.objectType = typeof(DefaultAsset); m_TransactionAssetField.RegisterValueChangedCallback(evt => { var assetPath = AssetDatabase.GetAssetPath(evt.newValue); LoadDatabase(assetPath, TimeRange.All(), true); }); rootVisualElement.Add(m_TransactionAssetField); m_TransactionListView = new UnityEngine.UIElements.ListView(); m_TransactionListView.itemsSource = Transactions; #if !USE_SEARCH_MODULE m_TransactionListView.itemHeight = k_TransactionRowHeight; #else m_TransactionListView.fixedItemHeight = k_TransactionRowHeight; #endif m_TransactionListView.makeItem = MakeRowItem; m_TransactionListView.bindItem = BindRowItem; m_TransactionListView.style.flexGrow = 1.0f; rootVisualElement.Add(m_TransactionListView); }
void UpdateListView(UnityEngine.UIElements.ListView listViewElement, TimeRange timeRange) { if (m_TransactionManager.Initialized) { var transactions = m_TransactionManager.Read(timeRange); Transactions.AddRange(transactions); } EditorApplication.delayCall += listViewElement.Rebuild; }
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); }
void UpdateListView(UnityEngine.UIElements.ListView listViewElement, TimeRange timeRange) { if (m_TransactionManager.Initialized) { var transactions = m_TransactionManager.Read(timeRange); Transactions.AddRange(transactions); } #if USE_SEARCH_MODULE EditorApplication.delayCall += listViewElement.Rebuild; #else EditorApplication.delayCall += listViewElement.Refresh; #endif }
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); } }