modular-avatar/Runtime/ModularAvatarMenuItem.cs
kaikoga 3667dc319a
chore: Wrap VRC dependencies and VRCAvatarDescriptors (#504)
* add version defines

* refactor: prefer BuildContext.ctor() overload taking GameObject

* wrap unit tests entirely with MA_VRCSDK3_AVATARS

* wrap unit tests smart with MA_VRCSDK3_AVATARS

* wrap runtime entirely with MA_VRCSDK3_AVATARS

* wrap VRC.SDKBase.IEditorOnly with MA_VRCSDK3_AVATARS

* wrap editor entirely with MA_VRCSDK3_AVATARS

* fix AvatarObjectReference.Get(Component)

* wrap editor smart with MA_VRCSDK3_AVATARS

* wrap BuildContext smart with MA_VRCSDK3_AVATARS

* wrap PluginDefinition smart with MA_VRCSDK3_AVATARS

* style: move conditional compiles one step outside
2023-11-10 15:37:56 +09:00

83 lines
2.3 KiB
C#

#if MA_VRCSDK3_AVATARS
using nadena.dev.modular_avatar.core.menu;
using UnityEngine;
using VRC.SDK3.Avatars.ScriptableObjects;
namespace nadena.dev.modular_avatar.core
{
public enum SubmenuSource
{
MenuAsset,
Children,
}
[AddComponentMenu("Modular Avatar/MA Menu Item")]
[HelpURL("https://modular-avatar.nadena.dev/docs/reference/menu-item?lang=auto")]
public class ModularAvatarMenuItem : AvatarTagComponent, MenuSource
{
public VRCExpressionsMenu.Control Control;
public SubmenuSource MenuSource;
public GameObject menuSource_otherObjectChildren;
/// <summary>
/// If no control group is set (and an action is linked), this controls whether this control is synced.
/// </summary>
public bool isSynced = true;
public bool isSaved = true;
protected override void OnValidate()
{
base.OnValidate();
RuntimeUtil.InvalidateMenu();
if (Control == null)
{
Control = new VRCExpressionsMenu.Control();
}
}
public override void ResolveReferences()
{
// no-op
}
public void Visit(NodeContext context)
{
if (Control == null)
{
Control = new VRCExpressionsMenu.Control();
}
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);
}
}
}
#endif