perf: switch to AssetSaver API (#1372)

This commit is contained in:
bd_ 2024-11-28 16:59:01 -08:00 committed by GitHub
parent 4a65b9f2ac
commit f3bf07b601
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 15 additions and 13 deletions

View File

@ -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"
}
}
}

View File

@ -416,7 +416,7 @@ namespace nadena.dev.modular_avatar.animation
{
try
{
AssetDatabase.AddObjectToAsset(curClip, _context.AssetContainer);
_context.AssetSaver.SaveAsset(curClip);
}
catch (Exception e)
{

View File

@ -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;
}

View File

@ -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<UnityObject, UnityObject>();
using var scope = _context.OpenSerializationScope();
Func<UnityObject, UnityObject> 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))

View File

@ -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)

View File

@ -63,7 +63,7 @@ namespace _ModularAvatar.EditModeTests.SerializationTests
Assert.False(string.IsNullOrEmpty(path));
var mainAsset = AssetDatabase.LoadMainAssetAtPath(path);
Assert.IsInstanceOf<GeneratedAssets>(mainAsset);
Assert.IsTrue(mainAsset is GeneratedAssets or SubAssetContainer);
}
}
}

View File

@ -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"
}
}