From 0d50a7e8483d97e03cae8050732df83eba33f31f Mon Sep 17 00:00:00 2001 From: yum Date: Wed, 19 Feb 2025 16:16:39 -0800 Subject: Menus no longer implicitly go under /YOTS --- Scripts/YOTSCore.cs | 35 +++++++++++++++-------------------- Scripts/YOTSNDMFGenerator.cs | 14 +++++++++++++- 2 files changed, 28 insertions(+), 21 deletions(-) (limited to 'Scripts') diff --git a/Scripts/YOTSCore.cs b/Scripts/YOTSCore.cs index 4ec3343..e7608e4 100644 --- a/Scripts/YOTSCore.cs +++ b/Scripts/YOTSCore.cs @@ -45,7 +45,7 @@ namespace YOTS // /YOTS. So if you put "Clothes" here, it'll be placed under // /YOTS/Clothes. [SerializeField] - public string menuPath = "/"; + public string menuPath = "/YOTS"; // The default value of the toggle. Range from 0-1. // For example, if you want a gimmick to start toggled off, set this to @@ -818,6 +818,7 @@ namespace YOTS .Select(g => g.First()) .ToList(); + // Update parameters var paramList = new List(); paramList.AddRange(vrcParams.parameters.Where(p => !uniqueToggles.Any(t => t.name == p.name))); foreach (var toggle in uniqueToggles) { @@ -830,22 +831,23 @@ namespace YOTS }); } vrcParams.parameters = paramList.ToArray(); - vrcMenu.controls.RemoveAll(c => c.name == "YOTS"); - // Create YOTS submenu - VRCExpressionsMenu yotsSubmenu = ScriptableObject.CreateInstance(); - yotsSubmenu.name = "YOTS"; - yotsSubmenu.controls = new List(); + + // Add toggles to menu foreach (var toggle in toggleSpecs) { - VRCExpressionsMenu currentMenu = yotsSubmenu; - // Recursively create menus until we wind up at the leaf. - if (!string.IsNullOrEmpty(toggle.menuPath) && toggle.menuPath != "/") { + VRCExpressionsMenu currentMenu = vrcMenu; + + // Navigate or create menu path if specified + if (!string.IsNullOrEmpty(toggle.menuPath)) { string trimmedPath = toggle.menuPath.Trim('/'); - var sections = trimmedPath.Split('/'); - foreach (var section in sections) { - currentMenu = GetOrCreateSubmenu(currentMenu, section); + if (!string.IsNullOrEmpty(trimmedPath)) { + var sections = trimmedPath.Split('/'); + foreach (var section in sections) { + currentMenu = GetOrCreateSubmenu(currentMenu, section); + } } } - // Add toggle. + + // Add toggle control if (toggle.type == "radial") { currentMenu.controls.Add(new VRCExpressionsMenu.Control{ name = toggle.name, @@ -863,13 +865,6 @@ namespace YOTS }); } } - - // Add YOTS submenu to main menu. - vrcMenu.controls.Add(new VRCExpressionsMenu.Control{ - name = "YOTS", - type = VRCExpressionsMenu.Control.ControlType.SubMenu, - subMenu = yotsSubmenu - }); } } } diff --git a/Scripts/YOTSNDMFGenerator.cs b/Scripts/YOTSNDMFGenerator.cs index 525953c..602c247 100644 --- a/Scripts/YOTSNDMFGenerator.cs +++ b/Scripts/YOTSNDMFGenerator.cs @@ -90,7 +90,7 @@ namespace YOTS return; } // Create copies so the originals don't get modified - menu = UnityEngine.Object.Instantiate(menu); + menu = DeepCopyMenu(menu); parameters = UnityEngine.Object.Instantiate(parameters); descriptor.expressionsMenu = menu; descriptor.expressionParameters = parameters; @@ -166,6 +166,18 @@ namespace YOTS private class YOTSBuildState { public string jsonConfig; } + + private static VRCExpressionsMenu DeepCopyMenu(VRCExpressionsMenu sourceMenu) { + var copiedMenu = UnityEngine.Object.Instantiate(sourceMenu); + // Deep copy all submenu references + for (int i = 0; i < copiedMenu.controls.Count; i++) { + var control = copiedMenu.controls[i]; + if (control.type == VRCExpressionsMenu.Control.ControlType.SubMenu) { + control.subMenu = DeepCopyMenu(control.subMenu); + } + } + return copiedMenu; + } } } -- cgit v1.2.3