chore: use binary serialization for generated assets

Thanks to @anatawa12 for the suggestion
This commit is contained in:
bd_ 2023-07-30 00:23:51 +09:00
parent 806841481c
commit dec90cb6ca
4 changed files with 24 additions and 5 deletions

View File

@ -24,6 +24,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -31,11 +32,11 @@ using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using nadena.dev.modular_avatar.editor.ErrorReporting; using nadena.dev.modular_avatar.editor.ErrorReporting;
using UnityEditor; using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEngine; using UnityEngine;
using VRC.SDK3.Avatars.Components; using VRC.SDK3.Avatars.Components;
using VRC.SDKBase.Editor.BuildPipeline; using VRC.SDKBase.Editor.BuildPipeline;
using BuildReport = nadena.dev.modular_avatar.editor.ErrorReporting.BuildReport; using BuildReport = nadena.dev.modular_avatar.editor.ErrorReporting.BuildReport;
using Debug = UnityEngine.Debug;
using Object = UnityEngine.Object; using Object = UnityEngine.Object;
[assembly: InternalsVisibleTo("Tests")] [assembly: InternalsVisibleTo("Tests")]
@ -158,6 +159,9 @@ namespace nadena.dev.modular_avatar.core.editor
var vrcAvatarDescriptor = avatarGameObject.GetComponent<VRCAvatarDescriptor>(); var vrcAvatarDescriptor = avatarGameObject.GetComponent<VRCAvatarDescriptor>();
Stopwatch sw = new Stopwatch();
sw.Start();
using (BuildReport.CurrentReport.ReportingOnAvatar(vrcAvatarDescriptor)) using (BuildReport.CurrentReport.ReportingOnAvatar(vrcAvatarDescriptor))
{ {
try try
@ -283,6 +287,8 @@ namespace nadena.dev.modular_avatar.core.editor
throw new Exception("Fatal error reported during avatar processing."); throw new Exception("Fatal error reported during avatar processing.");
} }
} }
Debug.Log($"Processed avatar " + avatarGameObject.name + " in " + sw.ElapsedMilliseconds + "ms");
} }
private static void ClearEditorOnlyTagComponents(Transform obj) private static void ClearEditorOnlyTagComponents(Transform obj)

View File

@ -14,7 +14,7 @@ namespace nadena.dev.modular_avatar.core.editor
{ {
internal readonly VRCAvatarDescriptor AvatarDescriptor; internal readonly VRCAvatarDescriptor AvatarDescriptor;
internal readonly AnimationDatabase AnimationDatabase = new AnimationDatabase(); internal readonly AnimationDatabase AnimationDatabase = new AnimationDatabase();
internal readonly AnimatorController AssetContainer; internal readonly UnityEngine.Object AssetContainer;
internal readonly Dictionary<VRCExpressionsMenu, VRCExpressionsMenu> ClonedMenus internal readonly Dictionary<VRCExpressionsMenu, VRCExpressionsMenu> ClonedMenus
= new Dictionary<VRCExpressionsMenu, VRCExpressionsMenu>(); = new Dictionary<VRCExpressionsMenu, VRCExpressionsMenu>();
@ -32,9 +32,10 @@ namespace nadena.dev.modular_avatar.core.editor
AvatarDescriptor = avatarDescriptor; AvatarDescriptor = avatarDescriptor;
// AssetDatabase.CreateAsset is super slow - so only do it once, and add everything else as sub-assets. // AssetDatabase.CreateAsset is super slow - so only do it once, and add everything else as sub-assets.
// This animator controller exists for the sole purpose of providing a placeholder to dump everything we // This scriptable object exists for the sole purpose of providing a placeholder to dump everything we
// generate into. // generate into. Note that we use a custom component here to force binary serialization; this saves both
AssetContainer = new AnimatorController(); // time as well as disk space (if you're using manual bake).
AssetContainer = ScriptableObject.CreateInstance<MAAssetBundle>();
AssetDatabase.CreateAsset(AssetContainer, Util.GenerateAssetPath()); AssetDatabase.CreateAsset(AssetContainer, Util.GenerateAssetPath());
} }

View File

@ -0,0 +1,9 @@
using UnityEngine;
namespace nadena.dev.modular_avatar.core
{
[PreferBinarySerialization]
class MAAssetBundle : ScriptableObject
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0e82ebb24aca47b7bc95ca94668015a6
timeCreated: 1690643821