void OnContentSelect(ContentPack selectedPack) { m_ActivePack = selectedPack; }
void UpdateContentList() { if (m_EntryListView == null) { return; } m_LoadingSpinners.Clear(); m_EntryListView.Clear(); if (m_SelectedPack == null && m_ContentPacks.Count > 0) { m_SelectedPack = m_ContentPacks[0]; UpdateContentDetail(); } // Create a selection button for each piece of visible content // Update the data inside // Configure actions to highlight a clicked piece of content in the detail pane foreach (var currentContent in m_ContentPacks) { var element = m_EntryTemplate.CloneTree().Q(className: k_EntryClass); var elementThumbnail = element.Q <VisualElement>(className: k_EntryThumbnailClass); var elementLabel = element.Q <Label>(className: k_EntryLabelClass); var elementCat = element.Q <Label>(className: k_EntryCatClass); element.userData = currentContent; elementLabel.text = DisplayNameString(currentContent); elementCat.text = char.ToUpper(currentContent.Category[0]) + currentContent.Category.Substring(1); element.RegisterCallback <PointerDownEvent>(ContentPackButtonClicked); if (currentContent.InstallStatus.HasFlag(InstallationStatus.Installed)) { element.AddToClassList(k_DownloadedClass); } else { element.RemoveFromClassList(k_DownloadedClass); } if (currentContent.InstallStatus.HasFlag(InstallationStatus.UpdateAvailable)) { element.AddToClassList(k_UpdateClass); } else { element.RemoveFromClassList(k_UpdateClass); } if (currentContent.InstallStatus.HasFlag(InstallationStatus.Locked) | currentContent.InstallStatus.HasFlag(InstallationStatus.InstallQueued) | currentContent.InstallStatus.HasFlag(InstallationStatus.UninstallQueued)) { element.AddToClassList(k_PendingClass); var elementIndicator = element.Q <VisualElement>(className: k_EntryDownloadIndicator); m_LoadingSpinners.Add(elementIndicator.transform); } else { element.RemoveFromClassList(k_PendingClass); } if (m_SelectedPack != null && currentContent == m_SelectedPack) { m_LastEntryElement = element; element.AddToClassList(k_SelectedClass); } var elementThumbnailStyle = elementThumbnail.style; elementThumbnailStyle.backgroundImage = currentContent.PreviewImage; m_EntryListView.Add(element); } }
static string DisplayNameString(ContentPack targetContent) { return(targetContent.Preview ? $"{targetContent.DisplayName} ({targetContent.PreviewLabel})" : targetContent.DisplayName); }
/// <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; }