Esempio n. 1
0
        public object Backup()
        {
            Profiler.BeginSample("VFXGraph.Backup");
            var dependencies = new HashSet <ScriptableObject>();

            dependencies.Add(this);
            CollectDependencies(dependencies);

            var result = VFXMemorySerializer.StoreObjectsToByteArray(dependencies.ToArray(), CompressionLevel.Fastest);

            Profiler.EndSample();

            return(result);
        }
Esempio n. 2
0
        public object Backup()
        {
            Profiler.BeginSample("VFXGraph.Backup");
            var dependencies = new HashSet <ScriptableObject>();

            dependencies.Add(this);
            CollectDependencies(dependencies);

            // This is a guard where dependencies that couldnt be deserialized (because script is missing for instance) are removed from the list
            // because else StoreObjectsToByteArray is crashing
            // TODO Fix that
            var safeDependencies = dependencies.Where(o => o != null);
            var result           = VFXMemorySerializer.StoreObjectsToByteArray(safeDependencies.ToArray(), CompressionLevel.Fastest);

            Profiler.EndSample();

            return(result);
        }
Esempio n. 3
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");
                }
            }
        }