2023-02-23 20:51:24 +09:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using UnityEditor;
|
2023-02-23 21:29:11 +09:00
|
|
|
|
using UnityEngine;
|
2023-02-23 20:51:24 +09:00
|
|
|
|
using VRC.SDK3.Avatars.ScriptableObjects;
|
|
|
|
|
|
|
|
|
|
namespace nadena.dev.modular_avatar.core.editor
|
|
|
|
|
{
|
|
|
|
|
internal class MenuItemCoreGUI
|
|
|
|
|
{
|
2023-02-23 21:29:11 +09:00
|
|
|
|
private readonly SerializedProperty _name;
|
|
|
|
|
private readonly SerializedProperty _texture;
|
|
|
|
|
private readonly SerializedProperty _type;
|
|
|
|
|
private readonly SerializedProperty _value;
|
|
|
|
|
private readonly SerializedProperty _submenu;
|
2023-02-23 20:51:24 +09:00
|
|
|
|
|
2023-02-23 21:29:11 +09:00
|
|
|
|
private readonly ParameterGUI _parameterGUI;
|
2023-02-23 20:51:24 +09:00
|
|
|
|
|
|
|
|
|
public MenuItemCoreGUI(SerializedObject _obj, Action redraw)
|
|
|
|
|
{
|
2023-02-23 21:29:11 +09:00
|
|
|
|
GameObject parameterReference = null;
|
|
|
|
|
if (_obj.targetObjects.Length == 1)
|
|
|
|
|
{
|
|
|
|
|
parameterReference = (_obj.targetObject as Component)?.gameObject;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var gameObjects = new SerializedObject(
|
2023-02-23 20:51:24 +09:00
|
|
|
|
_obj.targetObjects.Select(o =>
|
|
|
|
|
(UnityEngine.Object) ((ModularAvatarMenuItem) o).gameObject
|
|
|
|
|
).ToArray()
|
|
|
|
|
);
|
|
|
|
|
|
2023-02-23 21:29:11 +09:00
|
|
|
|
_name = gameObjects.FindProperty("m_Name");
|
|
|
|
|
var control = _obj.FindProperty(nameof(ModularAvatarMenuItem.Control));
|
|
|
|
|
|
|
|
|
|
_texture = control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.icon));
|
|
|
|
|
_type = control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.type));
|
|
|
|
|
var parameter = control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.parameter))
|
|
|
|
|
.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.parameter.name));
|
|
|
|
|
_value = control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.value));
|
|
|
|
|
_submenu = null;
|
|
|
|
|
|
|
|
|
|
_parameterGUI = new ParameterGUI(parameterReference, parameter, redraw);
|
|
|
|
|
}
|
2023-02-23 20:51:24 +09:00
|
|
|
|
|
2023-02-23 21:29:11 +09:00
|
|
|
|
public MenuItemCoreGUI(GameObject parameterReference, SerializedProperty _control, Action redraw)
|
|
|
|
|
{
|
|
|
|
|
_name = _control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.name));
|
|
|
|
|
_texture = _control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.icon));
|
2023-02-23 20:51:24 +09:00
|
|
|
|
_type = _control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.type));
|
2023-02-23 21:29:11 +09:00
|
|
|
|
var parameter = _control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.parameter))
|
2023-02-23 20:51:24 +09:00
|
|
|
|
.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.parameter.name));
|
|
|
|
|
_value = _control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.value));
|
2023-02-23 21:29:11 +09:00
|
|
|
|
_submenu = _control.FindPropertyRelative(nameof(VRCExpressionsMenu.Control.subMenu));
|
2023-02-23 20:51:24 +09:00
|
|
|
|
|
2023-02-23 21:29:11 +09:00
|
|
|
|
_parameterGUI = new ParameterGUI(parameterReference, parameter, redraw);
|
2023-02-23 20:51:24 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DoGUI()
|
|
|
|
|
{
|
2023-02-23 21:29:11 +09:00
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.BeginVertical();
|
2023-02-23 20:51:24 +09:00
|
|
|
|
EditorGUILayout.PropertyField(_name);
|
2023-02-23 21:29:11 +09:00
|
|
|
|
EditorGUILayout.PropertyField(_texture);
|
2023-02-23 20:51:24 +09:00
|
|
|
|
EditorGUILayout.PropertyField(_type);
|
|
|
|
|
EditorGUILayout.PropertyField(_value);
|
|
|
|
|
|
|
|
|
|
_parameterGUI.DoGUI();
|
2023-02-23 21:29:11 +09:00
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndVertical();
|
|
|
|
|
|
|
|
|
|
if (_texture != null)
|
|
|
|
|
{
|
|
|
|
|
var tex = _texture.objectReferenceValue as Texture2D;
|
|
|
|
|
if (tex != null)
|
|
|
|
|
{
|
|
|
|
|
var size = EditorGUIUtility.singleLineHeight * 5;
|
|
|
|
|
var margin = 4;
|
|
|
|
|
var withMargin = new Vector2(margin + size, margin + size);
|
|
|
|
|
|
|
|
|
|
var rect = GUILayoutUtility.GetRect(withMargin.x, withMargin.y, GUILayout.ExpandWidth(false),
|
|
|
|
|
GUILayout.ExpandHeight(true));
|
|
|
|
|
rect.x += margin;
|
|
|
|
|
rect.y = rect.y + rect.height / 2 - size / 2;
|
|
|
|
|
rect.width = size;
|
|
|
|
|
rect.height = size;
|
|
|
|
|
|
|
|
|
|
GUI.Box(rect, new GUIContent(), "flow node 1");
|
|
|
|
|
GUI.DrawTexture(rect, tex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndHorizontal();
|
|
|
|
|
|
|
|
|
|
if (_submenu != null) EditorGUILayout.PropertyField(_submenu);
|
2023-02-23 20:51:24 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|