void OnPreprocessAsset() { bool isVFX = VisualEffectAssetModicationProcessor.HasVFXExtension(assetPath); if (isVFX) { VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath); if (resource == null) { return; } VFXGraph graph = resource.graph as VFXGraph; if (graph != null) { graph.SanitizeForImport(); } else { Debug.LogError("VisualEffectGraphResource without graph"); } } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { List <string> assetToReimport = null; #if VFX_HAS_TIMELINE UnityEditor.VFX.Migration.ActivationToControlTrack.SanitizePlayable(importedAssets); #endif foreach (var assetPath in importedAssets) { bool isVFX = VisualEffectAssetModicationProcessor.HasVFXExtension(assetPath); if (isVFX) { VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath); if (resource == null) { continue; } VFXGraph graph = resource.GetOrCreateGraph(); //resource.graph should be already != null at this stage but GetOrCreateGraph is also assigning the visualEffectResource. It's required for UpdateSubAssets if (graph != null) { bool wasGraphSanitized = graph.sanitized; try { graph.SanitizeForImport(); if (!wasGraphSanitized && graph.sanitized) { assetToReimport ??= new List <string>(); assetToReimport.Add(assetPath); } } catch (Exception exception) { Debug.LogErrorFormat("Exception during sanitization of {0} : {1}", assetPath, exception); } var window = VFXViewWindow.GetWindow(graph, false, false); if (window != null) { window.UpdateTitle(assetPath); } } else { Debug.LogErrorFormat("VisualEffectGraphResource without graph : {0}", assetPath); } } } //Relaunch previously skipped OnCompileResource if (assetToReimport != null) { foreach (var assetPath in assetToReimport) { try { AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate); } catch (Exception exception) { Debug.LogErrorFormat("Exception during reimport of {0} : {1}", assetPath, exception); } } } }