menu item UI - integration with actions for base parameters

This commit is contained in:
bd_ 2023-02-28 23:36:15 +09:00
parent 4f5feeb1b9
commit ed1ae08d04
2 changed files with 60 additions and 9 deletions

View File

@ -3,8 +3,10 @@ using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using Codice.CM.Common.Tree.Partial; using Codice.CM.Common.Tree.Partial;
using nadena.dev.modular_avatar.core.menu; using nadena.dev.modular_avatar.core.menu;
using NUnit.Framework;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements;
using VRC.SDK3.Avatars.ScriptableObjects; using VRC.SDK3.Avatars.ScriptableObjects;
using static nadena.dev.modular_avatar.core.editor.Localization; using static nadena.dev.modular_avatar.core.editor.Localization;
@ -29,6 +31,8 @@ namespace nadena.dev.modular_avatar.core.editor
private readonly SerializedProperty _type; private readonly SerializedProperty _type;
private readonly SerializedProperty _value; private readonly SerializedProperty _value;
private readonly SerializedProperty _submenu; private readonly SerializedProperty _submenu;
private readonly SerializedProperty _toggleGroup;
private readonly SerializedProperty _isDefault;
private readonly ParameterGUI _parameterGUI; private readonly ParameterGUI _parameterGUI;
@ -48,6 +52,15 @@ namespace nadena.dev.modular_avatar.core.editor
public bool AlwaysExpandContents = false; public bool AlwaysExpandContents = false;
public bool ExpandContents = false; public bool ExpandContents = false;
private bool _hasActions;
private bool HasActions()
{
return _toggleGroup != null && _obj.targetObjects.Any(o =>
o is ModularAvatarMenuItem c && c.GetComponent<MenuAction>() != null
);
}
public MenuItemCoreGUI(SerializedObject obj, Action redraw) public MenuItemCoreGUI(SerializedObject obj, Action redraw)
{ {
_obj = obj; _obj = obj;
@ -68,6 +81,9 @@ namespace nadena.dev.modular_avatar.core.editor
); );
_name = gameObjects.FindProperty("m_Name"); _name = gameObjects.FindProperty("m_Name");
_toggleGroup = obj.FindProperty(nameof(ModularAvatarMenuItem.toggleGroup));
_isDefault = obj.FindProperty(nameof(ModularAvatarMenuItem.isDefault));
var control = obj.FindProperty(nameof(ModularAvatarMenuItem.Control)); var control = obj.FindProperty(nameof(ModularAvatarMenuItem.Control));
_texture = control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.icon)); _texture = control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.icon));
@ -87,6 +103,12 @@ namespace nadena.dev.modular_avatar.core.editor
_previewGUI = new MenuPreviewGUI(redraw); _previewGUI = new MenuPreviewGUI(redraw);
} }
/// <summary>
/// Builds a menu item GUI for a raw VRCExpressionsMenu.Control reference.
/// </summary>
/// <param name="parameterReference"></param>
/// <param name="_control"></param>
/// <param name="redraw"></param>
public MenuItemCoreGUI(GameObject parameterReference, SerializedProperty _control, Action redraw) public MenuItemCoreGUI(GameObject parameterReference, SerializedProperty _control, Action redraw)
{ {
_obj = _control.serializedObject; _obj = _control.serializedObject;
@ -100,6 +122,9 @@ namespace nadena.dev.modular_avatar.core.editor
_value = _control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.value)); _value = _control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.value));
_submenu = _control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.subMenu)); _submenu = _control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.subMenu));
_toggleGroup = null;
_isDefault = null;
_parameterGUI = new ParameterGUI(parameterReference, parameter, redraw); _parameterGUI = new ParameterGUI(parameterReference, parameter, redraw);
_subParamsRoot = _control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.subParameters)); _subParamsRoot = _control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.subParameters));
@ -112,15 +137,32 @@ namespace nadena.dev.modular_avatar.core.editor
public void DoGUI() public void DoGUI()
{ {
_hasActions = HasActions();
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
EditorGUILayout.BeginVertical(); EditorGUILayout.BeginVertical();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(_name, G("menuitem.prop.name")); EditorGUILayout.PropertyField(_name, G("menuitem.prop.name"));
if (EditorGUI.EndChangeCheck())
{
_name.serializedObject.ApplyModifiedProperties();
}
EditorGUILayout.PropertyField(_texture, G("menuitem.prop.icon")); EditorGUILayout.PropertyField(_texture, G("menuitem.prop.icon"));
EditorGUILayout.PropertyField(_type, G("menuitem.prop.type")); EditorGUILayout.PropertyField(_type, G("menuitem.prop.type"));
EditorGUILayout.PropertyField(_value, G("menuitem.prop.value")); EditorGUILayout.PropertyField(_value, G("menuitem.prop.value"));
_parameterGUI.DoGUI(); if (_hasActions)
{
EditorGUILayout.PropertyField(_toggleGroup);
using (new EditorGUI.DisabledScope(_obj.isEditingMultipleObjects))
{
EditorGUILayout.PropertyField(_isDefault);
}
}
_parameterGUI.DoGUI(!_hasActions);
EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical();
@ -244,7 +286,7 @@ namespace nadena.dev.modular_avatar.core.editor
{ {
EnsureParameterCount(1); EnsureParameterCount(1);
_subParams[0].DoGUI(G("menuitem.param.rotation")); _subParams[0].DoGUI(true, G("menuitem.param.rotation"));
break; break;
} }
@ -256,8 +298,8 @@ namespace nadena.dev.modular_avatar.core.editor
EditorGUILayout.LabelField("Parameters", EditorStyles.boldLabel); EditorGUILayout.LabelField("Parameters", EditorStyles.boldLabel);
EditorGUILayout.Space(2); EditorGUILayout.Space(2);
_subParams[0].DoGUI(G("menuitem.param.horizontal")); _subParams[0].DoGUI(true, G("menuitem.param.horizontal"));
_subParams[1].DoGUI(G("menuitem.param.vertical")); _subParams[1].DoGUI(true, G("menuitem.param.vertical"));
DoFourAxisLabels(false); DoFourAxisLabels(false);
@ -384,7 +426,7 @@ namespace nadena.dev.modular_avatar.core.editor
EditorGUI.PropertyField(rect_name, prop_name, GUIContent.none); EditorGUI.PropertyField(rect_name, prop_name, GUIContent.none);
if (showParams) if (showParams)
{ {
_subParams[index].DoGUI(rect_param, GUIContent.none); _subParams[index].DoGUI(rect_param, true, GUIContent.none);
} }
var tex = prop_icon.objectReferenceValue as Texture; var tex = prop_icon.objectReferenceValue as Texture;

View File

@ -23,17 +23,26 @@ namespace nadena.dev.modular_avatar.core.editor
_redraw = redraw; _redraw = redraw;
} }
public void DoGUI(GUIContent label = null) public void DoGUI(bool enabled = true, GUIContent label = null)
{ {
DoGUI(EditorGUILayout.GetControlRect( DoGUI(EditorGUILayout.GetControlRect(
true, true,
EditorGUIUtility.singleLineHeight EditorGUIUtility.singleLineHeight
), label); ), enabled, label);
} }
public void DoGUI(Rect rect, GUIContent label = null) public void DoGUI(Rect rect, bool enabled = true, GUIContent label = null)
{ {
if (label == null) label = G("menuitem.prop.parameter"); label = label ?? G("menuitem.prop.parameter");
if (!enabled)
{
using (new EditorGUI.DisabledScope(true))
{
EditorGUI.TextField(rect, label, "<controlled by action>");
return;
}
}
if (_parameterReference != null) GUILayout.Space(-2); if (_parameterReference != null) GUILayout.Space(-2);
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();