コード例 #1
0
        public void Refresh(IPackage package, IPackageVersion version)
        {
            m_Package = package;
            m_Version = version;
            Clear();

            if (package == null || version == null)
            {
                return;
            }

            var leftItems = new VisualElement {
                classList = { "left" }
            };

            Add(leftItems);

            // add links from the package
            foreach (var link in package.links)
            {
                if (string.IsNullOrEmpty(link.name) || string.IsNullOrEmpty(link.url))
                {
                    continue;
                }
                AddToLinks(leftItems, new Button(() => { m_Application.OpenURL(link.url); })
                {
                    text      = link.name,
                    tooltip   = link.url,
                    classList = { k_LinkClass }
                }, package.links.First() != link);
            }

            // add links related to the upm version
            if (UpmPackageDocs.HasDocs(version))
            {
                AddToLinks(leftItems, new Button(ViewDocClick)
                {
                    text = k_ViewDocumentationText, classList = { k_LinkClass }
                }, false);
            }

            if (UpmPackageDocs.HasChangelog(version))
            {
                AddToLinks(leftItems, new Button(ViewChangelogClick)
                {
                    text = k_ViewChangelogText, classList = { k_LinkClass }
                });
            }

            if (UpmPackageDocs.HasLicenses(version))
            {
                AddToLinks(leftItems, new Button(ViewLicensesClick)
                {
                    text = k_ViewLicensesText, classList = { k_LinkClass }
                });
            }

            if (UpmPackageDocs.HasUseCases(version))
            {
                AddToLinks(leftItems, new Button(ViewUseCasesClick)
                {
                    text = k_ViewUseCasesText, classList = { k_LinkClass }
                });
            }

            if (UpmPackageDocs.HasDashboard(version))
            {
                AddToLinks(leftItems, new Button(ViewDashboardClick)
                {
                    text = k_ViewDashboardText, classList = { k_LinkClass }
                });
            }

            var topOffset = false;

            if (package.Is(PackageType.Feature) && !string.IsNullOrEmpty(GetQuickStartUrl(m_Version)))
            {
                var quickStartButton = new Button(ViewQuickStartClick)
                {
                    name = "quickStart", classList = { "quickStartButton", "right" }
                };
                quickStartButton.Add(new VisualElement {
                    classList = { "quickStartIcon" }
                });
                quickStartButton.Add(new TextElement {
                    text = k_ViewQuickStartText, classList = { "quickStartText" }
                });

                Add(quickStartButton);

                topOffset = leftItems.childCount == 0;
            }
            // Offset the links container to the top when there are no links and only quick start button visible
            EnableInClassList("topOffset", topOffset);
            UIUtils.SetElementDisplay(this, childCount != 0);
        }