internal static void SelectPackageAndFilter(string packageIdOrDisplayName, PackageFilterTab?filterTab = null, bool refresh = false, string searchText = "") { instance = GetWindow <PackageManagerWindow>(typeof(SceneView)); instance.minSize = new Vector2(700, 250); if (!string.IsNullOrEmpty(packageIdOrDisplayName) || filterTab != null) { if (filterTab == null) { IPackageVersion version; IPackage package; PackageDatabase.instance.GetPackageAndVersionByIdOrName(packageIdOrDisplayName, out package, out version); filterTab = PageManager.instance.FindTab(package, version); } instance.m_FilterToSelectAfterLoad = filterTab; instance.m_PackageToSelectOnLoaded = packageIdOrDisplayName; instance.packageManagerToolbar.SetCurrentSearch(searchText); if (refresh || PackageDatabase.instance.isEmpty) { instance.DelayRefresh((PackageFilterTab)filterTab); } else { instance.SelectPackageAndFilter(); } } instance.Show(); }
internal static void SelectPackageAndFilter(string packageIdOrDisplayName, PackageFilterTab?filterTab = null, bool refresh = false, string searchText = "") { instance = GetWindow <PackageManagerWindow>(); instance.minSize = new Vector2(700, 250); if (!string.IsNullOrEmpty(packageIdOrDisplayName) || filterTab != null) { if (filterTab == null) { filterTab = PageManager.instance.FindTab(packageIdOrDisplayName); } instance.m_FilterToSelectAfterLoad = filterTab; instance.m_PackageToSelectOnLoaded = packageIdOrDisplayName; instance.packageManagerToolbar.SetCurrentSearch(searchText); if (refresh || PackageDatabase.instance.isEmpty) { PageManager.instance.Refresh(filterTab); } else { instance.SelectPackageAndFilter(); } } instance.Show(); }
private void SetupAddMenu() { AddMenu.menu.AppendAction("Add package from disk...", a => { var path = EditorUtility.OpenFilePanelWithFilters("Select package on disk", "", new[] { "package.json file", "json" }); if (!string.IsNullOrEmpty(path) && !Package.PackageOperationInProgress) { Package.AddFromLocalDisk(path); } }, a => DropdownMenuAction.Status.Normal); AddMenu.menu.AppendAction("Add package from git URL...", a => { var addFromGitUrl = new PackagesAction("Add"); addFromGitUrl.actionClicked += url => { addFromGitUrl.Hide(); if (!Package.PackageOperationInProgress) { Package.AddFromUrl(url); } }; parent.Add(addFromGitUrl); addFromGitUrl.Show(); }, a => DropdownMenuAction.Status.Normal); AddMenu.menu.AppendSeparator(""); AddMenu.menu.AppendAction("Create Package...", a => { var defaultName = PackageCreator.GenerateUniquePackageDisplayName("New Package"); var createPackage = new PackagesAction("Create", defaultName); createPackage.actionClicked += displayName => { createPackage.Hide(); var packagePath = PackageCreator.CreatePackage("Packages/" + displayName); AssetDatabase.Refresh(); EditorApplication.delayCall += () => { var path = Path.Combine(packagePath, "package.json"); var o = AssetDatabase.LoadMainAssetAtPath(path); if (o != null) { UnityEditor.Selection.activeObject = o; } PackageManagerWindow.SelectPackageAndFilter(displayName, PackageFilter.InDevelopment, true); }; }; parent.Add(createPackage); createPackage.Show(); }, a => DropdownMenuAction.Status.Normal); }
internal static void SelectPackageAndFilter(string packageIdOrDisplayName, PackageFilterTab?filterTab = null, bool refresh = false, string searchText = "") { s_Window = GetWindow <PackageManagerWindow>(); s_Window.minSize = new Vector2(700, 250); if (!string.IsNullOrEmpty(packageIdOrDisplayName)) { s_Window.packageManagerToolbar.SetCurrentSearch(searchText); s_Window.m_PackageToSelectOnLoaded = packageIdOrDisplayName; s_Window.m_FilterToSelectAfterLoad = filterTab; if (refresh) { PageManager.instance.Refresh(filterTab ?? PackageFilterTab.All); } else if (!PackageDatabase.instance.isEmpty) { s_Window.SelectPackageAndFilter(); } } s_Window.Show(); }
internal override void OnHeaderControlsGUI() { base.OnHeaderControlsGUI(); var previousEnabled = GUI.enabled; GUI.enabled = targets.Length == 1 && m_Package?.state == PackageState.InDevelopment && (m_Version?.isInstalled ?? false); if (GUILayout.Button(Styles.editPackage, EditorStyles.miniButton)) { var path = m_Version.packageInfo.assetPath; var manifest = AssetDatabase.LoadAssetAtPath <PackageManifest>($"{path}/package.json"); if (manifest != null) { Selection.activeObject = manifest; } } GUI.enabled = targets.Length == 1 && m_Package != null && m_Version != null; if (GUILayout.Button(Styles.viewInPackageManager, EditorStyles.miniButton)) { PackageManagerWindow.SelectPackageAndFilter(m_Version.uniqueId); } GUI.enabled = previousEnabled; }
private void RemoveClick() { var roots = PackageDatabase.instance.GetDependentVersions(displayVersion).Where(p => p.isDirectDependency && p.isInstalled).ToList(); // Only show this message on a package if it is installed by dependency only. This allows it to still be removed from the installed list. var showDialog = roots.Any() && !(!displayVersion.HasTag(PackageTag.BuiltIn) && displayVersion.isDirectDependency); if (showDialog) { if (roots.Count > MaxDependentList) { Debug.Log(GetDependentMessage(displayVersion, roots, int.MaxValue)); } var message = GetDependentMessage(displayVersion, roots); var title = displayVersion.HasTag(PackageTag.BuiltIn) ? "Cannot disable built-in package" : "Cannot remove dependent package"; EditorUtility.DisplayDialog(title, message, "Ok"); return; } if (displayVersion.HasTag(PackageTag.InDevelopment)) { if (!EditorUtility.DisplayDialog("Unity Package Manager", "You will loose all your changes (if any) if you delete a package in development. Are you sure?", "Yes", "No")) { return; } detailError.ClearError(); PackageDatabase.instance.RemoveEmbedded(package); RefreshPackageActionButtons(); EditorApplication.delayCall += () => { PackageFilterTab?newFilterTab = null; if (PackageFiltering.instance.currentFilterTab == PackageFilterTab.InDevelopment) { var hasOtherInDevelopment = PackageDatabase.instance.allPackages.Any(p => { var installed = p.installedVersion; return(installed != null && installed.HasTag(PackageTag.InDevelopment) && p.uniqueId != package.uniqueId); }); newFilterTab = hasOtherInDevelopment ? PackageFilterTab.InDevelopment : PackageFilterTab.Local; } PackageManagerWindow.SelectPackageAndFilter(displayVersion.uniqueId, newFilterTab, true); }; return; } var result = 0; if (displayVersion.HasTag(PackageTag.BuiltIn)) { if (!PackageManagerPrefs.instance.skipDisableConfirmation) { result = EditorUtility.DisplayDialogComplex("Disable Built-In Package", "Are you sure you want to disable this built-in package?", "Disable", "Cancel", "Never ask"); } } else { if (!PackageManagerPrefs.instance.skipRemoveConfirmation) { result = EditorUtility.DisplayDialogComplex("Removing Package", "Are you sure you want to remove this package?", "Remove", "Cancel", "Never ask"); } } // Cancel if (result == 1) { return; } // Do not ask again if (result == 2) { if (displayVersion.HasTag(PackageTag.BuiltIn)) { PackageManagerPrefs.instance.skipDisableConfirmation = true; } else { PackageManagerPrefs.instance.skipRemoveConfirmation = true; } } // Remove detailError.ClearError(); PackageDatabase.instance.Uninstall(package); RefreshPackageActionButtons(); }
private void SetupAddMenu() { addMenu.menu.AppendAction("Add package from disk...", a => { var path = EditorUtility.OpenFilePanelWithFilters("Select package on disk", "", new[] { "package.json file", "json" }); if (Path.GetFileName(path) != "package.json") { Debug.Log("Please select a valid package.json file in a package folder."); return; } if (!string.IsNullOrEmpty(path) && !PackageDatabase.instance.isInstallOrUninstallInProgress) { PackageDatabase.instance.InstallFromPath(Path.GetDirectoryName(path)); PackageManagerWindowAnalytics.SendEvent("addFromDisk"); } }, a => DropdownMenuAction.Status.Normal); addMenu.menu.AppendAction("Add package from tarball...", a => { var path = EditorUtility.OpenFilePanelWithFilters("Select package on disk", "", new[] { "Package tarball", "tgz" }); if (!string.IsNullOrEmpty(path) && !PackageDatabase.instance.isInstallOrUninstallInProgress) { PackageDatabase.instance.InstallFromPath(path); PackageManagerWindowAnalytics.SendEvent("addFromTarball"); } }, a => DropdownMenuAction.Status.Normal); addMenu.menu.AppendAction("Add package from git URL...", a => { var addFromGitUrl = new PackagesAction("Add"); addFromGitUrl.actionClicked += url => { addFromGitUrl.Hide(); if (!PackageDatabase.instance.isInstallOrUninstallInProgress) { PackageDatabase.instance.InstallFromUrl(url); PackageManagerWindowAnalytics.SendEvent("addFromGitUrl"); } }; parent.Add(addFromGitUrl); addFromGitUrl.Show(); }, a => DropdownMenuAction.Status.Normal); addMenu.menu.AppendSeparator(""); addMenu.menu.AppendAction("Create Package...", a => { var defaultName = PackageCreator.GenerateUniquePackageDisplayName("New Package"); var createPackage = new PackagesAction("Create", defaultName); createPackage.actionClicked += displayName => { createPackage.Hide(); var packagePath = PackageCreator.CreatePackage("Packages/" + displayName); PackageManagerWindowAnalytics.SendEvent("createPackage"); AssetDatabase.Refresh(); EditorApplication.delayCall += () => { var path = Path.Combine(packagePath, "package.json"); var o = AssetDatabase.LoadMainAssetAtPath(path); if (o != null) { UnityEditor.Selection.activeObject = o; } PackageManagerWindow.SelectPackageAndFilter(displayName, PackageFilterTab.InDevelopment, true); }; }; parent.Add(createPackage); createPackage.Show(); }, a => DropdownMenuAction.Status.Normal); PackageManagerExtensions.ExtensionCallback(() => { foreach (var extension in PackageManagerExtensions.MenuExtensions) { extension.OnAddMenuCreate(addMenu.menu); } }); }
private void RemoveClick() { if (DisplayPackage.IsBuiltIn) { var roots = Collection.GetDependents(DisplayPackage).ToList(); if (roots.Any()) { if (roots.Count > MaxDependentList) { Debug.Log(GetDependentMessage(roots, int.MaxValue)); } var message = GetDependentMessage(roots); EditorUtility.DisplayDialog("Cannot Disable Built-In Package", message, "Ok"); return; } } if (DisplayPackage.IsInDevelopment) { if (!EditorUtility.DisplayDialog("Unity Package Manager", "You will loose all your changes (if any) if you delete a package in development. Are you sure?", "Yes", "No")) { return; } RefreshRemoveButton(); RefreshAddButton(); Directory.Delete(DisplayPackage.Info.resolvedPath, true); AssetDatabase.Refresh(); EditorApplication.delayCall += () => { if (Collection.Filter == PackageFilter.InDevelopment) { var otherInDev = Collection.listPackages.Any(info => info.IsInDevelopment && info.Name != package.Name); PackageManagerWindow.SelectPackageAndFilter(DisplayPackage.VersionId, otherInDev ? PackageFilter.InDevelopment : PackageFilter.Local, true); } else { PackageManagerWindow.SelectPackageAndFilter(DisplayPackage.VersionId, null, true); } }; return; } var result = 0; if (DisplayPackage.IsBuiltIn) { if (!PackageManagerPrefs.SkipDisableConfirmation) { result = EditorUtility.DisplayDialogComplex("Disable Built-In Package", "Are you sure you want to disable this built-in package?", "Disable", "Cancel", "Never ask"); } } else { if (!PackageManagerPrefs.SkipRemoveConfirmation) { result = EditorUtility.DisplayDialogComplex("Removing Package", "Are you sure you want to remove this package?", "Remove", "Cancel", "Never ask"); } } // Cancel if (result == 1) { return; } // Do not ask again if (result == 2) { if (DisplayPackage.IsBuiltIn) { PackageManagerPrefs.SkipDisableConfirmation = true; } else { PackageManagerPrefs.SkipRemoveConfirmation = true; } } // Remove DetailError.ClearError(); package.Remove(); RefreshRemoveButton(); RefreshAddButton(); }
internal static void SelectPackageAndFilterStatic(string packageIdOrDisplayName, PackageFilterTab?filterTab = null, bool refresh = false, string searchText = "") { instance = GetWindow <PackageManagerWindow>(typeof(SceneView)); instance.minSize = new Vector2(800, 250); instance.SelectPackageAndFilter(packageIdOrDisplayName, filterTab, refresh, searchText); }