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;
|
|
|
|
|
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-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-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)
|
|
|
|
|
{
|
|
|
|
|
EditorGUILayout.PropertyField(prop_otherObjChildren);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serializedObject.ApplyModifiedProperties();
|
|
|
|
|
|
|
|
|
|
switch (menuItem.MenuSource)
|
|
|
|
|
{
|
|
|
|
|
default: break;
|
|
|
|
|
case SubmenuSource.Children:
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|