private async Task <Dictionary <AssetItem, object> > BuildAndReloadAssets(IEnumerable <AssetItem> assetsToRebuild) { var assetList = assetsToRebuild.ToList(); if (assetList.Count == 0) { return(null); } logger?.Debug($"Starting BuildAndReloadAssets for assets {string.Join(", ", assetList.Select(x => x.Location))}"); var value = Interlocked.Increment(ref loadingAssetCount); AssetLoading?.Invoke(this, new ContentLoadEventArgs(value)); try { // Rebuild the assets await Task.WhenAll(assetList.Select(x => database.Build(x))); logger?.Debug("Assets have been built"); // Unload the previous versions of assets and (re)load the newly build ones. var reloadedObjects = await UnloadAndReloadAssets(assetList); Game.TriggerActiveRenderStageReevaluation(); return(reloadedObjects); } finally { value = Interlocked.Decrement(ref loadingAssetCount); AssetLoaded?.Invoke(this, new ContentLoadEventArgs(value)); logger?.Debug($"Completed BuildAndReloadAssets for assets {string.Join(", ", assetList.Select(x => x.Location))}"); } }
public static void InvokeAssetLoading() => AssetLoading?.Invoke();
private void View_ScriptNotify(object sender, NotifyEventArgs e) { var key = e.Value.Substring(0, 4); var value = e.Value.Substring(4); switch (key) { // Loading assets case "LOAD": { AssetLoading?.Invoke(this, EventArgs.Empty); break; } // Assets loaded case "LODD": { _view.Opacity = 1; AssetLoaded?.Invoke(this, EventArgs.Empty); break; } // Camera alpha angle in radians case "ALPH": { AlphaInDegrees = GetDegreeFromRadian(double.Parse(value)); break; } // Camera beta angle in radians case "BETA": { BetaInDegrees = GetDegreeFromRadian(double.Parse(value)); break; } // Camera radius case "RADI": { RadiusPercentage = double.Parse(value); break; } // Animations are supported case "ANIM": { if (_commandGrid == null) { return; } _commandGrid.Visibility = Visibility.Visible; var animationNames = value.Split(','); if (_animationList != null) { _animationList.Items.Clear(); foreach (var animName in animationNames) { _animationList.Items.Add(animName); } _animationList.SelectedIndex = 0; _playSymbol.Visibility = Visibility.Collapsed; _pauseSymbol.Visibility = Visibility.Visible; } break; } // No animation case "NANM": { if (_commandGrid != null) { _commandGrid.Visibility = Visibility.Collapsed; } break; } // Current animation frame case "FRAM": { if (_animationSlider == null || !_sliderLayoutUpdated) { return; } var position = Math.Min(1, Math.Max(0, double.Parse(value))); // Making sure we are not overwhelming the system _sliderLayoutUpdated = false; _lastValueSetFromAnimation = position * 99.0; _animationSlider.Value = _lastValueSetFromAnimation; break; } } }