using System; using System.Collections.Generic; using System.Linq; using Semver; using UnityEngine; using UnityEngine.Networking; using UnityEngine.Experimental.UIElements; namespace UnityEditor.PackageManager.UI { #if !UNITY_2018_3_OR_NEWER internal class PackageDetailsFactory : UxmlFactory { protected override PackageDetails DoCreate(IUxmlAttributes bag, CreationContext cc) { return new PackageDetails(); } } #endif internal class PackageDetails : VisualElement { #if UNITY_2018_3_OR_NEWER internal new class UxmlFactory : UxmlFactory {} #endif private readonly VisualElement root; private Package package; private const string emptyDescriptionClass = "empty"; private List VersionItems; internal PopupField VersionPopup; private PackageInfo DisplayPackage; private PackageInfo SelectedPackage { get { return VersionPopup.value.Version != null ? VersionPopup.value.Version : null; } } internal enum PackageAction { Add, Remove, Update, Downgrade, Enable, Disable, UpToDate, Current, Local, Git, Embedded } private static readonly VersionItem EmptyVersion = new VersionItem {Version = null}; internal static readonly string[] PackageActionVerbs = { "Install", "Remove", "Update to", "Update to", "Enable", "Disable", "Up to date", "Current", "Local", "Git", "Embedded" }; internal static readonly string[] PackageActionInProgressVerbs = { "Installing", "Removing", "Updating to", "Updating to", "Enabling", "Disabling", "Up to date", "Current", "Local", "Git", "Embedded" }; public PackageDetails() { UIUtils.SetElementDisplay(this, false); root = Resources.GetTemplate("PackageDetails.uxml"); Add(root); foreach (var extension in PackageManagerExtensions.Extensions) CustomContainer.Add(extension.CreateExtensionUI()); root.StretchToParentSize(); SetUpdateVisibility(false); RemoveButton.visible = false; UpdateBuiltIn.visible = false; UpdateButton.clickable.clicked += UpdateClick; UpdateBuiltIn.clickable.clicked += UpdateClick; RemoveButton.clickable.clicked += RemoveClick; ViewDocButton.clickable.clicked += ViewDocClick; ViewChangelogButton.clickable.clicked += ViewChangelogClick; ViewLicenses.clickable.clicked += ViewLicensesClick; VersionItems = new List {EmptyVersion}; VersionPopup = new PopupField(VersionItems, 0); VersionPopup.SetLabelCallback(VersionSelectionSetLabel); VersionPopup.AddToClassList("popup"); VersionPopup.OnValueChanged(VersionSelectionChanged); if (VersionItems.Count == 1) VersionPopup.SetEnabled(false); UpdateDropdownContainer.Add(VersionPopup); VersionPopup.StretchToParentSize(); // Fix button on dark skin but overlapping edge pixel perfectly if (EditorGUIUtility.isProSkin) { VersionPopup.style.positionLeft = -1; UpdateDropdownContainer.style.sliceLeft = 4; } // We add a null check to avoid the null exception error when updating Package Manager UI to the new version if (DetailWarningLink != null) DetailWarningLink.clickable.clicked += () => Application.OpenURL("https://docs.unity3d.com/Manual/upm-scoped.html"); } private string VersionSelectionSetLabel(VersionItem item) { return item.Label; } private void VersionSelectionChanged(ChangeEvent e) { RefreshAddButton(); } private void SetUpdateVisibility(bool value) { if (UpdateContainer != null) UIUtils.SetElementDisplay(UpdateContainer, value); } internal void SetDisplayPackage(PackageInfo packageInfo) { DisplayPackage = packageInfo; var detailVisible = true; Error error = null; if (package == null || DisplayPackage == null) { detailVisible = false; UIUtils.SetElementDisplay(DocumentationContainer, false); UIUtils.SetElementDisplay(CustomContainer, false); UIUtils.SetElementDisplay(UpdateBuiltIn, false); foreach (var extension in PackageManagerExtensions.Extensions) extension.OnPackageSelectionChange(null); } else { SetUpdateVisibility(true); UIUtils.SetElementDisplay(ViewDocButton, true); RemoveButton.visible = true; if (string.IsNullOrEmpty(DisplayPackage.Description)) { DetailDesc.text = "There is no description for this package."; DetailDesc.AddToClassList(emptyDescriptionClass); } else { DetailDesc.text = DisplayPackage.Description; DetailDesc.RemoveFromClassList(emptyDescriptionClass); } DetailTitle.text = DisplayPackage.DisplayName; DetailVersion.text = "Version " + DisplayPackage.VersionWithoutTag; if (DisplayPackage.IsInDevelopment || DisplayPackage.HasVersionTag(PackageTag.preview)) UIUtils.SetElementDisplay(GetTag(PackageTag.verified), false); else { var unityVersionParts = Application.unityVersion.Split('.'); var unityVersion = string.Format("{0}.{1}", unityVersionParts[0], unityVersionParts[1]); VerifyLabel.text = unityVersion + " verified"; UIUtils.SetElementDisplay(GetTag(PackageTag.verified), DisplayPackage.IsVerified); } UIUtils.SetElementDisplay(GetTag(PackageTag.inDevelopment), DisplayPackage.IsInDevelopment); UIUtils.SetElementDisplay(GetTag(PackageTag.local), DisplayPackage.IsLocal); UIUtils.SetElementDisplay(GetTag(PackageTag.preview), DisplayPackage.IsPreview); UIUtils.SetElementDisplay(DocumentationContainer, DisplayPackage.Origin != PackageSource.BuiltIn); UIUtils.SetElementDisplay(ChangelogContainer, DisplayPackage.HasChangelog(DisplayPackage)); root.Q