Menu Installer: Default to installing at top level

Closes: #66
This commit is contained in:
bd_ 2022-11-06 19:33:48 -08:00 committed by bd_
parent 2db6e5a213
commit 5081516095
7 changed files with 43 additions and 7 deletions

View File

@ -55,12 +55,17 @@ namespace net.fushizen.modular_avatar.core.editor
var installTo = serializedObject.FindProperty(nameof(ModularAvatarMenuInstaller.installTargetMenu));
var isEnabled = targets.Length != 1 || ((ModularAvatarMenuInstaller) target).enabled;
if (!installTo.hasMultipleDifferentValues)
{
if (installTo.objectReferenceValue == null)
{
if (isEnabled)
{
EditorGUILayout.HelpBox(S("menuinstall.help.hint_set_menu"), MessageType.Info);
}
}
else if (!IsMenuReachable(RuntimeUtil.FindAvatarInParents(((Component) target).transform),
(VRCExpressionsMenu) installTo.objectReferenceValue))
{

View File

@ -1,7 +1,7 @@
{
"boneproxy.foldout.advanced": "Advanced",
"boneproxy.target": "Target",
"menuinstall.help.hint_set_menu": "Select one of your avatar's menus to automatically install controls for this prefab.",
"menuinstall.help.hint_set_menu": "This prefab will be installed to the root menu of your avatar by default. Select a different menu or uncheck the component's enabled checkbox to prevent this.",
"menuinstall.help.hint_bad_menu": "Selected menu asset is not part of your avatar.",
"menuinstall.installto": "Install To",
"menuinstall.installto.tooltip": "The controls for this prefab will be appended to this menu",

View File

@ -1,7 +1,7 @@
{
"boneproxy.foldout.advanced": "詳細設定",
"boneproxy.target": "ターゲット",
"menuinstall.help.hint_set_menu": "アバターのメニューを指定すれば、このプレハブの設定を自動的に該当メニューに導入します。",
"menuinstall.help.hint_set_menu": "このプレハブは自動的にアバターの一番上のメニューに導入されます。不要な場合は別のメニューを指定するか、コンポーネントの有効状態を切ってください。",
"menuinstall.help.hint_bad_menu": "選択されたメニューがアバターに紐づけされていません。",
"menuinstall.installto": "インストール先",
"menuinstall.installto.tooltip": "このプレハブのメニュー項目がこのメニューに追加されます。",

View File

@ -12,15 +12,27 @@ namespace net.fushizen.modular_avatar.core.editor
private Dictionary<VRCExpressionsMenu, VRCExpressionsMenu> _clonedMenus;
private Dictionary<VRCExpressionsMenu, VRCExpressionsMenu> _installTargets;
private VRCExpressionsMenu _rootMenu;
public void OnPreprocessAvatar(GameObject avatarRoot)
{
var menuInstallers = avatarRoot.GetComponentsInChildren<ModularAvatarMenuInstaller>(true);
var menuInstallers = avatarRoot.GetComponentsInChildren<ModularAvatarMenuInstaller>(true)
.Where(c => c.enabled)
.ToArray();
if (menuInstallers.Length == 0) return;
_clonedMenus = new Dictionary<VRCExpressionsMenu, VRCExpressionsMenu>();
var avatar = avatarRoot.GetComponent<VRCAvatarDescriptor>();
if (avatar.expressionsMenu == null)
{
var menu = ScriptableObject.CreateInstance<VRCExpressionsMenu>();
AssetDatabase.CreateAsset(menu, Util.GenerateAssetPath());
avatar.expressionsMenu = menu;
}
_rootMenu = avatar.expressionsMenu;
avatar.expressionsMenu = CloneMenu(avatar.expressionsMenu);
_installTargets = new Dictionary<VRCExpressionsMenu, VRCExpressionsMenu>(_clonedMenus);
@ -32,6 +44,13 @@ namespace net.fushizen.modular_avatar.core.editor
private void InstallMenu(ModularAvatarMenuInstaller installer)
{
if (!installer.enabled) return;
if (installer.installTargetMenu == null)
{
installer.installTargetMenu = _rootMenu;
}
if (installer.installTargetMenu == null || installer.menuToAppend == null) return;
if (!_installTargets.TryGetValue(installer.installTargetMenu, out var targetMenu)) return;
if (_installTargets.ContainsKey(installer.menuToAppend)) return;

View File

@ -150,7 +150,7 @@ namespace net.fushizen.modular_avatar.core.editor
case ModularAvatarMenuInstaller installer:
{
if (installer.menuToAppend != null && installer.installTargetMenu != null)
if (installer.menuToAppend != null && installer.enabled)
{
ProcessMenu(ref installer.menuToAppend, remaps);
}

View File

@ -1,4 +1,6 @@
using VRC.SDK3.Avatars.ScriptableObjects;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
using VRC.SDK3.Avatars.ScriptableObjects;
namespace net.fushizen.modular_avatar.core
{
@ -6,5 +8,12 @@ namespace net.fushizen.modular_avatar.core
{
public VRCExpressionsMenu menuToAppend;
public VRCExpressionsMenu installTargetMenu;
// ReSharper disable once Unity.RedundantEventFunction
void Start()
{
// Ensure that unity generates an enable checkbox
}
}
}

View File

@ -13,10 +13,13 @@ When you have a menu item to add!
### End-users
Click "Select Menu" and double-click the menu you want to install the prefab's controls to. Done!
By default, the prefab's menu will be installed at the top level of your avatar's action menu.
If that's what you want, you're done! Otherwise, click "Select Menu" and double-click the menu you want to install the prefab's controls to.
If the selected menu gets full, it will be automatically split into multiple pages (submenus).
If you want to disable the menu installation entirely, click the disable checkbox in the upper-left of the menu installer inspector.
### Prefab developers
First, create an expressions menu with the controls you want to add. This menu will be _appended_ to a selected submenu of the avatar's Expressions Menu tree.