From 34edbda56bbb6eb2d659d23f9e491b17d84e730a Mon Sep 17 00:00:00 2001 From: bd_ Date: Wed, 23 Aug 2023 21:46:39 +0900 Subject: [PATCH] feat: Initial integration with ABPF This is a draft integration with the ABPF framework. For now, this removes the old Apply On Play logic; not sure if we want to put this back for a transition period. --- Editor/OptimizerProcessor.cs | 89 ++++------- Editor/OptimizerSession.cs | 9 +- Editor/Utils.cs | 63 -------- ...m.anatawa12.avatar-optimizer.editor.asmdef | 6 +- Internal/ApplyOnPlay.meta | 3 - Internal/ApplyOnPlay/Editor.meta | 3 - .../Editor/ApplyOnPlayCallbackRegistry.cs | 104 ------------- .../ApplyOnPlayCallbackRegistry.cs.meta | 3 - .../ApplyOnPlay/Editor/ApplyOnPlayCaller.cs | 146 ------------------ .../Editor/ApplyOnPlayCaller.cs.meta | 3 - .../Editor/ApplyOnPlayConfiguration.cs | 67 -------- .../Editor/ApplyOnPlayConfiguration.cs.meta | 3 - .../Editor/IApplyOnPlayCallback.cs | 35 ----- .../Editor/IApplyOnPlayCallback.cs.meta | 3 - Internal/ApplyOnPlay/Editor/ManualBake.cs | 47 ------ .../ApplyOnPlay/Editor/ManualBake.cs.meta | 3 - .../Editor/ManualBakeFinallizer.cs | 29 ---- .../Editor/ManualBakeFinallizer.cs.meta | 3 - .../Editor/ModularAvatarSupport.cs | 92 ----------- .../Editor/ModularAvatarSupport.cs.meta | 3 - .../Editor/RemoveEditorOnlyOnPlay.cs | 20 --- .../Editor/RemoveEditorOnlyOnPlay.cs.meta | 3 - ...mizer.internal.apply-on-play.editor.asmdef | 29 ---- ....internal.apply-on-play.editor.asmdef.meta | 3 - Internal/ApplyOnPlay/Localization.meta | 3 - Internal/ApplyOnPlay/Localization/en.po | 12 -- Internal/ApplyOnPlay/Localization/en.po.meta | 3 - Internal/ApplyOnPlay/Localization/ja.po | 15 -- Internal/ApplyOnPlay/Localization/ja.po.meta | 3 - Internal/ApplyOnPlay/Runtime.meta | 3 - .../Runtime/ApplyOnPlayActivator.cs | 42 ----- .../Runtime/ApplyOnPlayActivator.cs.meta | 3 - .../ApplyOnPlay/Runtime/GlobalActivator.cs | 115 -------------- .../Runtime/GlobalActivator.cs.meta | 3 - .../Runtime/SceneChangeReceiver.cs | 73 --------- .../Runtime/SceneChangeReceiver.cs.meta | 3 - ...izer.internal.apply-on-play.runtime.asmdef | 15 -- ...internal.apply-on-play.runtime.asmdef.meta | 3 - .../ErrorReportingInitializerProcessor.cs | 7 +- 39 files changed, 48 insertions(+), 1024 deletions(-) delete mode 100644 Internal/ApplyOnPlay.meta delete mode 100644 Internal/ApplyOnPlay/Editor.meta delete mode 100644 Internal/ApplyOnPlay/Editor/ApplyOnPlayCallbackRegistry.cs delete mode 100644 Internal/ApplyOnPlay/Editor/ApplyOnPlayCallbackRegistry.cs.meta delete mode 100644 Internal/ApplyOnPlay/Editor/ApplyOnPlayCaller.cs delete mode 100644 Internal/ApplyOnPlay/Editor/ApplyOnPlayCaller.cs.meta delete mode 100644 Internal/ApplyOnPlay/Editor/ApplyOnPlayConfiguration.cs delete mode 100644 Internal/ApplyOnPlay/Editor/ApplyOnPlayConfiguration.cs.meta delete mode 100644 Internal/ApplyOnPlay/Editor/IApplyOnPlayCallback.cs delete mode 100644 Internal/ApplyOnPlay/Editor/IApplyOnPlayCallback.cs.meta delete mode 100644 Internal/ApplyOnPlay/Editor/ManualBake.cs delete mode 100644 Internal/ApplyOnPlay/Editor/ManualBake.cs.meta delete mode 100644 Internal/ApplyOnPlay/Editor/ManualBakeFinallizer.cs delete mode 100644 Internal/ApplyOnPlay/Editor/ManualBakeFinallizer.cs.meta delete mode 100644 Internal/ApplyOnPlay/Editor/ModularAvatarSupport.cs delete mode 100644 Internal/ApplyOnPlay/Editor/ModularAvatarSupport.cs.meta delete mode 100644 Internal/ApplyOnPlay/Editor/RemoveEditorOnlyOnPlay.cs delete mode 100644 Internal/ApplyOnPlay/Editor/RemoveEditorOnlyOnPlay.cs.meta delete mode 100644 Internal/ApplyOnPlay/Editor/com.anatawa12.avatar-optimizer.internal.apply-on-play.editor.asmdef delete mode 100644 Internal/ApplyOnPlay/Editor/com.anatawa12.avatar-optimizer.internal.apply-on-play.editor.asmdef.meta delete mode 100644 Internal/ApplyOnPlay/Localization.meta delete mode 100644 Internal/ApplyOnPlay/Localization/en.po delete mode 100644 Internal/ApplyOnPlay/Localization/en.po.meta delete mode 100644 Internal/ApplyOnPlay/Localization/ja.po delete mode 100644 Internal/ApplyOnPlay/Localization/ja.po.meta delete mode 100644 Internal/ApplyOnPlay/Runtime.meta delete mode 100644 Internal/ApplyOnPlay/Runtime/ApplyOnPlayActivator.cs delete mode 100644 Internal/ApplyOnPlay/Runtime/ApplyOnPlayActivator.cs.meta delete mode 100644 Internal/ApplyOnPlay/Runtime/GlobalActivator.cs delete mode 100644 Internal/ApplyOnPlay/Runtime/GlobalActivator.cs.meta delete mode 100644 Internal/ApplyOnPlay/Runtime/SceneChangeReceiver.cs delete mode 100644 Internal/ApplyOnPlay/Runtime/SceneChangeReceiver.cs.meta delete mode 100644 Internal/ApplyOnPlay/Runtime/com.anatawa12.avatar-optimizer.internal.apply-on-play.runtime.asmdef delete mode 100644 Internal/ApplyOnPlay/Runtime/com.anatawa12.avatar-optimizer.internal.apply-on-play.runtime.asmdef.meta diff --git a/Editor/OptimizerProcessor.cs b/Editor/OptimizerProcessor.cs index 56e6e955f..3d93e709f 100644 --- a/Editor/OptimizerProcessor.cs +++ b/Editor/OptimizerProcessor.cs @@ -1,49 +1,50 @@ using System; -using Anatawa12.ApplyOnPlay; +using System.Collections.Immutable; +using Anatawa12.AvatarOptimizer; using Anatawa12.AvatarOptimizer.ErrorReporting; -using UnityEngine; +using nadena.dev.ndmf; using VRC.SDK3.Avatars.Components; -using VRC.SDKBase.Editor.BuildPipeline; + +[assembly: ExportsPlugin(typeof(OptimizerPlugin))] namespace Anatawa12.AvatarOptimizer { + internal class OptimizerPlugin : Plugin + { + public override string QualifiedName => "Anatawa12.AvatarOptimizer"; + + public override ImmutableList RunsAfter => ImmutableList.Empty.Add("nadena.dev.modular-avatar"); + + public override ImmutableList Passes => ImmutableList.Empty + .Add(new EarlyOptimizerProcessor()) + .Add(new OptimizerProcessor()); + } + /// /// the Processor runs before removing EditorOnly /// - internal class EarlyOptimizerProcessor : IVRCSDKPreprocessAvatarCallback, IApplyOnPlayCallback + internal class EarlyOptimizerProcessor : PluginPass { - public int callbackOrder => -2048; + public override BuiltInPhase ExecutionPhase => BuiltInPhase.Resolving; + public string CallbackName => "Avatar Optimizer Early (Before IEditorOnly Deletion)"; public string CallbackId => "com.anatawa12.avatar-optimizer.early"; - public bool ApplyOnPlay(GameObject avatarGameObject, ApplyReason reason) - { - ProcessObject(new OptimizerSession(avatarGameObject, Utils.CreateOutputAssetFile(avatarGameObject, reason), - reason == ApplyReason.EnteringPlayMode)); - return true; - } + private static bool _processing; - public bool OnPreprocessAvatar(GameObject avatarGameObject) + public override ImmutableList RunsBefore => ImmutableList.Empty + .Add(SystemPassNames.RemoveEditorOnly); + + public override void Process(BuildContext context) { - try - { - ProcessObject(new OptimizerSession(avatarGameObject, true, false)); - return true; - } - catch (Exception e) - { - Debug.LogError(e); - return false; - } + ProcessObject(new OptimizerSession(context.AvatarRootObject, false, false)); } - - private static bool _processing; - + internal static void ProcessObject(OptimizerSession session) { if (_processing) return; - using (Utils.StartEditingScope(true)) + //using (Utils.StartEditingScope(true)) using (BuildReport.ReportingOnAvatar(session.GetRootComponent())) { try @@ -72,36 +73,16 @@ private static void DoProcessObject(OptimizerSession session) } } - internal class OptimizerProcessor : IVRCSDKPreprocessAvatarCallback, IVRCSDKPostprocessAvatarCallback, IApplyOnPlayCallback + internal class OptimizerProcessor : PluginPass { - public int callbackOrder => 0; + public override BuiltInPhase ExecutionPhase => BuiltInPhase.Optimization; + public string CallbackName => "Avatar Optimizer Main"; public string CallbackId => "com.anatawa12.avatar-optimizer.main"; - - public bool ApplyOnPlay(GameObject avatarGameObject, ApplyReason reason) - { - ProcessObject(new OptimizerSession(avatarGameObject, Utils.CreateOutputAssetFile(avatarGameObject, reason), - reason == ApplyReason.EnteringPlayMode)); - return true; - } - - public bool OnPreprocessAvatar(GameObject avatarGameObject) - { - try - { - ProcessObject(new OptimizerSession(avatarGameObject, true, false)); - return true; - } - catch (Exception e) - { - Debug.LogError(e); - return false; - } - } - - public void OnPostprocessAvatar() + + public override void Process(BuildContext context) { - Utils.DeleteTemporalDirectory(); + ProcessObject(new OptimizerSession(context.AvatarRootObject, false, false)); } private static bool _processing; @@ -109,7 +90,7 @@ public void OnPostprocessAvatar() public static void ProcessObject(OptimizerSession session) { if (_processing) return; - using (Utils.StartEditingScope(true)) + //using (Utils.StartEditingScope(true)) using (BuildReport.ReportingOnAvatar(session.GetRootComponent())) { try @@ -145,8 +126,6 @@ private static void DoProcessObject(OptimizerSession session) new Processors.MakeChildrenProcessor(early: false).Process(session); new Processors.ApplyObjectMapping().Apply(session); - - session.MarkDirtyAll(); } } } diff --git a/Editor/OptimizerSession.cs b/Editor/OptimizerSession.cs index 4ada56b55..5143e878e 100644 --- a/Editor/OptimizerSession.cs +++ b/Editor/OptimizerSession.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using nadena.dev.ndmf; using UnityEditor; using UnityEngine; using Object = UnityEngine.Object; @@ -15,8 +16,14 @@ internal class OptimizerSession public bool IsTest { get; } public ObjectMappingBuilder MappingBuilder { get; } + public OptimizerSession(BuildContext context) + : this(context.AvatarRootObject, null, false) + { + + } + public OptimizerSession(GameObject rootObject, bool addToAsset, bool isTest) : - this(rootObject, addToAsset ? Utils.CreateAssetFile() : null, isTest) + this(rootObject, null, isTest) { } diff --git a/Editor/Utils.cs b/Editor/Utils.cs index 9df8a85a6..6db60a703 100644 --- a/Editor/Utils.cs +++ b/Editor/Utils.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using Anatawa12.ApplyOnPlay; using JetBrains.Annotations; using Unity.Collections; using UnityEditor; @@ -312,68 +311,6 @@ public static GameObject NewGameObject(string name, Transform parent) return rootObject; } - private const string TemporalDirPath = "Assets/9999-OptimizerGeneratedTemporalAssets"; - private const string OutputDirPath = "Assets/AvatarOptimizerOutput"; - - public static void DeleteTemporalDirectory() - { - AssetDatabase.SaveAssets(); - AssetDatabase.DeleteAsset(TemporalDirPath); - FileUtil.DeleteFileOrDirectory(TemporalDirPath); - } - - [CanBeNull] - public static DummyObject CreateOutputAssetFile(GameObject avatarGameObject, ApplyReason reason) - { - switch (reason) - { - case ApplyReason.EnteringPlayMode: - return ApplyOnPlayConfig.Generate ? CreateAssetFile() : null; - case ApplyReason.ManualBake: - default: - return CreateOutputAssetFile(avatarGameObject); - } - } - - public static DummyObject CreateAssetFile() - { - var obj = ScriptableObject.CreateInstance(); - Directory.CreateDirectory(TemporalDirPath); - AssetDatabase.CreateAsset(obj, $"{TemporalDirPath}/{GUID.Generate()}.asset"); - return obj; - } - - public static DummyObject CreateOutputAssetFile(GameObject avatar) - { - var name = avatar.name; - if (name.EndsWith("(Clone)", StringComparison.Ordinal)) - name = name.Substring(0, name.Length - "(Clone)".Length); - return CreateOutputAssetFile(name); - } - - public static DummyObject CreateOutputAssetFile(string name) - { - Directory.CreateDirectory(OutputDirPath); - name = string.Join("_", name.Split(Path.GetInvalidFileNameChars())); - var path = GetUniqueFileName($"{OutputDirPath}/{name}", "asset"); - var obj = ScriptableObject.CreateInstance(); - AssetDatabase.CreateAsset(obj, path); - return obj; - } - - private static string GetUniqueFileName(string name, string extension) - { - // TOCTOU is allowed for now - string PathIfNotExists(string path) => File.Exists(path) || Directory.Exists(path) ? null : path; - - if (PathIfNotExists($"{name}.{extension}") is string firstTry) return firstTry; - - for (var number = 0; ; number++) - { - if (PathIfNotExists($"{name} ({number}).{extension}") is string otherTry) return otherTry; - } - } - public static ZipWithNextEnumerable ZipWithNext(this IEnumerable enumerable) => new ZipWithNextEnumerable(enumerable); diff --git a/Editor/com.anatawa12.avatar-optimizer.editor.asmdef b/Editor/com.anatawa12.avatar-optimizer.editor.asmdef index a84e39da3..13f17adaa 100644 --- a/Editor/com.anatawa12.avatar-optimizer.editor.asmdef +++ b/Editor/com.anatawa12.avatar-optimizer.editor.asmdef @@ -9,7 +9,8 @@ "GUID:f69eeb3e25674f4a9bd20e6d7e69e0e6", "GUID:2633ab9fa94544a69517fc9a1bc143c9", "GUID:b9880ca0b6584453a2627bd3c038759f", - "GUID:8542dbf824204440a818dbc2377cb4d6" + "GUID:8542dbf824204440a818dbc2377cb4d6", + "GUID:62ced99b048af7f4d8dfe4bed8373d76" ], "includePlatforms": [ "Editor" @@ -25,7 +26,8 @@ "VRCSDK3A.dll", "VRCSDKBase-Editor.dll", "VRCSDKBase.dll", - "System.Memory.dll" + "System.Memory.dll", + "System.Collections.Immutable.dll" ], "autoReferenced": false, "defineConstraints": [], diff --git a/Internal/ApplyOnPlay.meta b/Internal/ApplyOnPlay.meta deleted file mode 100644 index 46382bb40..000000000 --- a/Internal/ApplyOnPlay.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d3efff5aaf74461d847a84bef2a196e7 -timeCreated: 1688537830 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor.meta b/Internal/ApplyOnPlay/Editor.meta deleted file mode 100644 index 8b80554e0..000000000 --- a/Internal/ApplyOnPlay/Editor.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: e0b78af1dd2949d6be80e9bc0f2b0a93 -timeCreated: 1688537837 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/ApplyOnPlayCallbackRegistry.cs b/Internal/ApplyOnPlay/Editor/ApplyOnPlayCallbackRegistry.cs deleted file mode 100644 index 03c60464c..000000000 --- a/Internal/ApplyOnPlay/Editor/ApplyOnPlayCallbackRegistry.cs +++ /dev/null @@ -1,104 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using JetBrains.Annotations; -using UnityEditor; -using UnityEngine; - -namespace Anatawa12.ApplyOnPlay -{ - [InitializeOnLoad] - public static class ApplyOnPlayCallbackRegistry - { - internal static readonly List Callbacks = new List(); - internal static readonly List Finalizers = new List(); - internal const string ENABLE_EDITOR_PREFS_PREFIX = "com.anatawa12.apply-on-play.enabled."; - - static ApplyOnPlayCallbackRegistry() - { - var assemblies = AppDomain.CurrentDomain.GetAssemblies(); - - foreach (var assembly in assemblies) - { - try - { - var types = assembly.GetTypes(); - foreach (var type in types) - { - DoCallback(type, RegisterCallback); - DoCallback(type, RegisterFinalizer); - } - } - catch (Exception e) - { - try - { - LogException($"Discovering types in {assembly.GetName().Name}", e); - } - catch (Exception e2) - { - LogException("Discovering types in some assembly", e, e2); - } - } - } - } - - private static void DoCallback(Type type, Action add) - { - if (!typeof(T).IsAssignableFrom(type)) return; - var constructor = type.GetConstructor(Type.EmptyTypes); - if (constructor == null) return; - try - { - add((T)constructor.Invoke(Array.Empty())); - } - catch (Exception e) - { - LogException($"Instantiating {type.Name}", e); - } - } - - [PublicAPI] - public static void RegisterCallback(IApplyOnPlayCallback callback) - { - Callbacks.Add(callback); - } - - [PublicAPI] - public static void RegisterFinalizer(IManualBakeFinalizer callback) - { - Finalizers.Add(callback); - } - - internal static IApplyOnPlayCallback[] GetCallbacks() - { - var copied = Callbacks - .Where(x => EditorPrefs.GetBool(ENABLE_EDITOR_PREFS_PREFIX + x.CallbackId, true)) - .ToArray(); - Array.Sort(copied, (a, b) => a.callbackOrder.CompareTo(b.callbackOrder)); - return copied; - } - - internal static IManualBakeFinalizer[] GetFinalizers() - { - var copied = Finalizers.ToArray(); - Array.Sort(copied, (a, b) => a.callbackOrder.CompareTo(b.callbackOrder)); - return copied; - } - - private static void LogException(string message, params Exception[] exceptions) - { - message = $"[ApplyOnPlay] {message}"; - - if (exceptions.Length == 1) - { - Debug.LogException(new Exception(message, exceptions[0])); - } - else - { - Debug.LogException(new AggregateException(message, exceptions)); - } - } - } -} \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/ApplyOnPlayCallbackRegistry.cs.meta b/Internal/ApplyOnPlay/Editor/ApplyOnPlayCallbackRegistry.cs.meta deleted file mode 100644 index 9c67c81dd..000000000 --- a/Internal/ApplyOnPlay/Editor/ApplyOnPlayCallbackRegistry.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 0a345ccfc2414cc2b0ae3ad8162c8a36 -timeCreated: 1688544068 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/ApplyOnPlayCaller.cs b/Internal/ApplyOnPlay/Editor/ApplyOnPlayCaller.cs deleted file mode 100644 index 96d361435..000000000 --- a/Internal/ApplyOnPlay/Editor/ApplyOnPlayCaller.cs +++ /dev/null @@ -1,146 +0,0 @@ -using System; -using System.Diagnostics; -using System.Linq; -using UnityEditor; -using UnityEditor.SceneManagement; -using UnityEngine; -using UnityEngine.SceneManagement; -using VRC.SDK3.Avatars.Components; -using Debug = UnityEngine.Debug; -using Object = UnityEngine.Object; - -namespace Anatawa12.ApplyOnPlay -{ - [InitializeOnLoad] - internal static class ApplyOnPlayCaller - { - public const string SkipApplyingIfInactiveName = "com.anatawa12.apply-on-play.skip-if-inactive"; - - static ApplyOnPlayCaller() - { - GlobalActivator.activate = activator => OnProcessScene(activator.gameObject.scene); - ApplyOnPlayActivator.processAvatar = activator => - { - var component = activator.gameObject.GetComponent(); - Object.DestroyImmediate(activator); - if (component) - ProcessAvatar(component.gameObject, ApplyReason.EnteringPlayMode, - ApplyOnPlayCallbackRegistry.GetCallbacks()); - }; - - EditorSceneManager.newSceneCreated += (scene, _1, _2) => - EditorApplication.delayCall += () => SceneChangeReceiver.CreateIfNotExists(scene); - EditorSceneManager.sceneOpened += (scene, _) => GlobalActivator.CreateIfNotNeeded(scene); - - EditorApplication.playModeStateChanged += state => - { - if (state != PlayModeStateChange.EnteredEditMode) return; - foreach (var scene in Enumerable.Range(0, SceneManager.sceneCount) - .Select(SceneManager.GetSceneAt)) - SceneChangeReceiver.CreateIfNotNeeded(scene); - }; - - EditorApplication.delayCall += () => - { - foreach (var scene in Enumerable.Range(0, SceneManager.sceneCount) - .Select(SceneManager.GetSceneAt)) - GlobalActivator.CreateIfNotNeeded(scene); - }; - } - - public static bool SkipApplyingIfInactive - { - get => EditorPrefs.GetBool(SkipApplyingIfInactiveName, true); - set => EditorPrefs.SetBool(SkipApplyingIfInactiveName, value); - } - - public static void OnProcessScene(Scene scene) - { - var components = scene.GetRootGameObjects() - .SelectMany(x => x.GetComponentsInChildren(true)).ToArray(); - - var callbacks = ApplyOnPlayCallbackRegistry.GetCallbacks(); - - var skipIfInactive = SkipApplyingIfInactive; - - var stopwatch = Stopwatch.StartNew(); - try - { - AssetDatabase.StartAssetEditing(); - - foreach (var vrcAvatarDescriptor in components) - { - if (skipIfInactive && !vrcAvatarDescriptor.gameObject.activeInHierarchy) - { - var activator = vrcAvatarDescriptor.gameObject.AddComponent(); - activator.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector; - } - else - { - ProcessAvatar(vrcAvatarDescriptor.gameObject, ApplyReason.EnteringPlayMode, callbacks); - } - } - } - finally - { - AssetDatabase.StopAssetEditing(); - Debug.Log($"time to process apply on play: {stopwatch.Elapsed}"); - } - } - - internal static bool ProcessAvatar(GameObject avatarGameObject, ApplyReason reason, IApplyOnPlayCallback[] callbacks) - { - string action; - switch (reason) - { - case ApplyReason.EnteringPlayMode: - action = "Apply on Play"; - break; - case ApplyReason.ManualBake: - action = "Manual Bake"; - break; - default: - throw new ArgumentOutOfRangeException(nameof(reason), reason, null); - } - - foreach (var applyOnPlayCallback in callbacks) - { - try - { - if (!applyOnPlayCallback.ApplyOnPlay(avatarGameObject, reason)) - { - var message = $"The {action} for {avatarGameObject} was aborted because " + - $"'{applyOnPlayCallback.CallbackName}' reported a failure."; - Debug.LogError(message); - return false; - } - } - catch (Exception ex) - { - var message = $"The {action} for {avatarGameObject} was aborted because " + - $"'{applyOnPlayCallback.CallbackName}' threw an exception."; - Debug.LogError(message); - Debug.LogException(ex); - return false; - } - } - - return true; - } - - public static void CallManualBakeFinalizer(IManualBakeFinalizer[] finalizers, GameObject original, GameObject avatar) - { - foreach (var manualBakeFinalizer in finalizers) - { - try - { - manualBakeFinalizer.FinalizeManualBake(original, avatar); - } - catch (Exception ex) - { - Debug.LogException(ex); - } - } - } - } -} \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/ApplyOnPlayCaller.cs.meta b/Internal/ApplyOnPlay/Editor/ApplyOnPlayCaller.cs.meta deleted file mode 100644 index 027cef4d9..000000000 --- a/Internal/ApplyOnPlay/Editor/ApplyOnPlayCaller.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 627e27a2ee76477a943d110221ac7810 -timeCreated: 1688541277 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/ApplyOnPlayConfiguration.cs b/Internal/ApplyOnPlay/Editor/ApplyOnPlayConfiguration.cs deleted file mode 100644 index 11059f9db..000000000 --- a/Internal/ApplyOnPlay/Editor/ApplyOnPlayConfiguration.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System.Linq; -using CustomLocalization4EditorExtension; -using UnityEditor; -using UnityEngine; - -namespace Anatawa12.ApplyOnPlay -{ - internal class ApplyOnPlayConfiguration : EditorWindow - { - [MenuItem("Tools/Apply on Play/Configuration", false, 100)] - internal static void OpenWindow() => GetWindow("Apply on Play Config").Show(); - - [AssemblyCL4EELocalization] private static Localization Localization { get; } = new Localization("588f55b2626b4d7fb0b79d34fc67de42", "en"); - - private (string callbackId, string callbackName)[] _callbacks; - private Vector2 _scroll; - - private void OnEnable() - { - _callbacks = ApplyOnPlayCallbackRegistry.Callbacks - .OrderBy(x => x.callbackOrder) - .Select(x => (x.CallbackId, x.CallbackName)) - .ToArray(); - } - - private void OnGUI() - { - CL4EE.DrawLanguagePicker(); - - ApplyOnPlayCaller.SkipApplyingIfInactive - = EditorGUILayout.ToggleLeft(CL4EE.Tr("skip applying if avtar is not active"), - ApplyOnPlayCaller.SkipApplyingIfInactive); - - EditorGUILayout.HelpBox(CL4EE.Tr("window description"), MessageType.None); - - _scroll = EditorGUILayout.BeginScrollView(_scroll); - - foreach (var (callbackId, callbackName) in _callbacks) - { - var key = ApplyOnPlayCallbackRegistry.ENABLE_EDITOR_PREFS_PREFIX + callbackId; - var enabled = EditorPrefs.GetBool(key, true); - EditorGUI.BeginChangeCheck(); - enabled = EditorGUILayout.ToggleLeft(callbackName, enabled); - if (EditorGUI.EndChangeCheck()) - { - EditorPrefs.SetBool(key, enabled); - } - } - - EditorGUILayout.EndScrollView(); - - GUILayout.BeginHorizontal(); - if (GUILayout.Button("Enable All")) - { - foreach (var (callbackId, callbackName) in _callbacks) - EditorPrefs.SetBool(ApplyOnPlayCallbackRegistry.ENABLE_EDITOR_PREFS_PREFIX + callbackId, true); - } - - if (GUILayout.Button("Disable All")) - { - foreach (var (callbackId, callbackName) in _callbacks) - EditorPrefs.SetBool(ApplyOnPlayCallbackRegistry.ENABLE_EDITOR_PREFS_PREFIX + callbackId, false); - } - GUILayout.EndHorizontal(); - } - } -} \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/ApplyOnPlayConfiguration.cs.meta b/Internal/ApplyOnPlay/Editor/ApplyOnPlayConfiguration.cs.meta deleted file mode 100644 index 6e354b45f..000000000 --- a/Internal/ApplyOnPlay/Editor/ApplyOnPlayConfiguration.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 137dfac8e1bf4d9bba21cc9677cc02cc -timeCreated: 1688554923 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/IApplyOnPlayCallback.cs b/Internal/ApplyOnPlay/Editor/IApplyOnPlayCallback.cs deleted file mode 100644 index ee76df431..000000000 --- a/Internal/ApplyOnPlay/Editor/IApplyOnPlayCallback.cs +++ /dev/null @@ -1,35 +0,0 @@ -using UnityEditor.Build; -using UnityEngine; - -namespace Anatawa12.ApplyOnPlay -{ - /** - * The callback will be called on entering play mode. - * - * The instance of callback can be reused but may not be reused. - * - * If your class that implements this interface has public constructor without parameters, - * the class will automatically registered. - * If not, you have to register to manually yourself. - */ - public interface IApplyOnPlayCallback : IOrderedCallback - { - /// - /// The name of callback will be shown in the configuration window - /// - string CallbackName { get; } - - /// - /// Callback identifier. This ID is used as part of the name of the EditorPrefs key. - /// - string CallbackId { get; } - - bool ApplyOnPlay(GameObject avatarGameObject, ApplyReason reason); - } - - public enum ApplyReason - { - EnteringPlayMode, - ManualBake, - } -} diff --git a/Internal/ApplyOnPlay/Editor/IApplyOnPlayCallback.cs.meta b/Internal/ApplyOnPlay/Editor/IApplyOnPlayCallback.cs.meta deleted file mode 100644 index bee4e4327..000000000 --- a/Internal/ApplyOnPlay/Editor/IApplyOnPlayCallback.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 82202160f6e24a93a7f068e170d5bdb1 -timeCreated: 1688538730 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/ManualBake.cs b/Internal/ApplyOnPlay/Editor/ManualBake.cs deleted file mode 100644 index 6e5e45b12..000000000 --- a/Internal/ApplyOnPlay/Editor/ManualBake.cs +++ /dev/null @@ -1,47 +0,0 @@ -using UnityEditor; -using UnityEngine; -using VRC.SDK3.Avatars.Components; -using Object = UnityEngine.Object; - -namespace Anatawa12.ApplyOnPlay -{ - internal static class ManualBake - { - private const string ManualBakeMenuName = "Tools/Apply on Play/Manual Bake Avatar"; - private const string ManualBakeContextMenuName = "GameObject/[Apply on Play] Manual Bake Avatar"; - private const int ManualBakeContextMenuPriority = 49; - - [MenuItem(ManualBakeMenuName, true)] - [MenuItem(ManualBakeContextMenuName, true, ManualBakeContextMenuPriority)] - private static bool CheckManualBake() - { - var avatar = Selection.activeGameObject; - return avatar && avatar.GetComponent() != null; - } - - [MenuItem(ManualBakeMenuName, false)] - [MenuItem(ManualBakeContextMenuName, false, ManualBakeContextMenuPriority)] - private static void ExecuteManualBake() - { - var avatar = Selection.activeGameObject; - var avatarDescriptor = avatar.GetComponent(); - if (avatar == null || avatarDescriptor == null) return; - - var original = avatar; - avatar = Object.Instantiate(avatar); - avatar.transform.position += Vector3.forward * 2; - - var callbacks = ApplyOnPlayCallbackRegistry.GetCallbacks(); - - try - { - ApplyOnPlayCaller.ProcessAvatar(avatar, ApplyReason.ManualBake, callbacks); - } - finally - { - ApplyOnPlayCaller.CallManualBakeFinalizer(ApplyOnPlayCallbackRegistry.GetFinalizers(), original, avatar); - Selection.objects = new Object[] { avatar }; - } - } - } -} diff --git a/Internal/ApplyOnPlay/Editor/ManualBake.cs.meta b/Internal/ApplyOnPlay/Editor/ManualBake.cs.meta deleted file mode 100644 index c27c21933..000000000 --- a/Internal/ApplyOnPlay/Editor/ManualBake.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 25ca85ee035942b2a921cae685dc5566 -timeCreated: 1684048011 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/ManualBakeFinallizer.cs b/Internal/ApplyOnPlay/Editor/ManualBakeFinallizer.cs deleted file mode 100644 index ea76f10c8..000000000 --- a/Internal/ApplyOnPlay/Editor/ManualBakeFinallizer.cs +++ /dev/null @@ -1,29 +0,0 @@ -using UnityEditor.Build; -using UnityEngine; - -namespace Anatawa12.ApplyOnPlay -{ - /** - * The callback will be called on finalizing manual bake. - * - * The instance of callback can be reused but may not be reused. - * - * If your class that implements this interface has public constructor without parameters, - * the class will automatically registered. - * If not, you have to register to manually yourself. - */ - public interface IManualBakeFinalizer : IOrderedCallback - { - /// - /// The name of callback will be shown in the configuration window - /// - string CallbackName { get; } - - /// - /// Callback identifier. This ID is used as part of the name of the EditorPrefs key. - /// - string CallbackId { get; } - - void FinalizeManualBake(GameObject original, GameObject cloned); - } -} diff --git a/Internal/ApplyOnPlay/Editor/ManualBakeFinallizer.cs.meta b/Internal/ApplyOnPlay/Editor/ManualBakeFinallizer.cs.meta deleted file mode 100644 index a501b1f8b..000000000 --- a/Internal/ApplyOnPlay/Editor/ManualBakeFinallizer.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: a1568bec7c5841719b5dfccf9b631878 -timeCreated: 1688745881 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/ModularAvatarSupport.cs b/Internal/ApplyOnPlay/Editor/ModularAvatarSupport.cs deleted file mode 100644 index 02263288a..000000000 --- a/Internal/ApplyOnPlay/Editor/ModularAvatarSupport.cs +++ /dev/null @@ -1,92 +0,0 @@ -#if MODULAR_AVATAR -using System; -using System.IO; -using System.Reflection; -using nadena.dev.modular_avatar.core.editor; -using nadena.dev.modular_avatar.core; -using UnityEditor; -using UnityEngine; -using Object = UnityEngine.Object; - -namespace Anatawa12.ApplyOnPlay -{ - [InitializeOnLoad] - internal class ModularAvatarSupport : IApplyOnPlayCallback - { - static ModularAvatarSupport() - { - // if apply on play framework integration is embed to modular avatar itself, do not use this support module - if (typeof(AvatarProcessor).GetField("ApplyOnPlaySupported", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static) != null) - return; - - ApplyOnPlayCallbackRegistry.RegisterCallback(new ModularAvatarSupport(new AvatarProcessor())); - } - - private readonly AvatarProcessor _processor; - - public ModularAvatarSupport(AvatarProcessor processor) - { - _processor = processor; - } - - [MenuItem("Tools/Modular Avatar/Apply on Play config has been moved", false, 1000 - 1)] - private static void ToggleApplyOnPlay() => ApplyOnPlayConfiguration.OpenWindow(); - - public int callbackOrder => _processor.callbackOrder; - - public string CallbackName => "Modular Avatar"; - public string CallbackId => "com.anatawa12.apply-on-play.modular-avatar"; - - public bool ApplyOnPlay(GameObject avatarGameObject, ApplyReason reason) - { - if (!avatarGameObject.GetComponentInChildren()) - return true; // skip avatar without MA components - try - { - return _processor.OnPreprocessAvatar(avatarGameObject); - } - finally - { - if (reason == ApplyReason.ManualBake) - { - MoveModularAvatarAssets(avatarGameObject); - } - } - } - - private static void MoveModularAvatarAssets(GameObject avatarGameObject) - { - try - { - var maGeneratedPath = "Assets/999_Modular_Avatar_Generated"; - var outputPath = $"Assets/ModularAvatarOutput"; - if (!Directory.Exists(maGeneratedPath)) return; - - var avatarName = avatarGameObject.name; - if (avatarName.EndsWith("(Clone)", StringComparison.Ordinal)) - avatarName = avatarName.Substring(0, avatarName.Length - "(Clone)".Length); - - avatarName = string.Join("_", avatarName.Split(Path.GetInvalidFileNameChars())); - - var basePath = $"Assets/ModularAvatarOutput/{avatarName}"; - var savePath = basePath; - - var extension = 0; - - while (File.Exists(savePath) || Directory.Exists(savePath)) - { - savePath = basePath + " " + (++extension); - } - - Directory.CreateDirectory(outputPath); - Directory.Move(maGeneratedPath, savePath); - AssetDatabase.Refresh(); - } - catch (Exception e) - { - Debug.LogException(e); - } - } - } -} -#endif diff --git a/Internal/ApplyOnPlay/Editor/ModularAvatarSupport.cs.meta b/Internal/ApplyOnPlay/Editor/ModularAvatarSupport.cs.meta deleted file mode 100644 index 7b624b75b..000000000 --- a/Internal/ApplyOnPlay/Editor/ModularAvatarSupport.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 0524f821675e4aa7ad76f2222c21d8c5 -timeCreated: 1688546214 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/RemoveEditorOnlyOnPlay.cs b/Internal/ApplyOnPlay/Editor/RemoveEditorOnlyOnPlay.cs deleted file mode 100644 index 875610e24..000000000 --- a/Internal/ApplyOnPlay/Editor/RemoveEditorOnlyOnPlay.cs +++ /dev/null @@ -1,20 +0,0 @@ -using UnityEngine; -using Object = UnityEngine.Object; - -namespace Anatawa12.ApplyOnPlay -{ - internal class RemoveEditorOnlyOnPlay : IApplyOnPlayCallback - { - public int callbackOrder => -1024; - public string CallbackName => "Remove Editor Only"; - public string CallbackId => "com.anatawa12.apply-on-play.remove-editor-only"; - - public bool ApplyOnPlay(GameObject avatarGameObject, ApplyReason reason) - { - foreach (var transform in avatarGameObject.GetComponentsInChildren(true)) - if (transform && transform != avatarGameObject.transform && transform.gameObject.CompareTag("EditorOnly")) - Object.DestroyImmediate(transform.gameObject); - return true; - } - } -} \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/RemoveEditorOnlyOnPlay.cs.meta b/Internal/ApplyOnPlay/Editor/RemoveEditorOnlyOnPlay.cs.meta deleted file mode 100644 index 48a10833e..000000000 --- a/Internal/ApplyOnPlay/Editor/RemoveEditorOnlyOnPlay.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: a4ae1df3479b4e7995097c0c8fe365f8 -timeCreated: 1688557065 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/com.anatawa12.avatar-optimizer.internal.apply-on-play.editor.asmdef b/Internal/ApplyOnPlay/Editor/com.anatawa12.avatar-optimizer.internal.apply-on-play.editor.asmdef deleted file mode 100644 index 155f5a192..000000000 --- a/Internal/ApplyOnPlay/Editor/com.anatawa12.avatar-optimizer.internal.apply-on-play.editor.asmdef +++ /dev/null @@ -1,29 +0,0 @@ -{ - "name": "com.anatawa12.avatar-optimizer.internal.apply-on-play.editor", - "references": [ - "GUID:b1529a8c1c7946769969aca7e2ce5034", - "GUID:295ffbe0b63504ae3a7879cf089501ba", - "GUID:5ce33783346c3124990afbe7b0390a06", - "GUID:fc900867c0f47cd49b6e2ae4ef907300" - ], - "includePlatforms": [ - "Editor" - ], - "excludePlatforms": [], - "allowUnsafeCode": false, - "overrideReferences": true, - "precompiledReferences": [ - "VRCSDK3A.dll", - "VRCSDKBase.dll" - ], - "autoReferenced": false, - "defineConstraints": [], - "versionDefines": [ - { - "name": "nadena.dev.modular-avatar", - "expression": "[1.0.0,2.0.0)", - "define": "MODULAR_AVATAR" - } - ], - "noEngineReferences": false -} \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Editor/com.anatawa12.avatar-optimizer.internal.apply-on-play.editor.asmdef.meta b/Internal/ApplyOnPlay/Editor/com.anatawa12.avatar-optimizer.internal.apply-on-play.editor.asmdef.meta deleted file mode 100644 index c5bfef26d..000000000 --- a/Internal/ApplyOnPlay/Editor/com.anatawa12.avatar-optimizer.internal.apply-on-play.editor.asmdef.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 8d9ff9f975de4bf0b86c6cc50332d028 -timeCreated: 1688537879 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Localization.meta b/Internal/ApplyOnPlay/Localization.meta deleted file mode 100644 index d6a1db0a0..000000000 --- a/Internal/ApplyOnPlay/Localization.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 588f55b2626b4d7fb0b79d34fc67de42 -timeCreated: 1688555817 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Localization/en.po b/Internal/ApplyOnPlay/Localization/en.po deleted file mode 100644 index b283c77a9..000000000 --- a/Internal/ApplyOnPlay/Localization/en.po +++ /dev/null @@ -1,12 +0,0 @@ -msgid "" -msgstr "" -"Language: en\n" - -msgid "window description" -msgstr "" -"You can disable applying non-destructive avatar modification tools on play.\n" -"Checked means enabled and not checked means disabled.\n" -"This configuration is shared between projects." - -msgid "skip applying if avtar is not active" -msgstr "skip applying if avtar is not active" diff --git a/Internal/ApplyOnPlay/Localization/en.po.meta b/Internal/ApplyOnPlay/Localization/en.po.meta deleted file mode 100644 index df9146834..000000000 --- a/Internal/ApplyOnPlay/Localization/en.po.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 2062d885c1fa64f958102089d9d87e36 -timeCreated: 1679754988 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Localization/ja.po b/Internal/ApplyOnPlay/Localization/ja.po deleted file mode 100644 index 2e696a411..000000000 --- a/Internal/ApplyOnPlay/Localization/ja.po +++ /dev/null @@ -1,15 +0,0 @@ -msgid "" -msgstr "" -"Language: ja\n" - -msgid "locale:ja" -msgstr "日本語" - -msgid "window description" -msgstr "" -"非破壊アバター改変ツールのプレイ時の適用を無効にすることができます。\n" -"チェックが入っていると有効、チェックが入っていないと無効になります。\n" -"この設定はプロジェクト間で共有されます。" - -msgid "skip applying if avtar is not active" -msgstr "activeでないアバターではapplyしないようにする" diff --git a/Internal/ApplyOnPlay/Localization/ja.po.meta b/Internal/ApplyOnPlay/Localization/ja.po.meta deleted file mode 100644 index 7a48b3ca8..000000000 --- a/Internal/ApplyOnPlay/Localization/ja.po.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 41f2a70d735a348b896a3d642ced3dd0 -timeCreated: 1684121431 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Runtime.meta b/Internal/ApplyOnPlay/Runtime.meta deleted file mode 100644 index 1349e06e5..000000000 --- a/Internal/ApplyOnPlay/Runtime.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 5e8970ecd9224544a8ee780ad3267f28 -timeCreated: 1689408960 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Runtime/ApplyOnPlayActivator.cs b/Internal/ApplyOnPlay/Runtime/ApplyOnPlayActivator.cs deleted file mode 100644 index f6a47aef8..000000000 --- a/Internal/ApplyOnPlay/Runtime/ApplyOnPlayActivator.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using UnityEngine; - -[assembly:InternalsVisibleTo("com.anatawa12.avatar-optimizer.internal.apply-on-play.editor")] - -namespace Anatawa12.ApplyOnPlay -{ - [DefaultExecutionOrder(-100000)] - [ExecuteAlways] - [AddComponentMenu("")] - [DisallowMultipleComponent] - internal class ApplyOnPlayActivator : MonoBehaviour - { -#if UNITY_EDITOR - internal static Action processAvatar; - - private void Awake() - { - UnityEditor.EditorApplication.delayCall += () => DestroyIfNeeded(); - } - - private void Start() - { - if (!this) return; - if (DestroyIfNeeded()) return; - processAvatar?.Invoke(this); - } - - private bool DestroyIfNeeded() - { - var shouldDestroy = !UnityEditor.EditorApplication.isPlaying || - UnityEditor.EditorUtility.IsPersistent(this); - if (!shouldDestroy) return false; - - Debug.Log("Destroying ApplyOnPlayActivator in Start"); - DestroyImmediate(this); - return true; - } -#endif - } -} \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Runtime/ApplyOnPlayActivator.cs.meta b/Internal/ApplyOnPlay/Runtime/ApplyOnPlayActivator.cs.meta deleted file mode 100644 index 687c87ea9..000000000 --- a/Internal/ApplyOnPlay/Runtime/ApplyOnPlayActivator.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 6bc30d8be68840c5bf4d6be45b9c0f9f -timeCreated: 1689409131 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Runtime/GlobalActivator.cs b/Internal/ApplyOnPlay/Runtime/GlobalActivator.cs deleted file mode 100644 index 750854399..000000000 --- a/Internal/ApplyOnPlay/Runtime/GlobalActivator.cs +++ /dev/null @@ -1,115 +0,0 @@ -#if UNITY_EDITOR -using UnityEditor; -using UnityEditor.SceneManagement; -#endif -using System; -using System.Linq; -using UnityEngine; -using UnityEngine.SceneManagement; -using VRC.SDKBase; - -namespace Anatawa12.ApplyOnPlay -{ - [DefaultExecutionOrder(-100000)] - [ExecuteAlways] - [AddComponentMenu("")] - [DisallowMultipleComponent] - internal class GlobalActivator : MonoBehaviour - { -#if UNITY_EDITOR - internal static Action activate; - - private void Awake() - { - if (!EditorApplication.isPlaying || this == null) return; - activate?.Invoke(this); - DestroyImmediate(this); - } - - private void Start() - { - if (!EditorApplication.isPlaying || this == null) return; - activate?.Invoke(this); - DestroyImmediate(this); - } - - internal static bool HasAvatarInScene(Scene scene) - { - return scene.GetRootGameObjects().Any(x => x.GetComponentInChildren(true)); - } - - internal static void CreateIfNotNeeded(Scene scene) - { - if (!scene.IsValid() || EditorSceneManager.IsPreviewScene(scene)) return; - if (EditorApplication.isPlayingOrWillChangePlaymode) return; - - if (HasAvatarInScene(scene)) - { - CreateIfNotExists(scene); - } - else - { - SceneChangeReceiver.CreateIfNotExists(scene); - foreach (var root in scene.GetRootGameObjects()) - { - if (root.GetComponent() != null) - { - DestroyImmediate(root); - EditorSceneManager.MarkSceneDirty(scene); - } - } - } - } - - private static void CreateIfNotExists(Scene scene) - { - bool rootPresent = false; - foreach (var root in scene.GetRootGameObjects()) - { - if (root.GetComponent() != null) - { - root.hideFlags = HideFlags; - root.SetActive(true); - if (rootPresent) DestroyImmediate(root); - rootPresent = true; - } - } - - if (rootPresent) return; - - var oldActiveScene = SceneManager.GetActiveScene(); - try - { - SceneManager.SetActiveScene(scene); - var gameObject = new GameObject("ApplyOnPlayGlobalActivator"); - gameObject.AddComponent(); - gameObject.hideFlags = HideFlags; - } - finally - { - SceneManager.SetActiveScene(oldActiveScene); - } - } - - private void OnValidate() - { - if (EditorApplication.isPlayingOrWillChangePlaymode) return; - - EditorApplication.delayCall += () => - { - if (this == null) return; - - gameObject.hideFlags = HideFlags; - if (!HasAvatarInScene(gameObject.scene)) - { - var scene = gameObject.scene; - DestroyImmediate(gameObject); - EditorSceneManager.MarkSceneDirty(scene); - } - }; - } - - private const HideFlags HideFlags = UnityEngine.HideFlags.HideInHierarchy; -#endif - } -} \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Runtime/GlobalActivator.cs.meta b/Internal/ApplyOnPlay/Runtime/GlobalActivator.cs.meta deleted file mode 100644 index 2c9300bb3..000000000 --- a/Internal/ApplyOnPlay/Runtime/GlobalActivator.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 2fd77bd470834be2861d36c929588b6f -timeCreated: 1691744202 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Runtime/SceneChangeReceiver.cs b/Internal/ApplyOnPlay/Runtime/SceneChangeReceiver.cs deleted file mode 100644 index d3ac75681..000000000 --- a/Internal/ApplyOnPlay/Runtime/SceneChangeReceiver.cs +++ /dev/null @@ -1,73 +0,0 @@ -using UnityEngine; -using UnityEngine.SceneManagement; - -namespace Anatawa12.ApplyOnPlay -{ - [ExecuteAlways] - [AddComponentMenu("")] - [DisallowMultipleComponent] - public class SceneChangeReceiver : MonoBehaviour - { -#if UNITY_EDITOR - public Scene scene; - - void Update() - { - if (scene.IsValid()) - { - if (GlobalActivator.HasAvatarInScene(scene)) - { - GlobalActivator.CreateIfNotNeeded(scene); - DestroyImmediate(this); - } - } - else - { - DestroyImmediate(this); - } - } - - internal static void CreateIfNotNeeded(Scene scene) - { - if (!scene.IsValid() || UnityEditor.SceneManagement.EditorSceneManager.IsPreviewScene(scene)) return; - if (UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode) return; - if (GlobalActivator.HasAvatarInScene(scene)) return; - CreateIfNotExists(scene); - } - - internal static void CreateIfNotExists(Scene scene) - { - bool rootPresent = false; - foreach (var root in scene.GetRootGameObjects()) - { - if (root.GetComponent() != null) - { - root.hideFlags = HideFlags; - root.SetActive(true); - if (rootPresent) DestroyImmediate(root); - rootPresent = true; - } - } - - if (rootPresent) return; - - var oldActiveScene = SceneManager.GetActiveScene(); - try - { - SceneManager.SetActiveScene(scene); - var gameObject = new GameObject("ApplyOnPlaySceneChangeReceiver"); - var component = gameObject.AddComponent(); - component.scene = scene; - gameObject.hideFlags = HideFlags; - component.hideFlags = HideFlags; - } - finally - { - SceneManager.SetActiveScene(oldActiveScene); - } - } - - private const HideFlags HideFlags = UnityEngine.HideFlags.HideAndDontSave; -#endif - } -} \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Runtime/SceneChangeReceiver.cs.meta b/Internal/ApplyOnPlay/Runtime/SceneChangeReceiver.cs.meta deleted file mode 100644 index d940e4eb2..000000000 --- a/Internal/ApplyOnPlay/Runtime/SceneChangeReceiver.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 357a344b57c4469c88ba43f2342a4cb1 -timeCreated: 1691823379 \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Runtime/com.anatawa12.avatar-optimizer.internal.apply-on-play.runtime.asmdef b/Internal/ApplyOnPlay/Runtime/com.anatawa12.avatar-optimizer.internal.apply-on-play.runtime.asmdef deleted file mode 100644 index fb0b714d7..000000000 --- a/Internal/ApplyOnPlay/Runtime/com.anatawa12.avatar-optimizer.internal.apply-on-play.runtime.asmdef +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "com.anatawa12.avatar-optimizer.internal.apply-on-play.runtime", - "references": [], - "includePlatforms": [], - "excludePlatforms": [], - "allowUnsafeCode": false, - "overrideReferences": true, - "precompiledReferences": [ - "VRCSDKBase.dll" - ], - "autoReferenced": false, - "defineConstraints": [], - "versionDefines": [], - "noEngineReferences": false -} \ No newline at end of file diff --git a/Internal/ApplyOnPlay/Runtime/com.anatawa12.avatar-optimizer.internal.apply-on-play.runtime.asmdef.meta b/Internal/ApplyOnPlay/Runtime/com.anatawa12.avatar-optimizer.internal.apply-on-play.runtime.asmdef.meta deleted file mode 100644 index 0d859190c..000000000 --- a/Internal/ApplyOnPlay/Runtime/com.anatawa12.avatar-optimizer.internal.apply-on-play.runtime.asmdef.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b1529a8c1c7946769969aca7e2ce5034 -timeCreated: 1689409039 \ No newline at end of file diff --git a/Internal/ErrorReporter/Editor/ErrorReportingInitializerProcessor.cs b/Internal/ErrorReporter/Editor/ErrorReportingInitializerProcessor.cs index 603545a69..95e77f7e3 100644 --- a/Internal/ErrorReporter/Editor/ErrorReportingInitializerProcessor.cs +++ b/Internal/ErrorReporter/Editor/ErrorReportingInitializerProcessor.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Anatawa12.ApplyOnPlay; using UnityEngine; using VRC.SDK3.Avatars.Components; using VRC.SDKBase.Editor.BuildPipeline; @@ -9,15 +8,13 @@ namespace Anatawa12.AvatarOptimizer.ErrorReporting /// /// Initializes Error Reporting System /// - internal class ErrorReportingInitializerProcessor : IVRCSDKPreprocessAvatarCallback, IApplyOnPlayCallback, IManualBakeFinalizer + internal class ErrorReportingInitializerProcessor : IVRCSDKPreprocessAvatarCallback { public int callbackOrder => int.MinValue; public string CallbackName => "Error Reporting Initialization"; public string CallbackId => "com.anatawa12.error-reporting"; - - public bool ApplyOnPlay(GameObject avatarGameObject, ApplyReason reason) => OnPreprocessAvatar(avatarGameObject); - + public bool OnPreprocessAvatar(GameObject avatarGameObject) { BuildReport.Clear();