void UpdateCategoryList() { if (m_CategoryListView == null) { return; } // Rebuild the category list m_CategoryListView.Clear(); foreach (var category in m_CategoryEntries) { var element = m_CategoryTemplate.CloneTree().Q(className: k_CategoryClass); var categoryLabel = element.Q <Label>(className: k_CategoryLabelClass); element.userData = category; categoryLabel.text = category.Name; element.RegisterCallback <PointerDownEvent>(CategoryButtonClicked); m_CategoryListView.Add(element); element.AddToClassList(category.Name); if (m_LastCategoryElement == null || m_SelectedFilter != null && m_SelectedFilter == category) { m_LastCategoryElement = element; } } // Reselect the last element so that it continues to be highlighted in the window if (m_LastCategoryElement != null) { m_LastCategoryElement.AddToClassList(k_SelectedClass); m_SelectedFilter = m_LastCategoryElement.userData as CategoryFilter; m_ApplyContentFilter?.Invoke(m_SelectedFilter); } }
/// <summary> /// Used to start drawing the Content Manager window. /// </summary> /// <param name="ve">The root element that all UI will be placed inside</param> /// <param name="onWindowSize">Action to call when the window is resized</param> /// <param name="onProductFilter">Action to call when a product is selected</param> /// <param name="onContentFilter">Action to call when a category button is activated</param> /// <param name="onContentInstall">Action to call when the install button is activated for a piece of content</param> /// <param name="onContentUpdate">Action to call when the update button is activated for a piece of content</param> /// <param name="onContentUninstall">Action to call when the uninstall button is activated</param> /// <param name="onContentCancel">Action to call when the cancel button is activated</param> /// <param name="onContentSelect">Action to call when content is selected</param> /// <param name="defaultPack">An optional content pack to start focused on</param> /// <param name="defaultFilter">An optional category to start focused on</param> /// <param name="defaultProduct">An optional product to start focused on</param> public void Init(VisualElement ve, Action <Vector2> onWindowSize, Action <ContentProduct> onProductFilter, Action <CategoryFilter> onContentFilter, Action <ContentPack> onContentInstall, Action <ContentPack> onContentUpdate, Action <ContentPack> onContentUninstall, Action <ContentPack> onContentCancel, Action <ContentPack> onContentSelect, ContentPack defaultPack = null, CategoryFilter defaultFilter = null, ContentProduct defaultProduct = null) { if (s_ProductDropDown == null) { s_ProductDropDown = new ProductDropDown(new AdvancedDropdownState()); } s_ProductDropDown.OnSelect = SetProductFull; m_RootVisualElement = ve; m_WindowResize = onWindowSize; m_ApplyProductFilter = onProductFilter; m_ApplyContentFilter = onContentFilter; m_InstallContentPack = onContentInstall; m_UpdateContentPack = onContentUpdate; m_UninstallContentPack = onContentUninstall; m_CancelContentPack = onContentCancel; m_SelectContentPack = onContentSelect; m_SelectedPack = defaultPack; m_SelectedFilter = defaultFilter; m_SelectedProduct = defaultProduct; SetupUI(); EditorApplication.update += UpdateSpinners; }
void OnContentFilterChanged(CategoryFilter filter) { if (m_ContentManagerDriver == null) { return; } m_ActiveFilter = filter; UpdateFilteredPacks(); }
/// <summary> /// Sets the active product and resets the selected Content Pack and filter. /// </summary> /// <param name="target"></param> void SetProductFull(ContentProduct target) { if (target != m_SelectedProduct) { m_SelectedPack = null; m_SelectedFilter = null; m_LastCategoryElement = null; } SetProduct(target); }
void CategoryButtonClicked(PointerDownEvent evt) { var clicked = evt.currentTarget as VisualElement; if (clicked == m_LastCategoryElement) { return; } m_LastCategoryElement?.RemoveFromClassList(k_SelectedClass); if (clicked == null) { return; } clicked.AddToClassList(k_SelectedClass); m_LastCategoryElement = clicked; m_SelectedFilter = clicked.userData as CategoryFilter; m_ApplyContentFilter?.Invoke(m_SelectedFilter); }