Ejemplo n.º 1
0
        private void SelectPackageAndFilter()
        {
            IPackageVersion version = null;
            IPackage        package = null;

            if (!string.IsNullOrEmpty(m_PackageToSelectOnLoaded))
            {
                m_PackageDatabase.GetPackageAndVersionByIdOrName(m_PackageToSelectOnLoaded, out package, out version);
            }

            if (m_FilterToSelectAfterLoad == PackageFilterTab.AssetStore)
            {
                m_PackageFiltering.currentFilterTab = PackageFilterTab.AssetStore;

                if (!string.IsNullOrEmpty(m_PackageToSelectOnLoaded))
                {
                    if (package == null || package is PlaceholderPackage)
                    {
                        m_PageManager.Fetch(m_PackageToSelectOnLoaded);
                    }
                    else
                    {
                        m_PageManager.GetPage(PackageFilterTab.AssetStore).Load(package, version);
                    }
                }

                m_FilterToSelectAfterLoad  = null;
                m_PackageToSelectOnLoaded  = null;
                m_SubPageToSelectAfterLoad = null;
                return;
            }

            // The !IsInitialFetchingDone check was added to the start of this function in the past for the Entitlement Error checker,
            // But it caused `Open In Unity` to not work sometimes for the `My Assets` tab. Hence we moved the check from the beginning
            // of this function to after the `My Assets` logic is done so that we don't break `My Assets` and the Entitlement Error checker.
            if (!m_PageManager.IsInitialFetchingDone())
            {
                return;
            }

            if (package != null || m_FilterToSelectAfterLoad != null)
            {
                var tab = m_FilterToSelectAfterLoad ?? PackageFiltering.k_DefaultFilterTab;

                if (m_SubPageToSelectAfterLoad != null)
                {
                    void SelectSubPage(IPage page, string subPageName)
                    {
                        var subPage = page.subPages.FirstOrDefault(page => string.Compare(page.name, subPageName, StringComparison.InvariantCultureIgnoreCase) == 0) ?? page.subPages.First();

                        page.currentSubPage = subPage;
                    }

                    void OnFilterTabChangedSelectSubPage(PackageFilterTab filterTab)
                    {
                        m_PackageFiltering.onFilterTabChanged -= OnFilterTabChangedSelectSubPage;
                        SelectSubPage(m_PageManager.GetCurrentPage(), m_SubPageToSelectAfterLoad);
                    }

                    if (m_PackageFiltering.currentFilterTab == tab)
                    {
                        SelectSubPage(m_PageManager.GetCurrentPage(), m_SubPageToSelectAfterLoad);
                    }
                    else
                    {
                        m_PackageFiltering.onFilterTabChanged += OnFilterTabChangedSelectSubPage;
                    }

                    m_PackageToSelectOnLoaded = null;
                }

                m_PackageFiltering.currentFilterTab = tab;
                if (!string.IsNullOrEmpty(m_PackageToSelectOnLoaded))
                {
                    m_PageManager.SetSelected(package, version, true);
                    packageList.OnFocus();
                }

                m_FilterToSelectAfterLoad  = null;
                m_PackageToSelectOnLoaded  = null;
                m_SubPageToSelectAfterLoad = null;
            }
        }