mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-04-24 13:29:01 +08:00
chore: menuMap as a global variable
This commit is contained in:
parent
e2afd2f1e7
commit
90361afdda
@ -235,6 +235,8 @@ namespace nadena.dev.modular_avatar.core.editor.menu
|
|||||||
|
|
||||||
private Dictionary<object, VirtualMenuNode> _resolvedMenu = new Dictionary<object, VirtualMenuNode>();
|
private Dictionary<object, VirtualMenuNode> _resolvedMenu = new Dictionary<object, VirtualMenuNode>();
|
||||||
|
|
||||||
|
private Dictionary<ObjectReference, VRCExpressionsMenu> _menuMap = new Dictionary<ObjectReference, VRCExpressionsMenu>();
|
||||||
|
|
||||||
// TODO: immutable?
|
// TODO: immutable?
|
||||||
public Dictionary<object, VirtualMenuNode> ResolvedMenu => _resolvedMenu;
|
public Dictionary<object, VirtualMenuNode> ResolvedMenu => _resolvedMenu;
|
||||||
public VirtualMenuNode RootMenuNode => ResolvedMenu[RootMenuKey];
|
public VirtualMenuNode RootMenuNode => ResolvedMenu[RootMenuKey];
|
||||||
@ -274,11 +276,10 @@ namespace nadena.dev.modular_avatar.core.editor.menu
|
|||||||
{
|
{
|
||||||
var menu = new VirtualMenu(avatar.expressionsMenu, context);
|
var menu = new VirtualMenu(avatar.expressionsMenu, context);
|
||||||
|
|
||||||
var menuMap = new Dictionary<ObjectReference, VRCExpressionsMenu>();
|
|
||||||
void GetMenuReferences(VRCExpressionsMenu exMenu)
|
void GetMenuReferences(VRCExpressionsMenu exMenu)
|
||||||
{
|
{
|
||||||
if (!exMenu || menuMap.ContainsValue(exMenu)) return;
|
if (!exMenu || menu._menuMap.ContainsValue(exMenu)) return;
|
||||||
menuMap[ObjectRegistry.GetReference(exMenu)] = exMenu;
|
menu._menuMap[ObjectRegistry.GetReference(exMenu)] = exMenu;
|
||||||
foreach (var control in exMenu.controls)
|
foreach (var control in exMenu.controls)
|
||||||
{
|
{
|
||||||
if(control.type == VRCExpressionsMenu.Control.ControlType.SubMenu)
|
if(control.type == VRCExpressionsMenu.Control.ControlType.SubMenu)
|
||||||
@ -289,7 +290,7 @@ namespace nadena.dev.modular_avatar.core.editor.menu
|
|||||||
|
|
||||||
foreach (var installer in avatar.GetComponentsInChildren<ModularAvatarMenuInstaller>(true))
|
foreach (var installer in avatar.GetComponentsInChildren<ModularAvatarMenuInstaller>(true))
|
||||||
{
|
{
|
||||||
menu.RegisterMenuInstaller(installer, menuMap);
|
menu.RegisterMenuInstaller(installer);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var target in avatar.GetComponentsInChildren<ModularAvatarMenuInstallTarget>(true))
|
foreach (var target in avatar.GetComponentsInChildren<ModularAvatarMenuInstallTarget>(true))
|
||||||
@ -321,13 +322,13 @@ namespace nadena.dev.modular_avatar.core.editor.menu
|
|||||||
/// determine the effects of this menu installer, further processing is deferred until we freeze the menu.
|
/// determine the effects of this menu installer, further processing is deferred until we freeze the menu.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="installer"></param>
|
/// <param name="installer"></param>
|
||||||
internal void RegisterMenuInstaller(ModularAvatarMenuInstaller installer, Dictionary<ObjectReference, VRCExpressionsMenu> menuMap)
|
internal void RegisterMenuInstaller(ModularAvatarMenuInstaller installer)
|
||||||
{
|
{
|
||||||
// initial validation
|
// initial validation
|
||||||
if (installer.menuToAppend == null && installer.GetComponent<MenuSource>() == null) return;
|
if (installer.menuToAppend == null && installer.GetComponent<MenuSource>() == null) return;
|
||||||
|
|
||||||
var installTargetMenu = installer.installTargetMenu &&
|
var installTargetMenu = installer.installTargetMenu &&
|
||||||
menuMap.TryGetValue(ObjectRegistry.GetReference(installer.installTargetMenu), out var currentMenu) ?
|
_menuMap.TryGetValue(ObjectRegistry.GetReference(installer.installTargetMenu), out var currentMenu) ?
|
||||||
currentMenu : installer.installTargetMenu;
|
currentMenu : installer.installTargetMenu;
|
||||||
|
|
||||||
var target = installTargetMenu ? (object) installTargetMenu : RootMenuKey;
|
var target = installTargetMenu ? (object) installTargetMenu : RootMenuKey;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user