mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-01 20:25:07 +08:00
Add option to auto-apply on play without av3emu
This commit is contained in:
parent
c1dd24835f
commit
5549332a68
45
Packages/net.fushizen.modular-avatar/Editor/ApplyOnPlay.cs
Normal file
45
Packages/net.fushizen.modular-avatar/Editor/ApplyOnPlay.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 246c8f6cb27c4758972ceac5e8700add
|
||||
timeCreated: 1661822272
|
@ -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
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf636eb59d084fb3ae6ce8277adde230
|
||||
timeCreated: 1661822033
|
Loading…
Reference in New Issue
Block a user