Пример #1
0
        protected override void OnThreadUnSafeEventFired(object source, CharacterSessionDataChangedEventArgs args)
        {
            if (Logger.IsInfoEnabled)
            {
                Logger.Info($"Starting process to download world.");
            }

            UnityAsyncHelper.UnityMainThreadContext.PostAsync(async() =>
            {
                long worldId = 0;
                try
                {
                    //TODO: Handle failure
                    ProjectVersionStage.AssertAlpha();

                    //TODO: Handle throwing/error
                    //We need to know the world the zone is it, so we can request a download URL for it.
                    var worldConfig = await ZoneDataService.GetZoneWorldConfigurationAsync(args.ZoneIdentifier)
                                      .ConfigureAwaitFalse();

                    if (!worldConfig.isSuccessful)
                    {
                        throw new InvalidOperationException($"Failed to query World Configuration for ZoneId: {args.ZoneIdentifier}");
                    }

                    worldId = worldConfig.Result.WorldId;

                    //With the worldid we can get the download URL.
                    ContentDownloadURLResponse urlDownloadResponse = await ContentService.RequestWorldDownloadUrl(worldId)
                                                                     .ConfigureAwaitFalse();

                    if (Logger.IsInfoEnabled)
                    {
                        Logger.Info($"World Download Url: {urlDownloadResponse.DownloadURL}");
                    }

                    //Can't do web request not on the main thread, sadly.
                    await new UnityYieldAwaitable();

                    WorldDownloader downloader = new WorldDownloader(Logger);

                    await downloader.DownloadAsync(urlDownloadResponse.DownloadURL, urlDownloadResponse.Version, o =>
                    {
                        OnWorldDownloadBegins?.Invoke(this, new WorldDownloadBeginEventArgs(o));
                    });
                }
                catch (Exception e)
                {
                    if (Logger.IsErrorEnabled)
                    {
                        Logger.Error($"Failed to query for Download URL for ZoneId: {args.ZoneIdentifier} WorldId: {worldId} (0 if never succeeded request). Error: {e.Message}");
                    }
                    throw;
                }
            });
        }
Пример #2
0
        public async Task OnGameInitialized()
        {
            //TODO: Handle throwing/error
            ContentDownloadURLResponse downloadUrlResponse = await ContentService.RequestWorldDownloadUrl(WorldConfig.WorldId)
                                                             .ConfigureAwaitFalse();

            if (Logger.IsInfoEnabled)
            {
                Logger.Info($"World Download Url: {downloadUrlResponse.DownloadURL}");
            }

            //Can't do web request not on the main thread, sadly.
            await new UnityYieldAwaitable();

            //TODO: Handle failure.
            WorldDownloader downloader = new WorldDownloader(Logger);

            //At this point after this finishes the world shoud be downloaded.
            await downloader.DownloadAsync(downloadUrlResponse.DownloadURL, downloadUrlResponse.Version, null, true);             //important that the world loads ontop of the existing scene.
        }