Add option to auto-apply on play without av3emu

This commit is contained in:
bd_ 2022-08-29 18:34:22 -07:00
parent c1dd24835f
commit 5549332a68
4 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,45 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using VRC.SDK3.Avatars.Components;
using VRC.SDKBase.Editor.BuildPipeline;
namespace net.fushizen.modular_avatar.core.editor
{
[InitializeOnLoad]
public static class ApplyOnPlay
{
private const string MENU_NAME = "Tools/Modular Avatar/Apply on Play";
static ApplyOnPlay()
{
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
Menu.SetChecked(MENU_NAME, ModularAvatarSettings.applyOnPlay);
}
[MenuItem(MENU_NAME)]
private static void ToggleApplyOnPlay()
{
ModularAvatarSettings.applyOnPlay = !ModularAvatarSettings.applyOnPlay;
Menu.SetChecked(MENU_NAME, ModularAvatarSettings.applyOnPlay);
}
private static void OnPlayModeStateChanged(PlayModeStateChange obj)
{
if (obj == PlayModeStateChange.EnteredPlayMode && ModularAvatarSettings.applyOnPlay)
{
// TODO - only apply modular avatar changes?
foreach (var root in SceneManager.GetActiveScene().GetRootGameObjects())
{
foreach (var avatar in root.GetComponentsInChildren<VRCAvatarDescriptor>(true))
{
if (avatar.GetComponentsInChildren<AvatarTagComponent>(true).Length > 0)
{
VRCBuildPipelineCallbacks.OnPreprocessAvatar(avatar.gameObject);
}
}
}
}
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 246c8f6cb27c4758972ceac5e8700add
timeCreated: 1661822272

View File

@ -0,0 +1,19 @@
using UnityEditor;
using UnityEngine;
namespace net.fushizen.modular_avatar.core.editor
{
public static class ModularAvatarSettings
{
private const string PREFKEY_APPLY_ON_PLAY = "net.fushizen.modular-avatar.applyOnPlay";
#if UNITY_EDITOR
public static bool applyOnPlay
{
get => EditorPrefs.GetBool(PREFKEY_APPLY_ON_PLAY, true);
set => EditorPrefs.SetBool(PREFKEY_APPLY_ON_PLAY, value);
}
#else
public static bool applyOnPlay = false;
#endif
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bf636eb59d084fb3ae6ce8277adde230
timeCreated: 1661822033