This commit is contained in:
ousttrue
2021-06-21 18:07:58 +09:00
parent 4f549c59d1
commit 9ba9a9f5a6
5 changed files with 77 additions and 55 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ebda22df7de116b4dbc84385b56a69b8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,55 @@
using System;
using UnityEditor;
namespace UniGLTF
{
/// <summary>
/// ScriptableObject や MonoBehaviour の部分の Editor を表示する。
/// </summary>
public class SerializedPropertyEditor
{
protected SerializedObject m_serializedObject;
SerializedProperty m_root;
public SerializedPropertyEditor(SerializedObject serializedObject, SerializedProperty property)
{
m_serializedObject = serializedObject;
m_root = property;
}
public static SerializedPropertyEditor Create(SerializedObject serializedObject, string name)
{
var prop = serializedObject.FindProperty(name);
if (prop == null)
{
throw new ArgumentNullException();
}
return new SerializedPropertyEditor(serializedObject, prop);
}
public void OnGUI()
{
RecursiveProperty(m_root);
}
protected virtual void RecursiveProperty(SerializedProperty root)
{
var depth = root.depth;
var iterator = root.Copy();
for (var enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
{
if (iterator.depth < depth)
{
// 前の要素よりも浅くなった。脱出
return;
}
depth = iterator.depth;
using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath))
{
EditorGUILayout.PropertyField(iterator, true);
}
}
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 2a55f4351fdc33f4fadbaa02abc5ffdb
guid: 094682fd8f99ab7488b000e12d6a45b3
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,41 +0,0 @@
using UnityEditor;
namespace UniVRM10
{
/// <summary>
/// 指定した SerializedProperty を起点に再帰的に SerializedProperty を表示する。
/// </summary>
class PropGui
{
SerializedProperty m_root;
public PropGui(SerializedProperty property)
{
m_root = property;
}
// public static PropGui FromSerializedObject(SerializedObject serializedObject, string name)
// {
// var prop = serializedObject.FindProperty(name);
// return new PropGui(prop);
// }
public void RecursiveProperty()
{
var depth = m_root.depth;
var iterator = m_root.Copy();
for (var enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
{
if (iterator.depth < depth)
return;
depth = iterator.depth;
using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath))
{
EditorGUILayout.PropertyField(iterator, true);
}
}
}
}
}

View File

@@ -21,11 +21,11 @@ namespace UniVRM10
static Tabs _tab = Tabs.Meta;
// for SerializedProperty
PropGui m_expression;
PropGui m_meta;
PropGui m_lookAt;
PropGui m_firstPerson;
PropGui m_asset;
SerializedPropertyEditor m_expression;
SerializedPropertyEditor m_meta;
SerializedPropertyEditor m_lookAt;
SerializedPropertyEditor m_firstPerson;
SerializedPropertyEditor m_asset;
void OnEnable()
{
@@ -35,10 +35,10 @@ namespace UniVRM10
}
m_target = (VRM10Object)target;
m_expression = new PropGui(serializedObject.FindProperty(nameof(m_target.Expression)));
m_meta = new PropGui(serializedObject.FindProperty(nameof(m_target.Meta)));
m_lookAt = new PropGui(serializedObject.FindProperty(nameof(m_target.LookAt)));
m_firstPerson = new PropGui(serializedObject.FindProperty(nameof(m_target.FirstPerson)));
m_expression = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.Expression));
m_meta = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.Meta));
m_lookAt = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.LookAt));
m_firstPerson = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.FirstPerson));
}
public override void OnInspectorGUI()
@@ -54,19 +54,19 @@ namespace UniVRM10
switch (_tab)
{
case Tabs.Meta:
m_meta.RecursiveProperty();
m_meta.OnGUI();
break;
case Tabs.Expression:
m_expression.RecursiveProperty();
m_expression.OnGUI();
break;
case Tabs.LookAt:
m_lookAt.RecursiveProperty();
m_lookAt.OnGUI();
break;
case Tabs.FirstPerson:
m_firstPerson.RecursiveProperty();
m_firstPerson.OnGUI();
break;
}
serializedObject.ApplyModifiedProperties();