public void Restore(object str) { Profiler.BeginSample("VFXGraph.Restore"); var scriptableObject = VFXMemorySerializer.ExtractObjects(str as byte[], false); Profiler.BeginSample("VFXGraph.Restore SendUnknownChange"); foreach (var model in scriptableObject.OfType <VFXModel>()) { model.OnUnknownChange(); } Profiler.EndSample(); Profiler.EndSample(); m_ExpressionGraphDirty = true; m_ExpressionValuesDirty = true; m_DependentDirty = true; }
private static Func <object, bool, ScriptableObject[]> GetExtractObjectsFunction() { var advancedMethod = typeof(VFXMemorySerializer).GetMethod("ExtractObjects", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(byte[]), typeof(bool) }, null); if (advancedMethod != null) { return(delegate(object objects, bool asCopy) { return advancedMethod.Invoke(null, new object[] { objects as byte[], asCopy }) as ScriptableObject[]; }); } return(delegate(object objects, bool asCopy) { return VFXMemorySerializer.ExtractObjects(objects as string, asCopy); }); }
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"); } } }