2023-02-21 19:47:10 +09:00
|
|
|
|
using System;
|
2023-02-23 20:51:24 +09:00
|
|
|
|
using System.Collections.Generic;
|
2023-02-21 19:47:10 +09:00
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using VRC.SDK3.Avatars.ScriptableObjects;
|
|
|
|
|
|
|
|
|
|
namespace nadena.dev.modular_avatar.core.editor
|
|
|
|
|
{
|
2023-02-22 20:59:40 +09:00
|
|
|
|
[CustomEditor(typeof(ModularAvatarMenuItem))]
|
2023-02-21 19:47:10 +09:00
|
|
|
|
internal class MAMenuItemInspector : MAEditorBase
|
|
|
|
|
{
|
|
|
|
|
private SerializedProperty prop_submenu_source;
|
|
|
|
|
private SerializedProperty prop_control;
|
2023-02-23 21:29:11 +09:00
|
|
|
|
private SerializedProperty prop_extMenu;
|
2023-02-21 19:47:10 +09:00
|
|
|
|
private SerializedProperty prop_otherObjChildren;
|
|
|
|
|
|
2023-02-23 20:51:24 +09:00
|
|
|
|
private MenuItemCoreGUI _coreGUI;
|
|
|
|
|
|
|
|
|
|
private Dictionary<ModularAvatarMenuItem, MenuItemCoreGUI> _innerItemGUI =
|
|
|
|
|
new Dictionary<ModularAvatarMenuItem, MenuItemCoreGUI>();
|
|
|
|
|
|
2023-02-23 21:29:11 +09:00
|
|
|
|
private List<MenuItemCoreGUI> _expMenuInnerItemGUI = new List<MenuItemCoreGUI>();
|
|
|
|
|
private VRCExpressionsMenu _lastExpMenu;
|
|
|
|
|
|
2023-02-21 19:47:10 +09:00
|
|
|
|
void OnEnable()
|
|
|
|
|
{
|
2023-02-23 20:51:24 +09:00
|
|
|
|
_coreGUI = new MenuItemCoreGUI(serializedObject, Repaint);
|
|
|
|
|
|
2023-02-22 20:59:40 +09:00
|
|
|
|
prop_submenu_source = serializedObject.FindProperty(nameof(ModularAvatarMenuItem.MenuSource));
|
2023-02-23 20:51:24 +09:00
|
|
|
|
prop_control = serializedObject.FindProperty(nameof(ModularAvatarMenuItem.Control));
|
2023-02-23 21:29:11 +09:00
|
|
|
|
prop_extMenu = prop_control.FindPropertyRelative(nameof(ModularAvatarMenuItem.Control.subMenu));
|
2023-02-22 20:59:40 +09:00
|
|
|
|
prop_otherObjChildren =
|
|
|
|
|
serializedObject.FindProperty(nameof(ModularAvatarMenuItem.menuSource_otherObjectChildren));
|
2023-02-21 19:47:10 +09:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-23 20:51:24 +09:00
|
|
|
|
private void DrawControlSettings(ModularAvatarMenuItem item)
|
2023-02-21 19:47:10 +09:00
|
|
|
|
{
|
2023-02-23 20:51:24 +09:00
|
|
|
|
if (!_innerItemGUI.TryGetValue(item, out var gui))
|
2023-02-21 19:47:10 +09:00
|
|
|
|
{
|
2023-02-23 20:51:24 +09:00
|
|
|
|
gui = new MenuItemCoreGUI(new SerializedObject(item), Repaint);
|
|
|
|
|
_innerItemGUI.Add(item, gui);
|
2023-02-21 19:47:10 +09:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-23 20:51:24 +09:00
|
|
|
|
gui.DoGUI();
|
2023-02-21 19:47:10 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnInnerInspectorGUI()
|
|
|
|
|
{
|
|
|
|
|
bool multiEdit = targets.Length != 1;
|
|
|
|
|
|
|
|
|
|
serializedObject.Update();
|
|
|
|
|
|
2023-02-23 20:51:24 +09:00
|
|
|
|
_coreGUI.DoGUI();
|
2023-02-21 19:47:10 +09:00
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
|
|
|
|
|
|
|
|
if (multiEdit) return;
|
|
|
|
|
|
2023-02-22 20:59:40 +09:00
|
|
|
|
var menuItem = (ModularAvatarMenuItem) target;
|
2023-02-21 19:47:10 +09:00
|
|
|
|
if (menuItem.Control.type == VRCExpressionsMenu.Control.ControlType.SubMenu)
|
|
|
|
|
{
|
|
|
|
|
GUILayout.Space(EditorStyles.label.lineHeight);
|
|
|
|
|
EditorGUILayout.LabelField("Sub Menu", EditorStyles.boldLabel);
|
|
|
|
|
EditorGUILayout.PropertyField(prop_submenu_source);
|
|
|
|
|
|
|
|
|
|
if (prop_submenu_source.enumValueIndex == (int) SubmenuSource.Children)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (menuItem.MenuSource)
|
|
|
|
|
{
|
2023-02-23 21:29:11 +09:00
|
|
|
|
case SubmenuSource.MenuAsset:
|
|
|
|
|
{
|
|
|
|
|
EditorGUILayout.PropertyField(prop_extMenu);
|
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
|
|
|
|
|
|
|
|
var expMenu = prop_extMenu.objectReferenceValue as VRCExpressionsMenu;
|
|
|
|
|
|
|
|
|
|
if (expMenu == null || expMenu.controls == null)
|
|
|
|
|
{
|
|
|
|
|
_expMenuInnerItemGUI.Clear();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_lastExpMenu != expMenu || _expMenuInnerItemGUI.Count != expMenu.controls.Count)
|
|
|
|
|
{
|
|
|
|
|
_expMenuInnerItemGUI.Clear();
|
|
|
|
|
|
|
|
|
|
var expMenuSO = new SerializedObject(expMenu);
|
|
|
|
|
var controls = expMenuSO.FindProperty(nameof(expMenu.controls));
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < controls.arraySize; i++)
|
|
|
|
|
{
|
|
|
|
|
var control = controls.GetArrayElementAtIndex(i);
|
|
|
|
|
var gui = new MenuItemCoreGUI(((ModularAvatarMenuItem) target).gameObject, control,
|
|
|
|
|
Repaint);
|
|
|
|
|
_expMenuInnerItemGUI.Add(gui);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_lastExpMenu = expMenu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var gui in _expMenuInnerItemGUI)
|
|
|
|
|
{
|
|
|
|
|
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
|
|
|
|
|
|
|
|
|
|
gui.DoGUI();
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndVertical();
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-24 19:29:31 +09:00
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
|
|
|
|
|
|
|
|
if (expMenu != null && GUILayout.Button("Extract menu to children"))
|
|
|
|
|
{
|
|
|
|
|
MenuExtractor.ExtractSingleLayerMenu(expMenu, menuItem.gameObject);
|
|
|
|
|
Undo.RecordObject(menuItem, "Extract menu");
|
|
|
|
|
menuItem.Control.subMenu = null;
|
|
|
|
|
menuItem.MenuSource = SubmenuSource.Children;
|
|
|
|
|
serializedObject.Update();
|
|
|
|
|
EditorUtility.SetDirty(menuItem);
|
|
|
|
|
PrefabUtility.RecordPrefabInstancePropertyModifications(menuItem);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-23 21:29:11 +09:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 19:47:10 +09:00
|
|
|
|
case SubmenuSource.Children:
|
|
|
|
|
{
|
2023-02-23 21:29:11 +09:00
|
|
|
|
_lastExpMenu = null;
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.PropertyField(prop_otherObjChildren);
|
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
|
|
|
|
2023-02-21 19:47:10 +09:00
|
|
|
|
var source = menuItem.menuSource_otherObjectChildren != null
|
|
|
|
|
? menuItem.menuSource_otherObjectChildren
|
|
|
|
|
: menuItem.gameObject;
|
|
|
|
|
foreach (Transform t in source.transform)
|
|
|
|
|
{
|
2023-02-22 20:59:40 +09:00
|
|
|
|
var child = t.GetComponent<ModularAvatarMenuItem>();
|
2023-02-21 19:47:10 +09:00
|
|
|
|
if (child == null) continue;
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
|
|
|
|
|
|
|
|
|
|
GUILayout.BeginHorizontal();
|
|
|
|
|
using (new EditorGUI.DisabledScope(true))
|
|
|
|
|
{
|
2023-02-22 20:59:40 +09:00
|
|
|
|
EditorGUILayout.ObjectField(new GUIContent(), child, typeof(ModularAvatarMenuItem),
|
|
|
|
|
true,
|
2023-02-21 19:47:10 +09:00
|
|
|
|
GUILayout.ExpandWidth(true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GUILayout.Space(20);
|
|
|
|
|
GUILayout.Label("Enabled", GUILayout.Width(50));
|
|
|
|
|
var childObject = t.gameObject;
|
|
|
|
|
EditorGUI.BeginChangeCheck();
|
|
|
|
|
var active = GUILayout.Toggle(childObject.activeSelf, new GUIContent(),
|
|
|
|
|
GUILayout.Width(EditorGUIUtility.singleLineHeight));
|
|
|
|
|
if (EditorGUI.EndChangeCheck())
|
|
|
|
|
{
|
|
|
|
|
childObject.SetActive(active);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
|
|
2023-02-23 20:51:24 +09:00
|
|
|
|
DrawControlSettings(child);
|
2023-02-21 19:47:10 +09:00
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndVertical();
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-24 19:14:48 +09:00
|
|
|
|
|
|
|
|
|
if (GUILayout.Button("Add menu item"))
|
|
|
|
|
{
|
|
|
|
|
var obj = new GameObject();
|
|
|
|
|
obj.name = "New Control";
|
|
|
|
|
obj.transform.SetParent(source.transform, false);
|
|
|
|
|
obj.AddComponent<ModularAvatarMenuItem>();
|
|
|
|
|
Undo.RegisterCreatedObjectUndo(obj, "Add menu item");
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 19:47:10 +09:00
|
|
|
|
break;
|
|
|
|
|
}
|
2023-02-23 21:29:11 +09:00
|
|
|
|
default: break;
|
2023-02-21 19:47:10 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-23 21:29:11 +09:00
|
|
|
|
|
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
2023-02-21 19:47:10 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|