diff --git a/Prowl.Editor/Assets/AssetDatabase.Core.cs b/Prowl.Editor/Assets/AssetDatabase.Core.cs index ceacf9d46..77e2f2f7d 100644 --- a/Prowl.Editor/Assets/AssetDatabase.Core.cs +++ b/Prowl.Editor/Assets/AssetDatabase.Core.cs @@ -334,19 +334,20 @@ public static bool Reimport(FileInfo assetFile, bool disposeExisting = true) return false; // Import failed no Main Object } - // Update the meta file (LastModified is set by MetaFile.Load) - meta.assetTypes = new string[ctx.SubAssets.Count]; - for (int i = 0; i < ctx.SubAssets.Count; i++) - meta.assetTypes[i] = ctx.SubAssets[i].GetType().FullName!; - meta.Save(); - // Delete the old imported asset if it exists var serialized = GetSerializedFile(meta.guid); if (File.Exists(serialized.FullName)) serialized.Delete(); // Save the asset - ctx.SaveToFile(serialized); + ctx.SaveToFile(serialized, out var dependencies); + + // Update the meta file (LastModified is set by MetaFile.Load) + meta.assetTypes = new string[ctx.SubAssets.Count]; + for (int i = 0; i < ctx.SubAssets.Count; i++) + meta.assetTypes[i] = ctx.SubAssets[i].GetType().FullName!; + meta.dependencies = dependencies.ToList(); + meta.Save(); return true; } diff --git a/Prowl.Editor/Assets/MetaFile.cs b/Prowl.Editor/Assets/MetaFile.cs index 0b1b3665a..ec81fef68 100644 --- a/Prowl.Editor/Assets/MetaFile.cs +++ b/Prowl.Editor/Assets/MetaFile.cs @@ -11,6 +11,7 @@ public class MetaFile public DateTime lastModified; public ScriptedImporter importer; + public List dependencies; /// Default constructor for MetaFile. public MetaFile() { } diff --git a/Prowl.Runtime/Serializer/Serializer.cs b/Prowl.Runtime/Serializer/Serializer.cs index 3f612d27b..eb8e37bbf 100644 --- a/Prowl.Runtime/Serializer/Serializer.cs +++ b/Prowl.Runtime/Serializer/Serializer.cs @@ -223,8 +223,8 @@ private static SerializedProperty SerializeObject(object? value, SerializationCo compound["$id"] = new(PropertyType.Int, id); compound["$type"] = new(PropertyType.String, type.FullName); var dependencies = ctx.EndDependencies(); - if(dependencies.Count > 0) - compound["$dependencies"] = new(PropertyType.List, dependencies.Select(d => new SerializedProperty(PropertyType.String, d.ToString())).ToList()); + //if(dependencies.Count > 0) + // compound["$dependencies"] = new(PropertyType.List, dependencies.Select(d => new SerializedProperty(PropertyType.String, d.ToString())).ToList()); if (value is ISerializeCallbacks callback2) callback2.PostSerialize(); diff --git a/Prowl.Runtime/Utils/SerializedAsset.cs b/Prowl.Runtime/Utils/SerializedAsset.cs index 9b0c4c982..69035f5fa 100644 --- a/Prowl.Runtime/Utils/SerializedAsset.cs +++ b/Prowl.Runtime/Utils/SerializedAsset.cs @@ -12,16 +12,15 @@ public class SerializedAsset public bool HasMain => Main != null; - public void SaveToFile(FileInfo file) + public void SaveToFile(FileInfo file, out HashSet? dependencies) { if (Main == null) throw new Exception("Asset does not have a main object."); -#warning TODO: Somehow record Dependencies - reflection to find all AssetRef instances and store them in a list? - // We need a way for said Dependencies to be able to be loaded and references independently of the asset - // so like if we delete another asset we can let the user know its in use by X object are they sure? - file.Directory?.Create(); // Ensure the Directory exists - var tag = Serializer.Serialize(this); + Serializer.SerializationContext ctx = new(); + var tag = Serializer.Serialize(this, ctx); + dependencies = ctx.dependencies; + using var stream = file.OpenWrite(); using BinaryWriter writer = new(stream); BinaryTagConverter.WriteTo(tag, writer);