From 9ba9a9f5a6e2fb3518444caab05455bdeeb15086 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 21 Jun 2021 18:07:58 +0900 Subject: [PATCH] rename --- .../Editor/SerializedPropertyEditor.meta | 8 +++ .../SerializedPropertyEditor.cs | 55 +++++++++++++++++++ .../SerializedPropertyEditor.cs.meta} | 2 +- Assets/VRM10/Editor/Components/PropGui.cs | 41 -------------- .../Editor/Components/VRM10ObjectEditor.cs | 26 ++++----- 5 files changed, 77 insertions(+), 55 deletions(-) create mode 100644 Assets/UniGLTF/Editor/SerializedPropertyEditor.meta create mode 100644 Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs rename Assets/{VRM10/Editor/Components/PropGui.cs.meta => UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs.meta} (83%) delete mode 100644 Assets/VRM10/Editor/Components/PropGui.cs diff --git a/Assets/UniGLTF/Editor/SerializedPropertyEditor.meta b/Assets/UniGLTF/Editor/SerializedPropertyEditor.meta new file mode 100644 index 000000000..880411af0 --- /dev/null +++ b/Assets/UniGLTF/Editor/SerializedPropertyEditor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ebda22df7de116b4dbc84385b56a69b8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs b/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs new file mode 100644 index 000000000..cc9bdb69c --- /dev/null +++ b/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs @@ -0,0 +1,55 @@ +using System; +using UnityEditor; + +namespace UniGLTF +{ + /// + /// ScriptableObject や MonoBehaviour の部分の Editor を表示する。 + /// + 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); + } + } + } + } +} diff --git a/Assets/VRM10/Editor/Components/PropGui.cs.meta b/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs.meta similarity index 83% rename from Assets/VRM10/Editor/Components/PropGui.cs.meta rename to Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs.meta index 4fa08752a..b3bf15676 100644 --- a/Assets/VRM10/Editor/Components/PropGui.cs.meta +++ b/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 2a55f4351fdc33f4fadbaa02abc5ffdb +guid: 094682fd8f99ab7488b000e12d6a45b3 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/VRM10/Editor/Components/PropGui.cs b/Assets/VRM10/Editor/Components/PropGui.cs deleted file mode 100644 index 9d833c711..000000000 --- a/Assets/VRM10/Editor/Components/PropGui.cs +++ /dev/null @@ -1,41 +0,0 @@ -using UnityEditor; - -namespace UniVRM10 -{ - /// - /// 指定した SerializedProperty を起点に再帰的に SerializedProperty を表示する。 - /// - 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); - } - } - } - } -} diff --git a/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs b/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs index 4c9a19464..d6ba4f3a7 100644 --- a/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs +++ b/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs @@ -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();