예제 #1
0
        private void ImportClick()
        {
            PackageDatabase.instance.Import(package);
            RefreshImportAndDownloadButtons();

            PackageManagerWindowAnalytics.SendEvent("import", package.uniqueId);
        }
예제 #2
0
        private void DownloadOrCancelClick()
        {
            var downloadInProgress = PackageDatabase.instance.IsDownloadInProgress(displayVersion);

            if (!downloadInProgress && !ApplicationUtil.instance.isInternetReachable)
            {
                detailError.SetError(new UIError(UIErrorCode.NetworkError, ApplicationUtil.instance.GetTranslationForText("No internet connection")));
                return;
            }

            detailError.ClearError();
            if (downloadInProgress)
            {
                PackageDatabase.instance.AbortDownload(package);
            }
            else
            {
                PackageDatabase.instance.Download(package);
            }

            RefreshImportAndDownloadButtons();

            var eventName = downloadInProgress ? "abortDownload" : "startDownload";

            PackageManagerWindowAnalytics.SendEvent(eventName, package.uniqueId);
        }
예제 #3
0
        internal static void OpenPackageManager(string packageNameOrDisplayName)
        {
            var windows = UnityEngine.Resources.FindObjectsOfTypeAll <PackageManagerWindow>();
            var isWindowAlreadyVisible = windows != null;

            if (!isWindowAlreadyVisible)
            {
                string packageId = null;
                if (!string.IsNullOrEmpty(packageNameOrDisplayName))
                {
                    var packageUniqueId = packageNameOrDisplayName.Split('@')[0];

                    IPackageVersion version;
                    IPackage        package;
                    PackageDatabase.instance.GetPackageAndVersion(packageUniqueId, packageNameOrDisplayName, out package, out version);
                    if (package == null)
                    {
                        package = PackageDatabase.instance.GetPackage(packageNameOrDisplayName) ?? PackageDatabase.instance.GetPackageByDisplayName(packageNameOrDisplayName);
                    }

                    packageId = version?.uniqueId ?? package?.versions.primary.uniqueId ?? $"{packageNameOrDisplayName}@primary";
                }
                PackageManagerWindowAnalytics.SendEvent("openWindow", packageId);
            }

            SelectPackageAndFilter(packageNameOrDisplayName);
        }
        private void SetupAdvancedMenu()
        {
            advancedMenu.menu.AppendAction("Reset Packages to defaults", a =>
            {
                EditorApplication.ExecuteMenuItem(ApplicationUtil.k_ResetPackagesMenuPath);
                PageManager.instance.Refresh(RefreshOptions.UpmListOffline);
                PackageManagerWindowAnalytics.SendEvent("resetToDefaults");
            }, a => DropdownMenuAction.Status.Normal);

            advancedMenu.menu.AppendAction("Show dependencies", a =>
            {
                ToggleDependencies();
                PackageManagerWindowAnalytics.SendEvent("toggleDependencies");
            }, a => PackageManagerPrefs.instance.showPackageDependencies ? DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal);

            advancedMenu.menu.AppendAction("Show preview packages", a =>
            {
                TogglePreviewPackages();
                PackageManagerWindowAnalytics.SendEvent("togglePreview");
            }, a => PackageManagerPrefs.instance.showPreviewPackages ? DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal);

            PackageManagerExtensions.ExtensionCallback(() =>
            {
                foreach (var extension in PackageManagerExtensions.MenuExtensions)
                {
                    extension.OnAdvancedMenuCreate(advancedMenu.menu);
                }
            });
        }
예제 #5
0
        private void DevelopClick()
        {
            detailError.ClearError();
            PackageDatabase.instance.Embed(package);
            RefreshPackageActionButtons();

            PackageManagerWindowAnalytics.SendEvent("embed", displayVersion?.uniqueId);
        }
        internal static void OpenPackageManagerOnFilter(string filterAndSubPageToSelect)
        {
            var isWindowAlreadyVisible = Resources.FindObjectsOfTypeAll <PackageManagerWindow>()?.FirstOrDefault() != null;

            SelectFilterSubPageStatic(filterAndSubPageToSelect);
            if (!isWindowAlreadyVisible)
            {
                PackageManagerWindowAnalytics.SendEvent("openWindowOnFilter", filterAndSubPageToSelect);
            }
        }
