コード例 #1
0
ファイル: VFXData.cs プロジェクト: Audaxxy/Blight
        public override void Sanitize(int version)
        {
            base.Sanitize(version);

            if (m_Parent == null)
            {
                string assetPath = AssetDatabase.GetAssetPath(this);
                m_Parent = VisualEffectResource.GetResourceAtPath(assetPath).GetOrCreateGraph();
            }
        }
コード例 #2
0
        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();
                }
            }
        }
コード例 #3
0
ファイル: VFXGraph.cs プロジェクト: Telica/Graphics
        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);
        }
コード例 #4
0
ファイル: VFXGraph.cs プロジェクト: Telica/Graphics
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        void OnPreprocessAsset()
        {
            bool isVFX = assetPath.EndsWith(VisualEffectResource.Extension);

            if (isVFX)
            {
                VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath);
                if (resource == null)
                {
                    return;
                }

                resource.GetOrCreateGraph().SanitizeForImport();
            }
        }
コード例 #7
0
ファイル: VFXGraph.cs プロジェクト: wayneyip/Graphics
        void OnPreprocessAsset()
        {
            bool isVFX = VisualEffectAssetModicationProcessor.HasVFXExtension(assetPath);

            if (isVFX)
            {
                VisualEffectResource resource = VisualEffectResource.GetResourceAtPath(assetPath);
                if (resource == null)
                {
                    return;
                }

                resource.GetOrCreateGraph().SanitizeForImport();
            }
        }
コード例 #8
0
ファイル: VFXGraph.cs プロジェクト: Mechachleopteryx/Graphics
 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);
 }
コード例 #9
0
ファイル: VFXGraph.cs プロジェクト: pball1000/FPS-Template
        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);
        }
コード例 #10
0
ファイル: VFXGraph.cs プロジェクト: Telica/Graphics
        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);
        }
コード例 #11
0
ファイル: VFXGraph.cs プロジェクト: Telica/Graphics
        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");
                }
            }
        }
コード例 #12
0
 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);
 }
コード例 #13
0
        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();
            }
        }
コード例 #14
0
        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);
                    }
                }
            }
        }