Пример #1
0
        /// <summary>
        /// <para>Display the package information as a GUI.</para>
        /// <para>パッケージ情報をGUIとして表示する。</para>
        /// </summary>
        /// <param name="data">
        /// <para>Package infomation.</para>
        /// <para>パッケージ情報。</para>
        /// </param>
        /// <param name="bold">
        /// <para>Bold GUIStyle.</para>
        /// <para>太字のGUIStyle。</para>
        /// </param>
        /// <param name="window">
        /// <para>Main window of NuGet importer.</para>
        /// <para>NuGet importerのメインウィンドウ。</para>
        /// </param>
        /// <param name="selected">
        /// <para>Whether the package is selected.</para>
        /// <para>選択されたパッケージかどうか。</para>
        /// </param>
        /// <param name="installedVersion">
        /// <para>Installed version.</para>
        /// <para>インストールされているバージョン。</para>
        /// </param>
        internal static void ToGUI(this Catalog data, GUIStyle bold, NuGetImporterWindow window, bool selected, string installedVersion)
        {
            var   sizeScale = window.position.width / 1920;
            Color color     = GUI.color;

            if (selected)
            {
                GUI.color = Color.cyan;
            }
            Catalogentry catalogEntry = data.GetAllCatalogEntry().Where(catalog => catalog.version == installedVersion).First();

            using (var scope = new EditorGUILayout.HorizontalScope("Box", GUILayout.MinHeight(150), GUILayout.ExpandWidth(true)))
            {
                GUI.color = color;
                Event currentEvent = Event.current;
                if (currentEvent.type == EventType.MouseDown)
                {
                    if (scope.rect.Contains(currentEvent.mousePosition))
                    {
                        window.UpdateSelected(data);
                    }
                }
                using (new EditorGUILayout.VerticalScope(GUILayout.MinHeight(150), GUILayout.Width(150 * sizeScale)))
                {
                    GUILayout.FlexibleSpace();
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        GUILayout.FlexibleSpace();
                        EditorGUILayout.LabelField(new GUIContent(data.icon), GUILayout.Width(128 * sizeScale), GUILayout.Height(128 * sizeScale));
                        GUILayout.FlexibleSpace();
                    }
                    GUILayout.FlexibleSpace();
                }

                using (new EditorGUILayout.VerticalScope(GUILayout.ExpandWidth(true)))
                {
                    using (new EditorGUILayout.HorizontalScope(GUILayout.ExpandWidth(true)))
                    {
                        GUILayoutExtention.WrapedLabel(catalogEntry.id, 24);
                    }
                    using (new EditorGUILayout.HorizontalScope(GUILayout.ExpandWidth(true)))
                    {
                        GUILayout.Label("Author : ", bold);
                        GUILayout.Label(string.Join(", ", catalogEntry.authors));
                        GUILayout.FlexibleSpace();
                        GUILayout.Label("v" + installedVersion);
                    }
                    GUILayoutExtention.WrapedLabel(catalogEntry.summary == "" ? catalogEntry.description : catalogEntry.summary);
                }
            }
        }
Пример #2
0
        private static async Task PackageOperation(Task operation, NuGetImporterWindow window, string packageId, string message)
        {
            try
            {
                await operation;
                EditorUtility.DisplayDialog("NuGet importer", message, "OK");
            }
            catch (InvalidOperationException e)
            {
                EditorUtility.DisplayDialog("NuGet importer", e.Message, "OK");
            }
            catch (ArgumentException e)
            {
                EditorUtility.DisplayDialog("NuGet importer", e.Message, "OK");
            }
            await window.UpdateInstalledList();

            await window.UpdateSelected(packageId);
        }
Пример #3
0
        /// <summary>
        /// <para>Display the package information as a GUI.</para>
        /// <para>パッケージ情報をGUIとして表示する。</para>
        /// </summary>
        /// <param name="data">
        /// <para>Package infomation.</para>
        /// <para>パッケージ情報。</para>
        /// </param>
        /// <param name="bold">
        /// <para>Bold GUIStyle.</para>
        /// <para>太字のGUIStyle。</para>
        /// </param>
        /// <param name="window">
        /// <para>Main window of NuGet importer.</para>
        /// <para>NuGet importerのメインウィンドウ。</para>
        /// </param>
        /// <param name="selected">
        /// <para>Whether the package is selected.</para>
        /// <para>選択されたパッケージかどうか。</para>
        /// </param>
        /// <param name="onlyStable">
        /// <para>Whether only stable.</para>
        /// <para>安定版のみか。</para>
        /// </param>
        /// <returns>
        /// <para>Task</para>
        /// </returns>
        internal static async Task ToGUI(this Datum data, GUIStyle bold, NuGetImporterWindow window, bool selected, bool onlyStable)
        {
            var tasks     = new List <Task>();
            var sizeScale = window.position.width / 1920;

            if (onlyStable)
            {
                if (!data.versions.Any(version => !version.version.Contains('-') && version.version[0] != '0'))
                {
                    return;
                }
            }

            Color color = GUI.color;

            if (selected)
            {
                GUI.color = Color.cyan;
            }

            using (var scope = new EditorGUILayout.HorizontalScope("Box", GUILayout.MinHeight(150), GUILayout.ExpandWidth(true)))
            {
                GUI.color = color;
                Event currentEvent = Event.current;
                if (currentEvent.type == EventType.MouseDown)
                {
                    if (scope.rect.Contains(currentEvent.mousePosition))
                    {
                        tasks.Add(window.UpdateSelected(data));
                    }
                }
                using (new EditorGUILayout.VerticalScope(GUILayout.MinHeight(150), GUILayout.Width(150 * sizeScale)))
                {
                    GUILayout.FlexibleSpace();
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        GUILayout.FlexibleSpace();
                        EditorGUILayout.LabelField(new GUIContent(data.icon), GUILayout.Width(128 * sizeScale), GUILayout.Height(128 * sizeScale));
                        GUILayout.FlexibleSpace();
                    }
                    GUILayout.FlexibleSpace();
                }

                using (new EditorGUILayout.VerticalScope(GUILayout.ExpandWidth(true)))
                {
                    using (new EditorGUILayout.HorizontalScope(GUILayout.ExpandWidth(true)))
                    {
                        GUILayoutExtention.WrapedLabel(data.id, 24);
                    }

                    using (new EditorGUILayout.HorizontalScope(GUILayout.ExpandWidth(true)))
                    {
                        GUILayout.Label("Author : ", bold);
                        GUILayoutExtention.WrapedLabel(string.Join(", ", data.authors));
                        GUILayout.Label("Download :", bold);
                        GUILayout.Label(data.totalDownloads.ToString());
                        GUILayout.FlexibleSpace();
                        IEnumerable <string> sortedVersions = data.GetAllVersion().AsEnumerable().Reverse();
                        var version = onlyStable ? sortedVersions.First(ver => !ver.Contains('-') && ver[0] != '0') : sortedVersions.First();
                        if (PackageManager.Installed != null && PackageManager.Installed.package != null)
                        {
                            IEnumerable <Package> installed = PackageManager.Installed.package.Where(package => package.id == data.id);
                            if (installed != null && installed.Any())
                            {
                                version = installed.First().version;
                            }
                        }
                        GUILayout.Label("v" + version);
                    }
                    GUILayoutExtention.WrapedLabel(data.summary == "" ? data.description : data.summary);
                }
            }

            await Task.WhenAll(tasks);
        }
