public void SelectPackageAndFilter(string packageToSelect, PackageFilterTab?filterTab = null, bool refresh = false, string searchText = "") { if (!string.IsNullOrEmpty(packageToSelect) || filterTab != null) { if (filterTab == null) { m_PackageDatabase.GetPackageAndVersionByIdOrName(packageToSelect, out var package, out var version); if (package != null) { filterTab = m_PageManager.FindTab(package, version); } else { var packageToSelectSplit = packageToSelect.Split('@'); var versionString = packageToSelectSplit.Length == 2 ? packageToSelectSplit[1] : string.Empty; // Package is not found in PackageDatabase but we can determine if it's a preview package or not with it's version string. SemVersionParser.TryParse(versionString, out var semVersion); if (!m_SettingsProxy.enablePreReleasePackages && semVersion.HasValue && (semVersion.Value.Major == 0 || semVersion.Value.Prerelease.StartsWith("preview"))) { Debug.Log("You must check \"Enable Preview Packages\" in Project Settings > Package Manager in order to see this package."); filterTab = m_PackageFiltering.currentFilterTab; packageToSelect = null; } else { filterTab = PackageFilterTab.UnityRegistry; } } } m_FilterToSelectAfterLoad = filterTab; m_PackageToSelectOnLoaded = packageToSelect; packageManagerToolbar.SetCurrentSearch(searchText); if (refresh || m_PackageDatabase.isEmpty) { DelayRefresh((PackageFilterTab)filterTab); } else { SelectPackageAndFilter(); } } }
private void InstallByNameAndVersion(string packageName, string packageVersion = null) { var packageId = string.IsNullOrEmpty(packageVersion) ? packageName : $"{packageName}@{packageVersion}"; m_UpmClient.AddById(packageId); PackageManagerWindowAnalytics.SendEvent("addByNameAndVersion", packageId); Close(); var package = m_PackageDatabase.GetPackage(packageName); if (package != null) { m_PackageFiltering.currentFilterTab = m_PageManager.FindTab(package); m_PageManager.SetSelected(package, package.versions?.FirstOrDefault(v => v.versionString == packageVersion)); } }