From 5081516095611587bd2c960b46ac877ec32db707 Mon Sep 17 00:00:00 2001 From: bd_ Date: Sun, 6 Nov 2022 19:33:48 -0800 Subject: [PATCH] Menu Installer: Default to installing at top level Closes: #66 --- .../Editor/Inspector/MenuInstallerEditor.cs | 7 ++++++- .../Editor/Localization/en.json | 2 +- .../Editor/Localization/ja.json | 2 +- .../Editor/MenuInstallHook.cs | 21 ++++++++++++++++++- .../Editor/RenameParametersHook.cs | 2 +- .../Runtime/ModularAvatarMenuInstaller.cs | 11 +++++++++- docs/docs/reference/menu-installer.md | 5 ++++- 7 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Packages/net.fushizen.modular-avatar/Editor/Inspector/MenuInstallerEditor.cs b/Packages/net.fushizen.modular-avatar/Editor/Inspector/MenuInstallerEditor.cs index 89441d20..37b8c0ab 100644 --- a/Packages/net.fushizen.modular-avatar/Editor/Inspector/MenuInstallerEditor.cs +++ b/Packages/net.fushizen.modular-avatar/Editor/Inspector/MenuInstallerEditor.cs @@ -55,11 +55,16 @@ 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) { - EditorGUILayout.HelpBox(S("menuinstall.help.hint_set_menu"), MessageType.Info); + if (isEnabled) + { + EditorGUILayout.HelpBox(S("menuinstall.help.hint_set_menu"), MessageType.Info); + } } else if (!IsMenuReachable(RuntimeUtil.FindAvatarInParents(((Component) target).transform), (VRCExpressionsMenu) installTo.objectReferenceValue)) diff --git a/Packages/net.fushizen.modular-avatar/Editor/Localization/en.json b/Packages/net.fushizen.modular-avatar/Editor/Localization/en.json index cef312d1..3ca34bdf 100644 --- a/Packages/net.fushizen.modular-avatar/Editor/Localization/en.json +++ b/Packages/net.fushizen.modular-avatar/Editor/Localization/en.json @@ -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", diff --git a/Packages/net.fushizen.modular-avatar/Editor/Localization/ja.json b/Packages/net.fushizen.modular-avatar/Editor/Localization/ja.json index d1b29f96..f801520f 100644 --- a/Packages/net.fushizen.modular-avatar/Editor/Localization/ja.json +++ b/Packages/net.fushizen.modular-avatar/Editor/Localization/ja.json @@ -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": "このプレハブのメニュー項目がこのメニューに追加されます。", diff --git a/Packages/net.fushizen.modular-avatar/Editor/MenuInstallHook.cs b/Packages/net.fushizen.modular-avatar/Editor/MenuInstallHook.cs index 0c956895..dc410df3 100644 --- a/Packages/net.fushizen.modular-avatar/Editor/MenuInstallHook.cs +++ b/Packages/net.fushizen.modular-avatar/Editor/MenuInstallHook.cs @@ -12,15 +12,27 @@ namespace net.fushizen.modular_avatar.core.editor private Dictionary _clonedMenus; private Dictionary _installTargets; + private VRCExpressionsMenu _rootMenu; + public void OnPreprocessAvatar(GameObject avatarRoot) { - var menuInstallers = avatarRoot.GetComponentsInChildren(true); + var menuInstallers = avatarRoot.GetComponentsInChildren(true) + .Where(c => c.enabled) + .ToArray(); if (menuInstallers.Length == 0) return; _clonedMenus = new Dictionary(); var avatar = avatarRoot.GetComponent(); + if (avatar.expressionsMenu == null) + { + var menu = ScriptableObject.CreateInstance(); + AssetDatabase.CreateAsset(menu, Util.GenerateAssetPath()); + avatar.expressionsMenu = menu; + } + + _rootMenu = avatar.expressionsMenu; avatar.expressionsMenu = CloneMenu(avatar.expressionsMenu); _installTargets = new Dictionary(_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; diff --git a/Packages/net.fushizen.modular-avatar/Editor/RenameParametersHook.cs b/Packages/net.fushizen.modular-avatar/Editor/RenameParametersHook.cs index 051b328c..d91d4d04 100644 --- a/Packages/net.fushizen.modular-avatar/Editor/RenameParametersHook.cs +++ b/Packages/net.fushizen.modular-avatar/Editor/RenameParametersHook.cs @@ -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); } diff --git a/Packages/net.fushizen.modular-avatar/Runtime/ModularAvatarMenuInstaller.cs b/Packages/net.fushizen.modular-avatar/Runtime/ModularAvatarMenuInstaller.cs index f1fa8e96..1149224c 100644 --- a/Packages/net.fushizen.modular-avatar/Runtime/ModularAvatarMenuInstaller.cs +++ b/Packages/net.fushizen.modular-avatar/Runtime/ModularAvatarMenuInstaller.cs @@ -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 + } } } \ No newline at end of file diff --git a/docs/docs/reference/menu-installer.md b/docs/docs/reference/menu-installer.md index 4bff748c..ee858eb4 100644 --- a/docs/docs/reference/menu-installer.md +++ b/docs/docs/reference/menu-installer.md @@ -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.