Пример #4
0
        /// <summary>
        /// <para>Displays an overview of the package information as a GUI.</para>
        /// <para>パッケージの概要をGUIとして表示する。</para>
        /// </summary>
        /// <param name="summary">
        /// <para>An overview of the package information.</para>
        /// <para>パッケージの概要。</para>
        /// </param>
        /// <param name="bold">
        /// <para>Bold GUIStyle.</para>
        /// <para>太字のGUIStyle。</para>
        /// </param>
        /// <param name="window">
        /// <para>Main window of NuGet importer.</para>
        /// <para>NuGet importerのメインウィンドウ。</para>
        /// </param>
        /// <param name="onlyStable">
        /// <para>Whether only stable.</para>
        /// <para>安定版のみか。</para>
        /// </param>
        /// <param name="method">
        /// <para>Method to select a version.</para>
        /// <para>バージョンを選択する方法。</para>
        /// <returns>
        /// <para>Task</para>
        /// </returns>
        internal static async Task ToGUI(this PackageSummary summary, GUIStyle bold, NuGetImporterWindow window, bool onlyStable, VersionSelectMethod method)
        {
            var tasks     = new List <Task>();
            var sizeScale = window.position.width / 1920;

            using (new EditorGUILayout.HorizontalScope(GUILayout.Height(150)))
            {
                using (new EditorGUILayout.VerticalScope(GUILayout.Width(150 * sizeScale)))
                {
                    GUILayout.FlexibleSpace();
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        GUILayout.FlexibleSpace();
                        EditorGUILayout.LabelField(new GUIContent(summary.Image), GUILayout.Width(128 * sizeScale), GUILayout.Height(128 * sizeScale));
                        GUILayout.FlexibleSpace();
                    }
                    GUILayout.FlexibleSpace();
                }

                using (new EditorGUILayout.VerticalScope(GUILayout.ExpandWidth(true)))
                {
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        GUILayoutExtention.WrapedLabel(summary.PackageId, 24);
                    }

                    using (new EditorGUILayout.HorizontalScope())
                    {
                        GUILayout.Label("version", bold);
                        List <string> versions = onlyStable ? summary.StableVersion : summary.AllVersion;
                        var           index    = versions.Contains(summary.SelectedVersion) ? versions.IndexOf(summary.SelectedVersion) : 0;
                        summary.SelectedVersion = versions[EditorGUILayout.Popup(index, versions.ToArray(), GUILayout.ExpandWidth(true))];
                        var isSameVersion = summary.SelectedVersion == summary.InstalledVersion;
                        var installText   = summary.InstalledVersion == null ? "Install" : isSameVersion ? "Repair" : "Change Version";
                        if (GUILayout.Button(installText, GUILayout.ExpandWidth(true)))
                        {
                            if (summary.InstalledVersion == null)
                            {
                                tasks.Add(PackageOperation(PackageManager.InstallPackage(summary.PackageId, summary.SelectedVersion, onlyStable, method), window, summary.PackageId, "Installation finished."));
                            }
                            else if (isSameVersion)
                            {
                                tasks.Add(PackageOperation(PackageManager.FixPackage(summary.PackageId), window, summary.PackageId, "The repair finished."));
                            }
                            else
                            {
                                tasks.Add(PackageOperation(PackageManager.ChangePackageVersion(summary.PackageId, summary.SelectedVersion, onlyStable, method), window, summary.PackageId, "Version change finished."));
                            }
                        }

                        using (new EditorGUI.DisabledScope(!isSameVersion))
                        {
                            if (GUILayout.Button("Uninstall", GUILayout.ExpandWidth(true)))
                            {
                                tasks.Add(PackageOperation(PackageManager.UninstallPackages(summary.PackageId, onlyStable), window, summary.PackageId, "Uninstallation finished."));
                            }
                        }
                    }
                }
            }
            await Task.WhenAll(tasks);
        }