예제 #1
0
 static void OnCompileResource(VisualEffectResource resource)
 {
     if (resource != null)
     {
         VFXGraph graph = resource.GetOrCreateGraph();
         if (graph != null)
         {
             graph.CompileForImport();
         }
     }
 }
예제 #2
0
        static void OnCompileResource(VisualEffectResource resource)
        {
            if (resource != null)
            {
                VFXGraph graph = resource.graph as VFXGraph;
                if (graph != null)
                {
                    if (!graph.sanitized)
                    {
                        //Early return, the reimport will be forced with the next OnPostprocessAllAssets after Sanitize
                        resource.ClearRuntimeData();
                    }
                    else
                    {
                        //Workaround, use backup system to prevent any modification of the graph during compilation
                        //The responsible of this unexpected change is PrepareSubgraphs => RecurseSubgraphRecreateCopy => ResyncSlots
                        //It will let the VFXGraph in a really bad state after compilation.
                        graph = resource.GetOrCreateGraph();
                        var dependencies = new HashSet <ScriptableObject>();
                        dependencies.Add(graph);
                        graph.CollectDependencies(dependencies);
                        var backup = VFXMemorySerializer.StoreObjectsToByteArray(dependencies.ToArray(), CompressionLevel.None);

                        graph.CompileForImport();

                        VFXMemorySerializer.ExtractObjects(backup, false);
                        //The backup during undo/redo is actually calling UnknownChange after ExtractObjects
                        //You have to avoid because it will call ResyncSlot
                    }
                }
                else
                {
                    Debug.LogError("OnCompileResource error - VisualEffectResource without graph");
                }
            }
        }