mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-02-06 22:02:48 +08:00
fix: add "add menu item" button
This commit is contained in:
parent
7d97c75ef8
commit
023e8266ec
@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using nadena.dev.modular_avatar.core.menu;
|
using nadena.dev.modular_avatar.core.menu;
|
||||||
|
using static nadena.dev.modular_avatar.core.editor.Localization;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using VRC.SDK3.Avatars.ScriptableObjects;
|
using VRC.SDK3.Avatars.ScriptableObjects;
|
||||||
@ -168,6 +169,14 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
|
|
||||||
public void PushNode(MenuSource source)
|
public void PushNode(MenuSource source)
|
||||||
{
|
{
|
||||||
|
var originalSource = source;
|
||||||
|
if (source is ModularAvatarMenuGroup group)
|
||||||
|
{
|
||||||
|
// Avoid calling source.Visit as this results in an extra MenuObjectHeader
|
||||||
|
// TODO: Avoid this unnecessary header in a cleaner way?
|
||||||
|
source = new MenuNodesUnder(group.targetObject != null ? group.targetObject : group.gameObject);
|
||||||
|
}
|
||||||
|
|
||||||
if (source is ModularAvatarMenuItem item)
|
if (source is ModularAvatarMenuItem item)
|
||||||
{
|
{
|
||||||
_gui.PushGuiNode(item, () =>
|
_gui.PushGuiNode(item, () =>
|
||||||
@ -186,12 +195,24 @@ namespace nadena.dev.modular_avatar.core.editor
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
using (new MenuObjectHeader(source as UnityEngine.Object).Scope())
|
using (new MenuObjectHeader(originalSource as UnityEngine.Object).Scope())
|
||||||
{
|
{
|
||||||
if (_visited.Contains(source)) return;
|
if (_visited.Contains(originalSource)) return;
|
||||||
_visited.Add(source);
|
_visited.Add(originalSource);
|
||||||
|
|
||||||
source.Visit(this);
|
source.Visit(this);
|
||||||
|
|
||||||
|
if (source is MenuNodesUnder nodesUnder)
|
||||||
|
{
|
||||||
|
if (GUILayout.Button(G("menuitem.misc.add_item")))
|
||||||
|
{
|
||||||
|
var newChild = new GameObject();
|
||||||
|
newChild.name = "New item";
|
||||||
|
newChild.transform.SetParent(nodesUnder.root.transform, false);
|
||||||
|
newChild.AddComponent<ModularAvatarMenuItem>();
|
||||||
|
Undo.RegisterCreatedObjectUndo(newChild, "Added menu item");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,5 +118,6 @@
|
|||||||
"menuitem.prop.control_group.tooltip": "Only one toggle in a given group can be selected at the same time",
|
"menuitem.prop.control_group.tooltip": "Only one toggle in a given group can be selected at the same time",
|
||||||
"menuitem.prop.is_default": "Is Group Default",
|
"menuitem.prop.is_default": "Is Group Default",
|
||||||
"animation_gen.duplicate_binding": "Controls from different control groups are trying to animate the same parameter. Parameter: {0}",
|
"animation_gen.duplicate_binding": "Controls from different control groups are trying to animate the same parameter. Parameter: {0}",
|
||||||
"animation_gen.multiple_defaults": "Multiple default menu items were found in the same control group."
|
"animation_gen.multiple_defaults": "Multiple default menu items were found in the same control group.",
|
||||||
|
"menuitem.misc.add_item": "Add menu item"
|
||||||
}
|
}
|
@ -115,5 +115,6 @@
|
|||||||
"menuitem.prop.control_group.tooltip": "同じグループ内では、一つのトグルしか起動できません",
|
"menuitem.prop.control_group.tooltip": "同じグループ内では、一つのトグルしか起動できません",
|
||||||
"menuitem.prop.is_default": "グループの初期設定にする",
|
"menuitem.prop.is_default": "グループの初期設定にする",
|
||||||
"animation_gen.duplicate_binding": "別々のコントロールグループから、同じパラメーターが操作されています。パラメーター:{0}",
|
"animation_gen.duplicate_binding": "別々のコントロールグループから、同じパラメーターが操作されています。パラメーター:{0}",
|
||||||
"animation_gen.multiple_defaults": "同じコントロールグループに初期設定に指定されたメニューアイテムが複数あります。"
|
"animation_gen.multiple_defaults": "同じコントロールグループに初期設定に指定されたメニューアイテムが複数あります。",
|
||||||
|
"menuitem.misc.add_item": "メニューアイテムを追加"
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,23 @@ namespace nadena.dev.modular_avatar.core
|
|||||||
[FormerlySerializedAs("toggleGroup")] public ControlGroup controlGroup;
|
[FormerlySerializedAs("toggleGroup")] public ControlGroup controlGroup;
|
||||||
public bool isDefault;
|
public bool isDefault;
|
||||||
|
|
||||||
|
protected override void OnValidate()
|
||||||
|
{
|
||||||
|
base.OnValidate();
|
||||||
|
|
||||||
|
if (Control == null)
|
||||||
|
{
|
||||||
|
Control = new VRCExpressionsMenu.Control();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void Visit(NodeContext context)
|
public override void Visit(NodeContext context)
|
||||||
{
|
{
|
||||||
|
if (Control == null)
|
||||||
|
{
|
||||||
|
Control = new VRCExpressionsMenu.Control();
|
||||||
|
}
|
||||||
|
|
||||||
var cloned = new VirtualControl(Control);
|
var cloned = new VirtualControl(Control);
|
||||||
cloned.subMenu = null;
|
cloned.subMenu = null;
|
||||||
cloned.name = gameObject.name;
|
cloned.name = gameObject.name;
|
||||||
|
Loading…
Reference in New Issue
Block a user