예제 #7
0
        private void UpdateClick()
        {
            detailError.ClearError();
            PackageDatabase.instance.Install(targetVersion);
            RefreshPackageActionButtons();

            var eventName = package.installedVersion == null ? "installNew" : "installUpdate";

            PackageManagerWindowAnalytics.SendEvent(eventName, displayVersion?.uniqueId);
        }
        private void SetFilterFromMenu(PackageFilterTab filter)
        {
            if (filter == m_PackageFiltering.currentFilterTab)
            {
                return;
            }

            SetCurrentSearch(string.Empty);
            SetFilter(filter);
            PackageManagerWindowAnalytics.SendEvent("changeFilter");
        }
        private void OnImportButtonClicked()
        {
            var previousImports     = m_Sample.previousImports;
            var previousImportPaths = string.Empty;

            foreach (var v in previousImports)
            {
                previousImportPaths += v.Replace(Application.dataPath, "Assets") + "\n";
            }

            var warningMessage = string.Empty;

            if (previousImports.Count > 1)
            {
                warningMessage = ApplicationUtil.instance.GetTranslationForText("Different versions of the sample are already imported at") + "\n\n"
                                 + previousImportPaths + "\n" + ApplicationUtil.instance.GetTranslationForText("They will be deleted when you update.");
            }
            else if (previousImports.Count == 1)
            {
                if (m_Sample.isImported)
                {
                    warningMessage = ApplicationUtil.instance.GetTranslationForText("The sample is already imported at") + "\n\n"
                                     + previousImportPaths + "\n" + ApplicationUtil.instance.GetTranslationForText("Importing again will override all changes you have made to it.");
                }
                else
                {
                    warningMessage = ApplicationUtil.instance.GetTranslationForText("A different version of the sample is already imported at") + "\n\n"
                                     + previousImportPaths + "\n" + ApplicationUtil.instance.GetTranslationForText("It will be deleted when you update.");
                }
            }

            if (!string.IsNullOrEmpty(warningMessage) &&
                EditorUtility.DisplayDialog(ApplicationUtil.instance.GetTranslationForText("Unity Package Manager"),
                                            warningMessage + ApplicationUtil.instance.GetTranslationForText(" Are you sure you want to continue?"),
                                            ApplicationUtil.instance.GetTranslationForText("No"), ApplicationUtil.instance.GetTranslationForText("Yes")))
            {
                return;
            }

            PackageManagerWindowAnalytics.SendEvent("importSample", m_Version.uniqueId);

            if (m_Sample.Import(Sample.ImportOptions.OverridePreviousImports))
            {
                RefreshImportStatus();
                if (m_Sample.isImported)
                {
                    // Highlight import path
                    var    importRelativePath = m_Sample.importPath.Replace(Application.dataPath, "Assets");
                    Object obj = AssetDatabase.LoadAssetAtPath(importRelativePath, typeof(Object));
                    Selection.activeObject = obj;
                    EditorGUIUtility.PingObject(obj);
                }
            }
        }
 private void DelayedSearchEvent()
 {
     if (DateTime.Now.Ticks - m_SearchTextChangeTimestamp > k_SearchEventDelayTicks)
     {
         EditorApplication.update -= DelayedSearchEvent;
         PackageFiltering.instance.currentSearchText = searchToolbar.value;
         if (!string.IsNullOrEmpty(searchToolbar.value))
         {
             PackageManagerWindowAnalytics.SendEvent("search");
         }
     }
 }
        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);

            PackageManagerExtensions.ExtensionCallback(() =>
            {
                foreach (var extension in PackageManagerExtensions.MenuExtensions)
                {
                    extension.OnAddMenuCreate(addMenu.menu);
                }
            });
        }
