fix: multiple issues in autocreate parameter heuristics (#1032)

- Don't create parameters for submenus and puppets automatically
- Create parameters when the menu item and RC are on the same GameObject
This commit is contained in:
bd_ 2024-08-21 21:16:40 -07:00 committed by GitHub
parent f44e070c46
commit 037c450760
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,19 +13,32 @@ namespace nadena.dev.modular_avatar.core.editor
{ {
internal static bool ShouldAssignParametersToMami(ModularAvatarMenuItem item) internal static bool ShouldAssignParametersToMami(ModularAvatarMenuItem item)
{ {
bool hasRC = false; switch (item?.Control?.type)
{
case VRCExpressionsMenu.Control.ControlType.Button:
case VRCExpressionsMenu.Control.ControlType.Toggle:
// ok
break;
default:
return false;
}
foreach (var rc in item.GetComponentsInChildren<ReactiveComponent>(true)) foreach (var rc in item.GetComponentsInChildren<ReactiveComponent>(true))
{ {
// Only track components where this is the closest parent // Only track components where this is the closest parent
if (rc.transform == item.transform)
{
return true;
}
var parentMami = rc.GetComponentInParent<ModularAvatarMenuItem>(); var parentMami = rc.GetComponentInParent<ModularAvatarMenuItem>();
if (parentMami == item) if (parentMami == item)
{ {
hasRC = true; return true;
break;
} }
} }
return hasRC; return false;
} }
protected override void Execute(ndmf.BuildContext context) protected override void Execute(ndmf.BuildContext context)
@ -107,7 +120,7 @@ namespace nadena.dev.modular_avatar.core.editor
internal static ControlCondition AssignMenuItemParameter(ModularAvatarMenuItem mami) internal static ControlCondition AssignMenuItemParameter(ModularAvatarMenuItem mami)
{ {
if (mami?.Control?.parameter?.name == null) return null; if (string.IsNullOrWhiteSpace(mami?.Control?.parameter?.name)) return null;
return new ControlCondition return new ControlCondition
{ {