From 25c4258c9d837370ee321d3f348b0d9c4b6a2f69 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Fri, 5 May 2023 18:00:54 +0900 Subject: [PATCH 1/3] feat: add AssetEditingScope --- Editor/Utils.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Editor/Utils.cs b/Editor/Utils.cs index 4c869e05e..7feb638d6 100644 --- a/Editor/Utils.cs +++ b/Editor/Utils.cs @@ -328,6 +328,33 @@ public static NativeArray SliceNativeArray(NativeArray source, int leng source.AsReadOnlySpan().Slice(0, length).CopyTo(res.AsSpan()); return res; } + + public static AssetEditingScope StartEditingScope(bool saveAssets) => AssetEditingScope.Start(saveAssets); + + internal readonly struct AssetEditingScope : IDisposable + { + // 0: default: skip stop + // 1: stop asset editing + // 2: stop editing & save assets + private readonly int _flags; + + private AssetEditingScope(int flags) + { + _flags = flags; + } + + public static AssetEditingScope Start(bool saveAssets) + { + AssetDatabase.StartAssetEditing(); + return new AssetEditingScope(1 | (saveAssets ? 2 : 0)); + } + + public void Dispose() + { + if ((_flags & 1) != 0) AssetDatabase.StopAssetEditing(); + if ((_flags & 2) != 0) AssetDatabase.SaveAssets(); + } + } } internal struct ArraySerializedPropertyEnumerable : IEnumerable From 414426ce3c9242ee659e570d147b31ca18387277 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Fri, 5 May 2023 18:07:08 +0900 Subject: [PATCH 2/3] chore: use Utils.StartEditingScope instead of AssetDatabase.StartAssetEditing --- Editor/OptimizerProcessor.cs | 49 +++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/Editor/OptimizerProcessor.cs b/Editor/OptimizerProcessor.cs index 568b4af89..2aaa97ae2 100644 --- a/Editor/OptimizerProcessor.cs +++ b/Editor/OptimizerProcessor.cs @@ -32,16 +32,18 @@ public bool OnPreprocessAvatar(GameObject avatarGameObject) private static void ProcessObject(OptimizerSession session) { if (_processing) return; - try - { - AssetDatabase.StartAssetEditing(); - _processing = true; - DoProcessObject(session); - } - finally + using (Utils.StartEditingScope(true)) { - _processing = false; - AssetDatabase.SaveAssets(); + try + { + _processing = true; + DoProcessObject(session); + } + finally + { + _processing = false; + session.MarkDirtyAll(); + } } } @@ -80,22 +82,23 @@ public void OnPostprocessAvatar() public static void ProcessObject(OptimizerSession session) { if (_processing) return; - try - { - AssetDatabase.StartAssetEditing(); - _processing = true; - DoProcessObject(session); - } - finally + using (Utils.StartEditingScope(true)) { - _processing = false; - AssetDatabase.StopAssetEditing(); - foreach (var component in session.GetComponents()) - UnityEngine.Object.DestroyImmediate(component); - foreach (var activator in session.GetComponents()) - UnityEngine.Object.DestroyImmediate(activator); + try + { + _processing = true; + DoProcessObject(session); + } + finally + { + _processing = false; + foreach (var component in session.GetComponents()) + UnityEngine.Object.DestroyImmediate(component); + foreach (var activator in session.GetComponents()) + UnityEngine.Object.DestroyImmediate(activator); - AssetDatabase.SaveAssets(); + session.MarkDirtyAll(); + } } } From 157f0710df6f4c9e5ea49c8fac1b528901c32ae4 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Fri, 5 May 2023 18:08:44 +0900 Subject: [PATCH 3/3] docs(changelog): add Bad behaviour with VRCFury on build --- CHANGELOG-PRERELEASE.md | 1 + CHANGELOG.md | 1 + 2 files changed, 2 insertions(+) diff --git a/CHANGELOG-PRERELEASE.md b/CHANGELOG-PRERELEASE.md index e7f92d205..56f61b5d8 100644 --- a/CHANGELOG-PRERELEASE.md +++ b/CHANGELOG-PRERELEASE.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog]. ### Fixed - Can't remove SkinnedMeshRenderer error `#133` - This error should do nothing bad but it confuses everyone +- Bad behaviour with VRCFury on build `#134` ### Security diff --git a/CHANGELOG.md b/CHANGELOG.md index 90a7bdc14..4c05444cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ The format is based on [Keep a Changelog]. ### Fixed - Can't remove SkinnedMeshRenderer error `#133` - This error should do nothing bad but it confuses everyone +- Bad behaviour with VRCFury on build `#134` ### Security