modular-avatar/Packages/nadena.dev.modular-avatar/Runtime/ModularAvatarMenuItem.cs
bd_ 76edc43aca
feat: menu actions (#231)
Add a new feature to generate animations for menu items automatically.
Currently this only supports generating blend-tree based GameObject toggles.
2023-03-04 14:31:23 +09:00

55 lines
1.7 KiB
C#

using System.Collections.Generic;
using System.Linq;
using nadena.dev.modular_avatar.core.menu;
using UnityEngine;
using UnityEngine.Serialization;
using VRC.SDK3.Avatars.ScriptableObjects;
namespace nadena.dev.modular_avatar.core
{
public enum SubmenuSource
{
MenuAsset,
Children,
}
[AddComponentMenu("Modular Avatar/MA Menu Item")]
public class ModularAvatarMenuItem : MenuSourceComponent
{
public VRCExpressionsMenu.Control Control;
public SubmenuSource MenuSource;
public GameObject menuSource_otherObjectChildren;
[FormerlySerializedAs("toggleGroup")] public ControlGroup controlGroup;
public bool isDefault;
public override void Visit(NodeContext context)
{
var cloned = new VirtualControl(Control);
cloned.subMenu = null;
cloned.name = gameObject.name;
if (cloned.type == VRCExpressionsMenu.Control.ControlType.SubMenu)
{
switch (this.MenuSource)
{
case SubmenuSource.MenuAsset:
cloned.SubmenuNode = context.NodeFor(this.Control.subMenu);
break;
case SubmenuSource.Children:
{
var root = this.menuSource_otherObjectChildren != null
? this.menuSource_otherObjectChildren
: this.gameObject;
cloned.SubmenuNode = context.NodeFor(new MenuNodesUnder(root));
break;
}
}
}
context.PushControl(cloned);
}
}
}