mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2024-12-29 18:55:06 +08:00
ddbc3b164b
* chore: rearrange package structure to have the package at the root * ci: update CI workflows * ci: fixing workflow bugs * ci: recurse building .zip package * ci: more fixes * ci: add back in the nadena.dev VPM repo * ci: fix tests
78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
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")]
|
|
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);
|
|
}
|
|
}
|
|
} |