public override void Sanitize(int version) { base.Sanitize(version); if (m_Parent == null) { string assetPath = AssetDatabase.GetAssetPath(this); m_Parent = VisualEffectResource.GetResourceAtPath(assetPath).GetOrCreateGraph(); } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { var modifiedShaderGraphs = new HashSet <ShaderGraphVfxAsset>(); foreach (var asset in importedAssets.Concat(deletedAssets)) { if (asset.EndsWith(".shadergraph", StringComparison.InvariantCultureIgnoreCase)) { var ass = AssetDatabase.LoadAssetAtPath <ShaderGraphVfxAsset>(asset); if (ass != null) { modifiedShaderGraphs.Add(ass); } } } if (modifiedShaderGraphs.Count > 0) { string[] guids = AssetDatabase.FindAssets("t:VisualEffectAsset"); var assetsToReimport = new HashSet <VFXGraph>(); foreach (var vfxPath in guids.Select(t => AssetDatabase.GUIDToAssetPath(t))) { var resource = VisualEffectResource.GetResourceAtPath(vfxPath); if (resource != null) { VFXGraph graph = resource.GetOrCreateGraph(); if (graph != null) { if (graph.children.OfType <VFXShaderGraphParticleOutput>().Any(t => modifiedShaderGraphs.Contains(t.shaderGraph))) { assetsToReimport.Add(graph); } } } } foreach (var graph in assetsToReimport) { foreach (var sgOutput in graph.children.OfType <VFXShaderGraphParticleOutput>().Where(t => modifiedShaderGraphs.Contains(t.shaderGraph))) { int instanceID = sgOutput.shaderGraph.GetInstanceID(); // This is needed because the imported invalidate the object sgOutput.shaderGraph = EditorUtility.InstanceIDToObject(instanceID) as ShaderGraphVfxAsset; sgOutput.ResyncSlots(true); } graph.SetExpressionGraphDirty(); graph.RecompileIfNeeded(); } } }
public static VisualEffectResource GetResource(this VisualEffectObject asset) { string assetPath = AssetDatabase.GetAssetPath(asset); VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath); if (resource == null && !string.IsNullOrEmpty(assetPath)) { throw new NullReferenceException($"VFX resource does not exist for this asset at path: {assetPath}"); } return(resource); }
public static VisualEffectResource GetOrCreateResource(this VisualEffectObject asset) { string assetPath = AssetDatabase.GetAssetPath(asset); VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath); if (resource == null && !string.IsNullOrEmpty(assetPath)) { resource = new VisualEffectResource(); resource.SetAssetPath(assetPath); } return(resource); }
static string[] OnAddResourceDependencies(string assetPath) { VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath); if (resource != null) { VFXGraph graph = resource.GetOrCreateGraph(); if (graph != null) { return(graph.GetImportDependencies()); } } return(null); }
void OnPreprocessAsset() { bool isVFX = assetPath.EndsWith(VisualEffectResource.Extension); if (isVFX) { VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath); if (resource == null) { return; } resource.GetOrCreateGraph().SanitizeForImport(); } }
void OnPreprocessAsset() { bool isVFX = VisualEffectAssetModicationProcessor.HasVFXExtension(assetPath); if (isVFX) { VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath); if (resource == null) { return; } resource.GetOrCreateGraph().SanitizeForImport(); } }
static string[] OnWillSaveAssets(string[] paths) { Profiler.BeginSample("VisualEffectAssetModicationProcessor.OnWillSaveAssets"); foreach (string path in paths.Where(t => HasVFXExtension(t))) { var vfxResource = VisualEffectResource.GetResourceAtPath(path); if (vfxResource != null) { var graph = vfxResource.GetOrCreateGraph(); vfxResource.WriteAsset(); // write asset as the AssetDatabase won't do it. } } Profiler.EndSample(); return(paths); }
public static VisualEffectResource GetResource(this VisualEffectAsset asset) { VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(AssetDatabase.GetAssetPath(asset)); if (resource == null) { string assetPath = AssetDatabase.GetAssetPath(asset); resource = VisualEffectResource.GetResourceAtPath(assetPath); if (resource == null) { resource = new VisualEffectResource(); resource.SetAssetPath(assetPath); } } return(resource); }
static string[] OnAddResourceDependencies(string assetPath) { VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath); if (resource != null) { VFXGraph graph = resource.graph as VFXGraph; if (graph != null) { return(resource.GetOrCreateGraph().GetImportDependencies()); } else { Debug.LogError("VisualEffectGraphResource without graph"); } } return(null); }
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 string[] OnWillSaveAssets(string[] paths) { Profiler.BeginSample("VisualEffectAssetModicationProcessor.OnWillSaveAssets"); foreach (string path in paths.Where(t => HasVFXExtension(t))) { var vfxResource = VisualEffectResource.GetResourceAtPath(path); if (vfxResource != null) { vfxResource.GetOrCreateGraph().UpdateSubAssets(); try { VFXGraph.compilingInEditMode = vfxResource.GetOrCreateGraph().GetCompilationMode() == VFXCompilationMode.Edition; vfxResource.WriteAsset(); // write asset as the AssetDatabase won't do it. } finally { VFXGraph.compilingInEditMode = false; } } } Profiler.EndSample(); return(paths); }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { Profiler.BeginSample("VFXShaderGraphPostProcessor"); try { if (!disableImportDependentVFX) { var modifiedShaderGraphs = new HashSet <ShaderGraphVfxAsset>(); foreach (var asset in importedAssets.Concat(deletedAssets)) { if (asset.EndsWith(".shadergraph", StringComparison.InvariantCultureIgnoreCase)) { var ass = AssetDatabase.LoadAssetAtPath <ShaderGraphVfxAsset>(asset); if (ass != null) { modifiedShaderGraphs.Add(ass); } } } if (modifiedShaderGraphs.Count > 0) { string[] guids = AssetDatabase.FindAssets("t:VisualEffectAsset"); var assetsToReimport = new HashSet <VFXGraph>(); foreach (var vfxPath in guids.Select(t => AssetDatabase.GUIDToAssetPath(t))) { var resource = VisualEffectResource.GetResourceAtPath(vfxPath); if (resource != null) { VFXGraph graph = resource.GetOrCreateGraph(); if (graph != null) { if (graph.children.OfType <VFXShaderGraphParticleOutput>().Any(t => modifiedShaderGraphs.Contains(t.shaderGraph))) { assetsToReimport.Add(graph); } } } } foreach (var graph in assetsToReimport) { foreach (var sgOutput in graph.children.OfType <VFXShaderGraphParticleOutput>().Where(t => modifiedShaderGraphs.Contains(t.shaderGraph))) { int instanceID = sgOutput.shaderGraph.GetInstanceID(); // This is needed because the imported invalidate the object sgOutput.shaderGraph = EditorUtility.InstanceIDToObject(instanceID) as ShaderGraphVfxAsset; sgOutput.ResyncSlots(true); } graph.SetExpressionGraphDirty(); graph.RecompileIfNeeded(); } } // Update currently edited VFX mesh outputs if needed var currentGraph = VFXViewWindow.currentWindow?.graphView?.controller?.graph; if (currentGraph) { var meshOutputs = currentGraph.children.OfType <VFXStaticMeshOutput>(); if (meshOutputs.Any()) { foreach (var asset in importedAssets.Concat(deletedAssets)) { if (asset.EndsWith(".shadergraph", StringComparison.InvariantCultureIgnoreCase) || asset.EndsWith(".shader", StringComparison.InvariantCultureIgnoreCase)) { var shader = AssetDatabase.LoadAssetAtPath <Shader>(asset); foreach (var output in meshOutputs) { output.RefreshShader(shader); } } } } } } } finally { Profiler.EndSample(); } }
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); } } } }