예제 #12
0
        private void DelayedSearchEvent()
        {
            if (DateTime.Now.Ticks - m_SearchTextChangeTimestamp > k_SearchEventDelayTicks)
            {
                if (string.IsNullOrEmpty(searchToolbar.value))
                {
                    return;
                }
                EditorApplication.update -= DelayedSearchEvent;

                PackageManagerWindowAnalytics.SendEvent("search");
            }
        }
        internal static void OpenPackageManager(string packageNameOrDisplayName)
        {
            var windows = UnityEngine.Resources.FindObjectsOfTypeAll <PackageManagerWindow>();
            var isWindowAlreadyVisible = windows != null;

            if (!isWindowAlreadyVisible)
            {
                string packageId = null;
                if (!string.IsNullOrEmpty(packageNameOrDisplayName))
                {
                    var package = PackageDatabase.instance.GetPackage(packageNameOrDisplayName)
                                  ?? PackageDatabase.instance.GetPackageByDisplayName(packageNameOrDisplayName);
                    packageId = package?.primaryVersion.uniqueId ?? $"{packageNameOrDisplayName}@primary";
                }
                PackageManagerWindowAnalytics.SendEvent("openWindow", packageId);
            }

            SelectPackageAndFilter(packageNameOrDisplayName);
        }
예제 #14
0
        internal static void OpenPackageManager(string packageNameOrDisplayName)
        {
            var window = GetWindowDontShow <PackageManagerWindow>();
            var isWindowAlreadyVisible = window != null && window.m_Parent != null;

            SelectPackageAndFilter(packageNameOrDisplayName);

            if (!isWindowAlreadyVisible)
            {
                string packageId = null;
                if (!string.IsNullOrEmpty(packageNameOrDisplayName))
                {
                    var package = PackageDatabase.instance.GetPackage(packageNameOrDisplayName)
                                  ?? PackageDatabase.instance.GetPackageByDisplayName(packageNameOrDisplayName);
                    packageId = package?.primaryVersion.uniqueId ?? $"{packageNameOrDisplayName}@primary";
                }
                PackageManagerWindowAnalytics.SendEvent("openWindow", packageId);
            }
        }
예제 #15
0
        private void UpdateClick()
        {
            // dissuade users from updating by showing a warning message
            if (package.versions.installed != null && !package.versions.installed.isDirectDependency && package.versions.installed != targetVersion)
            {
                var message = ApplicationUtil.instance.GetTranslationForText("This version of the package is being used by other packages. Upgrading a different version might break your project. Are you sure you want to continue?");
                if (!EditorUtility.DisplayDialog(ApplicationUtil.instance.GetTranslationForText("Unity Package Manager"), message, ApplicationUtil.instance.GetTranslationForText("Yes"), ApplicationUtil.instance.GetTranslationForText("No")))
                {
                    return;
                }
            }

            detailError.ClearError();
            PackageDatabase.instance.Install(targetVersion);
            RefreshPackageActionButtons();

            var eventName = package.versions.installed == null ? "installNew" : "installUpdate";

            PackageManagerWindowAnalytics.SendEvent(eventName, displayVersion?.uniqueId);
        }
        internal static void OpenPackageManager(string packageToSelect)
        {
            var isWindowAlreadyVisible = Resources.FindObjectsOfTypeAll <PackageManagerWindow>()?.FirstOrDefault() != null;

            SelectPackageAndFilterStatic(packageToSelect);
            if (!isWindowAlreadyVisible)
            {
                string packageId = null;
                if (!string.IsNullOrEmpty(packageToSelect))
                {
                    var packageDatabase = ServicesContainer.instance.Resolve <Internal.PackageDatabase>();
                    Internal.IPackageVersion version;
                    Internal.IPackage        package;
                    packageDatabase.GetPackageAndVersionByIdOrName(packageToSelect, out package, out version);

                    packageId = version?.uniqueId ?? package?.versions.primary.uniqueId ?? string.Format("{0}@primary", packageToSelect);
                }
                PackageManagerWindowAnalytics.SendEvent("openWindow", packageId);
            }
        }
