From f3bf07b60100523702ef54a75dcfbcfb7668913b Mon Sep 17 00:00:00 2001 From: bd_ Date: Thu, 28 Nov 2024 16:59:01 -0800 Subject: [PATCH] perf: switch to AssetSaver API (#1372) --- .github/ProjectRoot/vpm-manifest-2022.json | 4 ++-- Editor/Animation/AnimationDatabase.cs | 2 +- Editor/Animation/AnimatorCombiner.cs | 4 ++-- Editor/Animation/DeepClone.cs | 12 +++++++----- Editor/BuildContext.cs | 2 +- UnitTests~/SerializationTests/SerializationTests.cs | 2 +- package.json | 2 +- 7 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/ProjectRoot/vpm-manifest-2022.json b/.github/ProjectRoot/vpm-manifest-2022.json index ab64302d..4b40b6cd 100644 --- a/.github/ProjectRoot/vpm-manifest-2022.json +++ b/.github/ProjectRoot/vpm-manifest-2022.json @@ -4,7 +4,7 @@ "version": "3.7.0" }, "nadena.dev.ndmf": { - "version": "1.5.6" + "version": "1.6.0" } }, "locked": { @@ -19,7 +19,7 @@ "dependencies": {} }, "nadena.dev.ndmf": { - "version": "1.5.6" + "version": "1.6.0" } } } \ No newline at end of file diff --git a/Editor/Animation/AnimationDatabase.cs b/Editor/Animation/AnimationDatabase.cs index cb8a1a8d..d34ddff8 100644 --- a/Editor/Animation/AnimationDatabase.cs +++ b/Editor/Animation/AnimationDatabase.cs @@ -416,7 +416,7 @@ namespace nadena.dev.modular_avatar.animation { try { - AssetDatabase.AddObjectToAsset(curClip, _context.AssetContainer); + _context.AssetSaver.SaveAsset(curClip); } catch (Exception e) { diff --git a/Editor/Animation/AnimatorCombiner.cs b/Editor/Animation/AnimatorCombiner.cs index 6a64fe28..ea886afa 100644 --- a/Editor/Animation/AnimatorCombiner.cs +++ b/Editor/Animation/AnimatorCombiner.cs @@ -78,7 +78,7 @@ namespace nadena.dev.modular_avatar.animation _combined = new AnimatorController(); if (context.AssetContainer != null && EditorUtility.IsPersistent(context.AssetContainer)) { - AssetDatabase.AddObjectToAsset(_combined, context.AssetContainer); + context.AssetSaver.SaveAsset(_combined); } _combined.name = assetName; @@ -191,7 +191,7 @@ namespace nadena.dev.modular_avatar.animation EditorUtility.CopySerialized(t, newTransition); if (_context.AssetContainer != null) { - AssetDatabase.AddObjectToAsset(newTransition, _context.AssetContainer); + _context.AssetSaver.SaveAsset(newTransition); } t = newTransition; } diff --git a/Editor/Animation/DeepClone.cs b/Editor/Animation/DeepClone.cs index e84bac6f..50caadca 100644 --- a/Editor/Animation/DeepClone.cs +++ b/Editor/Animation/DeepClone.cs @@ -14,6 +14,7 @@ namespace nadena.dev.modular_avatar.animation internal class DeepClone { + private BuildContext _context; private bool _isSaved; private UnityObject _combined; @@ -21,6 +22,7 @@ namespace nadena.dev.modular_avatar.animation public DeepClone(BuildContext context) { + _context = context; _isSaved = context.AssetContainer != null && EditorUtility.IsPersistent(context.AssetContainer); _combined = context.AssetContainer; } @@ -33,6 +35,8 @@ namespace nadena.dev.modular_avatar.animation if (original == null) return null; if (cloneMap == null) cloneMap = new Dictionary(); + using var scope = _context.OpenSerializationScope(); + Func visitor = null; if (basePath != null) { @@ -96,14 +100,12 @@ namespace nadena.dev.modular_avatar.animation if (_isSaved && !EditorUtility.IsPersistent(obj)) { - AssetDatabase.AddObjectToAsset(obj, _combined); + scope.SaveAsset(obj); } return (T)obj; } - - var ctor = original.GetType().GetConstructor(Type.EmptyTypes); if (ctor == null || original is ScriptableObject) { @@ -120,7 +122,7 @@ namespace nadena.dev.modular_avatar.animation if (_isSaved) { - AssetDatabase.AddObjectToAsset(obj, _combined); + scope.SaveAsset(obj); } SerializedObject so = new SerializedObject(obj); @@ -233,7 +235,7 @@ namespace nadena.dev.modular_avatar.animation newClip.name = "rebased " + clip.name; if (_isSaved) { - AssetDatabase.AddObjectToAsset(newClip, _combined); + _context.AssetSaver.SaveAsset(newClip); } foreach (var binding in AnimationUtility.GetCurveBindings(clip)) diff --git a/Editor/BuildContext.cs b/Editor/BuildContext.cs index acd3f5cf..b1dfa3fc 100644 --- a/Editor/BuildContext.cs +++ b/Editor/BuildContext.cs @@ -71,7 +71,7 @@ namespace nadena.dev.modular_avatar.core.editor { if (!SaveImmediate || AssetDatabase.IsMainAsset(obj) || AssetDatabase.IsSubAsset(obj)) return; - AssetDatabase.AddObjectToAsset(obj, AssetContainer); + PluginBuildContext.AssetSaver.SaveAsset(obj); } public AnimatorController CreateAnimator(AnimatorController toClone = null) diff --git a/UnitTests~/SerializationTests/SerializationTests.cs b/UnitTests~/SerializationTests/SerializationTests.cs index b7272b90..c68f308b 100644 --- a/UnitTests~/SerializationTests/SerializationTests.cs +++ b/UnitTests~/SerializationTests/SerializationTests.cs @@ -63,7 +63,7 @@ namespace _ModularAvatar.EditModeTests.SerializationTests Assert.False(string.IsNullOrEmpty(path)); var mainAsset = AssetDatabase.LoadMainAssetAtPath(path); - Assert.IsInstanceOf(mainAsset); + Assert.IsTrue(mainAsset is GeneratedAssets or SubAssetContainer); } } } diff --git a/package.json b/package.json index 486d3a31..214be5df 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,6 @@ }, "vpmDependencies": { "com.vrchat.avatars": ">=3.7.0", - "nadena.dev.ndmf": ">=1.5.6 <2.0.0-a" + "nadena.dev.ndmf": ">=1.6.0 <2.0.0-a" } }