private void AssetPropertyChanged(object sender, AssetChangedEventArgs e) { if (e.Assets.Any(x => x.Asset == CurrentGameSettings)) { RaiseGameSettings(CurrentGameSettings); } }
private void AssetPropertyChanged(object sender, AssetChangedEventArgs e) { if (currentGraphicsCompositorAsset != null && e.Assets.Any(x => x.Asset == currentGraphicsCompositorAsset.Asset)) { ReloadGraphicsCompositor(true).Forget(); } }
private async void Session_AssetPropertiesChanged(object sender, AssetChangedEventArgs e) { // Only continue if there was changes in this asset if (!e.Assets.Contains(Asset)) { return; } await TriggerBackgroundCompilation(); }
private void OnAssetPropertyChanged(object sender, AssetChangedEventArgs e) { lock (previewLock) { var allAssets = AssetViewModel.ComputeRecursiveReferencerAssets(e.Assets); allAssets.AddRange(e.Assets); if (currentPreview != null && allAssets.Contains(currentPreview.AssetViewModel)) { PreviewGame.Script.AddTask(UpdatePreviewAsset); } } }
private void OnAssetPropertiesChanged(object sender, AssetChangedEventArgs args) { sceneEditorController.InvokeTask(async() => { bool shouldRebuild = false; foreach (var assetViewModel in args.Assets) { if (assetViewModel.AssetType == typeof(NavigationMeshAsset)) { await UpdateNavigationMeshLink(assetViewModel); } else if (assetViewModel.AssetType == typeof(SceneAsset)) { shouldRebuild = true; } } if (shouldRebuild && (dynamicNavigationMeshSystem?.Enabled ?? false)) { // Trigger rebuild of dynamic navigation game.Script.AddTask(async() => await dynamicNavigationMeshSystem.Rebuild()); } }); }
private async void AssetPropertiesChanged(object sender, AssetChangedEventArgs e) { // Get the list of assets directly referenced by entities, that reference one of the modified asset. (eg. get models when a material is changed) var allAssetsToRebuild = new HashSet <AssetViewModel>(); // Don't propagate property changes until we're fully initialized. await Asset.EditorInitialized; // If GameSettingsAssets.ColorSpace was changed, rebuild the whole scene var assets = e.Assets.ToList(); var references = await ComputeReferences(); var assetsToProcess = new Queue <AssetViewModel>(assets); var processedAssets = new HashSet <AssetViewModel>(assets); // Recurse through assets that depend on this one (recursively) while (assetsToProcess.Count > 0) { var assetToProcess = assetsToProcess.Dequeue(); HashSet <AssetId> modifiedAssetReferencers; // Check if the asset is referenced in the scene. if (!references.TryGetValue(assetToProcess.Id, out modifiedAssetReferencers)) { continue; } // We wait for a lock of the database. The lock we retrieve is synchronous, do not await in this using block! using ((await database.ReserveSyncLock()).Lock()) { // Use fast reload if supported and the asset is currently loaded if (FastReloadTypes.Contains(assetToProcess.AssetType) && IsCurrentlyLoaded(assetToProcess.Id)) { // Allow fast-reload only if the has not been added as non-fast-reloadable. allAssetsToRebuild.Add(assetToProcess); // Find dependent assets foreach (var referencer in assetToProcess.Dependencies.ReferencerAssets) { var node = database.AssetDependenciesCompiler.BuildDependencyManager.FindOrCreateNode(referencer.AssetItem, typeof(AssetCompilationContext)); node.Analyze(database.CompilerContext); foreach (var reference in node.References) { // Check if this reference is actually a compile-time dependency if (reference.Target.AssetItem.Id == assetToProcess.Id && reference.HasOne(BuildDependencyType.CompileContent | BuildDependencyType.Runtime)) { // If yes, process this asset later if (processedAssets.Add(referencer)) { assetsToProcess.Enqueue(referencer); } } } } } else { // Otherwise, rebuild the objects that are referenced by entities from the scene and that references this asset foreach (var assetViewModel in modifiedAssetReferencers.Select(x => Session.GetAssetById(x)).NotNull()) { allAssetsToRebuild.Add(assetViewModel); } } } } await BuildAndReloadAssets(allAssetsToRebuild.Select(x => x.AssetItem)); }
private async void AssetPropertiesChanged(object sender, AssetChangedEventArgs e) { // Get the list of assets directly referenced by entities, that reference one of the modified asset. (eg. get models when a material is changed) var allAssetsToRebuild = new HashSet <AssetViewModel>(); // Don't propagate property changes until we're fully initialized. await Asset.EditorInitialized; // If GameSettingsAssets.ColorSpace was changed, rebuild the whole scene var assets = e.Assets.ToList(); var references = await ComputeReferences(); var assetsToProcess = new Queue <AssetViewModel>(assets); var processedAssets = new HashSet <AssetViewModel>(assets); // Recurse through assets that depend on this one (recursively) while (assetsToProcess.Count > 0) { var assetToProcess = assetsToProcess.Dequeue(); HashSet <AssetId> modifiedAssetReferencers; // Check if the asset is referenced in the scene. if (!references.TryGetValue(assetToProcess.Id, out modifiedAssetReferencers)) { continue; } // We wait for a lock of the database. The lock we retrieve is synchronous, do not await in this using block! using ((await database.ReserveSyncLock()).Lock()) { // There is two patterns: // - Object is a fast-reloadable & already loaded object: we can replace its content internally without loading a new object and recreating any of its referencers // Note that we still need to process referencers in case it is used as a compile-time dependency (i.e. Material layer) // - Object is not a fast-reloadable object: we need to find its referencers (recursively) until we find node directly referenced by the scene (part of modifiedAssetReferencers) and reload this one var isFastReloadCurrentlyLoaded = FastReloadTypes.Contains(assetToProcess.AssetType) && IsCurrentlyLoaded(assetToProcess.Id); if (modifiedAssetReferencers.Contains(assetToProcess.Id) || isFastReloadCurrentlyLoaded) { allAssetsToRebuild.Add(assetToProcess); } // Find dependent assets foreach (var referencer in assetToProcess.Dependencies.ReferencerAssets) { var node = database.AssetDependenciesCompiler.BuildDependencyManager.FindOrCreateNode(referencer.AssetItem, typeof(AssetCompilationContext)); node.Analyze(database.CompilerContext); foreach (var reference in node.References) { // Check if this reference is actually a compile-time dependency // Or if it's not a fast reloadable type (in which case we also need to process its references) if (reference.Target.AssetItem.Id == assetToProcess.Id && (reference.HasOne(BuildDependencyType.CompileContent | BuildDependencyType.CompileAsset) || !isFastReloadCurrentlyLoaded)) { // If yes, process this asset later if (processedAssets.Add(referencer)) { assetsToProcess.Enqueue(referencer); } } } } } } await BuildAndReloadAssets(allAssetsToRebuild.Select(x => x.AssetItem)); }