Beispiel #1
0
        private IEnumerator DownloadPack(ReleaseType releaseType)
        {
            EditorUtility.DisplayProgressBar("Downloading", $"Downloading latest {releaseType}", 0);
            try
            {
                ReleaseResponse parsed       = null;
                string          errorMessage = null;
                var             releaseTask  = GitHubApi.GetLatestReleaseForRepo(
                    GithubRepo,
                    releaseType,
                    r => parsed       = r,
                    e => errorMessage = e);
                while (releaseTask.MoveNext())
                {
                    yield return(releaseTask.Current);
                }
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    EditorUtility.DisplayDialog("Error", errorMessage, "Ok");
                    yield break;
                }

                if (buildPacks.Any(p => p.Id == parsed.id))
                {
                    EditorUtility.DisplayDialog("Info", $"Version {parsed.tag_name} already downloaded", "Ok");
                    yield break;
                }

                var downloadTask = DownloadPack(packsLocation, parsed, error =>
                {
                    errorMessage = error;
                });
                while (downloadTask.MoveNext())
                {
                    yield return(downloadTask.Current);

                    if (!string.IsNullOrEmpty(errorMessage))
                    {
                        EditorUtility.DisplayDialog("Error", errorMessage, "Ok");
                        yield break;
                    }
                }
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    EditorUtility.DisplayDialog("Error", errorMessage, "Ok");
                    yield break;
                }
            }
            finally
            {
                EditorUtility.ClearProgressBar();
                UpdatePacksList();
            }
        }
Beispiel #2
0
        private void RenderPack(T pack)
        {
            EditorGUI.indentLevel++;
            switch (pack.Status)
            {
            case BuildPackStatus.NotLoaded:
                BackgroundTaskInvoker.StartBackgroundTask(GitHubApi.GetReleaseForRep(GithubRepo, pack.Id, p =>
                {
                    pack.PublishDate = p.PublishedAt;
                    pack.Status      = BuildPackStatus.Loaded;
                }, e => pack.Status = BuildPackStatus.LoadingError));
                pack.Status         = BuildPackStatus.Loading;
                break;

            case BuildPackStatus.Loading:
                EditorGUILayout.LabelField($"Downloading...");
                break;

            case BuildPackStatus.Loaded:
                EditorGUILayout.LabelField($"Publish date: {pack.PublishDate:yyyy-MM-dd}");
                if (GUI.Button(EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()), "Remove"))
                {
                    RemovePack(pack);
                    UpdatePacksList();
                }
                break;

            case BuildPackStatus.LoadingError:
                EditorGUILayout.LabelField($"Download error");
                break;

            default:
                EditorGUILayout.LabelField($"Unexpected error");
                break;
            }
            EditorGUI.indentLevel--;
        }