예제 #17
0
        internal static void OpenPackageManager(string packageNameOrDisplayName)
        {
            var window = UnityEngine.Resources.FindObjectsOfTypeAll <PackageManagerWindow>()?.FirstOrDefault();
            var isWindowAlreadyVisible = window != null;

            if (!isWindowAlreadyVisible)
            {
                string packageId = null;
                if (!string.IsNullOrEmpty(packageNameOrDisplayName))
                {
                    IPackageVersion version;
                    IPackage        package;
                    PackageDatabase.instance.GetPackageAndVersionByIdOrName(packageNameOrDisplayName, out package, out version);

                    packageId = version?.uniqueId ?? package?.versions.primary.uniqueId ?? string.Format(ApplicationUtil.instance.GetTranslationForText("{0}@primary"), packageNameOrDisplayName);
                }
                PackageManagerWindowAnalytics.SendEvent("openWindow", packageId);
            }

            SelectPackageAndFilter(packageNameOrDisplayName);
        }
        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 SetFilterFromMenu(PackageFilterTab filter)
 {
     SetFilter(filter);
     PackageManagerWindowAnalytics.SendEvent("changeFilter");
 }
예제 #20
0
        private void RemoveClick()
        {
            var roots = PackageDatabase.instance.GetReverseDependencies(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() ?? false) && !(!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) ? ApplicationUtil.instance.GetTranslationForText("Cannot disable built-in package") : ApplicationUtil.instance.GetTranslationForText("Cannot remove dependent package");
                EditorUtility.DisplayDialog(title, message, ApplicationUtil.instance.GetTranslationForText("Ok"));

                return;
            }

            if (displayVersion.HasTag(PackageTag.InDevelopment))
            {
                if (!EditorUtility.DisplayDialog(ApplicationUtil.instance.GetTranslationForText("Unity Package Manager"), ApplicationUtil.instance.GetTranslationForText("You will lose all your changes (if any) if you delete a package in development. Are you sure?"), ApplicationUtil.instance.GetTranslationForText("Yes"), ApplicationUtil.instance.GetTranslationForText("No")))
                {
                    return;
                }

                detailError.ClearError();
                PackageDatabase.instance.RemoveEmbedded(package);
                RefreshPackageActionButtons();

                PackageManagerWindowAnalytics.SendEvent("removeEmbedded", displayVersion.uniqueId);
                return;
            }

            var result = 0;

            if (displayVersion.HasTag(PackageTag.BuiltIn))
            {
                if (!PackageManagerPrefs.instance.skipDisableConfirmation)
                {
                    result = EditorUtility.DisplayDialogComplex(ApplicationUtil.instance.GetTranslationForText("Disable Built-In Package"),
                                                                ApplicationUtil.instance.GetTranslationForText("Are you sure you want to disable this built-in package?"),
                                                                ApplicationUtil.instance.GetTranslationForText("Disable"), ApplicationUtil.instance.GetTranslationForText("Cancel"), ApplicationUtil.instance.GetTranslationForText("Never ask"));
                }
            }
            else
            {
                if (!PackageManagerPrefs.instance.skipRemoveConfirmation)
                {
                    result = EditorUtility.DisplayDialogComplex(ApplicationUtil.instance.GetTranslationForText("Removing Package"),
                                                                ApplicationUtil.instance.GetTranslationForText("Are you sure you want to remove this package?"),
                                                                ApplicationUtil.instance.GetTranslationForText("Remove"), ApplicationUtil.instance.GetTranslationForText("Cancel"), ApplicationUtil.instance.GetTranslationForText("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();

            PackageManagerWindowAnalytics.SendEvent("uninstall", displayVersion?.uniqueId);
        }
예제 #21
0
        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();

                PackageManagerWindowAnalytics.SendEvent("removeEmbedded", displayVersion.uniqueId);

                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();

            PackageManagerWindowAnalytics.SendEvent("uninstall", displayVersion?.uniqueId);
        }