From 9ba9a9f5a6e2fb3518444caab05455bdeeb15086 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 21 Jun 2021 18:07:58 +0900 Subject: [PATCH 1/4] 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(); From b4131c4bada6052bd5f5706db81467383eec240b Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 21 Jun 2021 18:34:39 +0900 Subject: [PATCH 2/4] VRM10MetaEditor --- .../SerializedPropertyEditor.cs | 6 ++--- .../Editor/Components/VRM10MetaEditor.cs | 22 +++++++++++++++++++ .../Editor/Components/VRM10MetaEditor.cs.meta | 11 ++++++++++ .../Editor/Components/VRM10ObjectEditor.cs | 7 ++---- 4 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 Assets/VRM10/Editor/Components/VRM10MetaEditor.cs create mode 100644 Assets/VRM10/Editor/Components/VRM10MetaEditor.cs.meta diff --git a/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs b/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs index cc9bdb69c..0b89b8966 100644 --- a/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs +++ b/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs @@ -9,12 +9,12 @@ namespace UniGLTF public class SerializedPropertyEditor { protected SerializedObject m_serializedObject; - SerializedProperty m_root; + protected SerializedProperty m_rootProperty; public SerializedPropertyEditor(SerializedObject serializedObject, SerializedProperty property) { m_serializedObject = serializedObject; - m_root = property; + m_rootProperty = property; } public static SerializedPropertyEditor Create(SerializedObject serializedObject, string name) @@ -29,7 +29,7 @@ namespace UniGLTF public void OnGUI() { - RecursiveProperty(m_root); + RecursiveProperty(m_rootProperty); } protected virtual void RecursiveProperty(SerializedProperty root) diff --git a/Assets/VRM10/Editor/Components/VRM10MetaEditor.cs b/Assets/VRM10/Editor/Components/VRM10MetaEditor.cs new file mode 100644 index 000000000..cc1c1f331 --- /dev/null +++ b/Assets/VRM10/Editor/Components/VRM10MetaEditor.cs @@ -0,0 +1,22 @@ +using UniGLTF; +using UnityEditor; + +namespace UniVRM10 +{ + public class VRM10MetaEditor : SerializedPropertyEditor + { + public VRM10MetaEditor(SerializedObject serializedObject, SerializedProperty property) : base(serializedObject, property) + { + } + + public static VRM10MetaEditor Create(SerializedObject serializedObject) + { + return new VRM10MetaEditor(serializedObject, serializedObject.FindProperty(nameof(VRM10Object.Meta))); + } + + protected override void RecursiveProperty(SerializedProperty root) + { + EditorGUILayout.LabelField("meta"); + } + } +} diff --git a/Assets/VRM10/Editor/Components/VRM10MetaEditor.cs.meta b/Assets/VRM10/Editor/Components/VRM10MetaEditor.cs.meta new file mode 100644 index 000000000..28bcb0260 --- /dev/null +++ b/Assets/VRM10/Editor/Components/VRM10MetaEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ea2bc7cd57762f747bb03606c307cdcf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs b/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs index d6ba4f3a7..cfdb7329e 100644 --- a/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs +++ b/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs @@ -1,8 +1,5 @@ -using System; -using System.IO; -using UniGLTF; +using UniGLTF; using UnityEditor; -using UnityEngine; namespace UniVRM10 { @@ -36,7 +33,7 @@ namespace UniVRM10 m_target = (VRM10Object)target; m_expression = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.Expression)); - m_meta = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.Meta)); + m_meta = VRM10MetaEditor.Create(serializedObject); m_lookAt = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.LookAt)); m_firstPerson = SerializedPropertyEditor.Create(serializedObject, nameof(m_target.FirstPerson)); } From 61d77b2989af38a8881f58ce733da5ca087a815c Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 21 Jun 2021 19:13:48 +0900 Subject: [PATCH 3/4] restore meta editor --- .../Editor/Components/VRM10MetaEditor.cs | 257 +++++++++++++++- Assets/VRM10/Editor/VRM10MetaObjectEditor.cs | 291 ------------------ .../Editor/VRM10MetaObjectEditor.cs.meta | 11 - 3 files changed, 256 insertions(+), 303 deletions(-) delete mode 100644 Assets/VRM10/Editor/VRM10MetaObjectEditor.cs delete mode 100644 Assets/VRM10/Editor/VRM10MetaObjectEditor.cs.meta diff --git a/Assets/VRM10/Editor/Components/VRM10MetaEditor.cs b/Assets/VRM10/Editor/Components/VRM10MetaEditor.cs index cc1c1f331..300f114fb 100644 --- a/Assets/VRM10/Editor/Components/VRM10MetaEditor.cs +++ b/Assets/VRM10/Editor/Components/VRM10MetaEditor.cs @@ -1,12 +1,218 @@ using UniGLTF; +using UniGLTF.M17N; using UnityEditor; +using UnityEngine; namespace UniVRM10 { public class VRM10MetaEditor : SerializedPropertyEditor { + class ValidateProperty + { + public SerializedProperty m_prop; + + public delegate (string, MessageType) Validator(SerializedProperty prop); + Validator m_validator; + + public ValidateProperty(SerializedProperty prop, Validator validator) + { + m_prop = prop; + m_validator = validator; + } + + public void OnGUI() + { + // var old = m_prop.stringValue; + if (m_prop.propertyType == SerializedPropertyType.Generic) + { + if (m_prop.arrayElementType != null) + { + EditorGUILayout.LabelField(m_prop.name); + + var depth = m_prop.depth; + var iterator = m_prop.Copy(); + for (var enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false) + { + if (iterator.depth < depth) + break; + + depth = iterator.depth; + + // using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath)) + EditorGUILayout.PropertyField(iterator, true); + } + } + else + { + throw new System.NotImplementedException(); + } + } + else + { + EditorGUILayout.PropertyField(m_prop); + } + var (msg, msgType) = m_validator(m_prop); + if (!string.IsNullOrEmpty(msg)) + { + EditorGUILayout.HelpBox(msg, msgType); + } + // return old != m_prop.stringValue; + } + } + + SerializedProperty m_exporterVersion; + SerializedProperty m_thumbnail; + ValidateProperty m_title; + ValidateProperty m_version; + ValidateProperty m_author; + ValidateProperty m_contact; + ValidateProperty m_reference; + + SerializedProperty m_AllowedUser; + SerializedProperty m_ViolentUssage; + SerializedProperty m_SexualUssage; + SerializedProperty m_CommercialUssage; + SerializedProperty m_PoliticalOrReligiousUsage; + SerializedProperty m_OtherPermissionUrl; + + SerializedProperty m_LicenseType; + SerializedProperty m_OtherLicenseUrl; + + static string RequiredMessage(string name) + { + switch (LanguageGetter.Lang) + { + case Languages.ja: + return $"必須項目。{name} を入力してください"; + + case Languages.en: + return $"{name} is required"; + + default: + throw new System.NotImplementedException(); + } + } + + enum MessageKeys + { + [LangMsg(Languages.ja, "アバターの人格に関する許諾範囲")] + [LangMsg(Languages.en, "Personation / Characterization Permission")] + PERSONATION, + + [LangMsg(Languages.ja, "アバターに人格を与えることの許諾範囲")] + [LangMsg(Languages.en, "A person who can perform with this avatar")] + ALLOWED_USER, + + [LangMsg(Languages.ja, "このアバターを用いて暴力表現を演じることの許可")] + [LangMsg(Languages.en, "Violent acts using this avatar")] + VIOLENT_USAGE, + + [LangMsg(Languages.ja, "このアバターを用いて性的表現を演じることの許可")] + [LangMsg(Languages.en, "Sexuality acts using this avatar")] + SEXUAL_USAGE, + + [LangMsg(Languages.ja, "商用利用の許可")] + [LangMsg(Languages.en, "For commercial use")] + COMMERCIAL_USAGE, + + [LangMsg(Languages.ja, "再配布・改変に関する許諾範囲")] + [LangMsg(Languages.en, "Redistribution / Modifications License")] + REDISTRIBUTION_MODIFICATIONS, + + // [LangMsg(Languages.ja, "")] + // [LangMsg(Languages.en, "")] + } + + static string Msg(MessageKeys key) + { + return LanguageGetter.Msg(key); + } + + bool m_foldoutInfo = true; + bool m_foldoutPermission = true; + bool m_foldoutDistribution = true; + + static (Rect, Rect) FixedRight(Rect r, int width) + { + if (width > r.width) + { + width = (int)r.width; + } + return ( + new Rect(r.x, r.y, r.width - width, r.height), + new Rect(r.x + r.width - width, r.y, width, r.height) + ); + } + + static void RightFixedPropField(SerializedProperty prop, string label) + { + var r = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(EditorGUIUtility.singleLineHeight)); + var (left, right) = FixedRight(r, 64); + // Debug.Log($"{left}, {right}"); + EditorGUI.LabelField(left, label); + EditorGUI.PropertyField(right, prop, new GUIContent(""), false); + } + + private static Texture2D TextureField(string name, Texture2D texture, int size) + { + GUILayout.BeginHorizontal(); + var style = new GUIStyle(GUI.skin.label); + style.alignment = TextAnchor.UpperCenter; + //style.fixedWidth = size; + GUILayout.Label(name, style); + var result = (Texture2D)EditorGUILayout.ObjectField(texture, typeof(Texture2D), false, GUILayout.Width(size), GUILayout.Height(size)); + GUILayout.EndVertical(); + return result; + } + public VRM10MetaEditor(SerializedObject serializedObject, SerializedProperty property) : base(serializedObject, property) { + m_exporterVersion = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.ExporterVersion)); + m_thumbnail = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.Thumbnail)); + + m_title = new ValidateProperty(m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.Name)), prop => + { + if (string.IsNullOrEmpty(prop.stringValue)) + { + return (RequiredMessage(prop.name), MessageType.Error); + } + return ("", MessageType.None); + }); + m_version = new ValidateProperty(m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.Version)), prop => + { + // if (string.IsNullOrEmpty(prop.stringValue)) + // { + // return (RequiredMessage(prop.name), MessageType.Error); + // } + return ("", MessageType.None); + }); + m_author = new ValidateProperty(m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.Authors)), prop => + { + if (prop.arraySize == 0) + { + return (RequiredMessage(prop.name), MessageType.Error); + } + return ("", MessageType.None); + }); + m_contact = new ValidateProperty(m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.ContactInformation)), prop => + { + return ("", MessageType.None); + }); + m_reference = new ValidateProperty(m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.References)), prop => + { + return ("", MessageType.None); + }); + + m_AllowedUser = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.AllowedUser)); + m_ViolentUssage = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.ViolentUsage)); + m_SexualUssage = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.SexualUsage)); + m_CommercialUssage = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.CommercialUsage)); + m_PoliticalOrReligiousUsage = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.PoliticalOrReligiousUsage)); + m_OtherPermissionUrl = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.OtherLicenseUrl)); + + // m_LicenseType = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.)); + + m_OtherLicenseUrl = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.OtherLicenseUrl)); } public static VRM10MetaEditor Create(SerializedObject serializedObject) @@ -16,7 +222,56 @@ namespace UniVRM10 protected override void RecursiveProperty(SerializedProperty root) { - EditorGUILayout.LabelField("meta"); + if (VRMVersion.IsNewer(m_exporterVersion.stringValue)) + { + EditorGUILayout.HelpBox("Check UniVRM new version. https://github.com/dwango/UniVRM/releases", MessageType.Warning); + } + + // texture + EditorGUILayout.BeginHorizontal(); + { + EditorGUILayout.BeginVertical(); + GUI.enabled = false; + EditorGUILayout.PropertyField(m_exporterVersion); + GUI.enabled = true; + EditorGUILayout.PropertyField(m_thumbnail); + EditorGUILayout.EndVertical(); + m_thumbnail.objectReferenceValue = TextureField("", (Texture2D)m_thumbnail.objectReferenceValue, 100); + } + EditorGUILayout.EndHorizontal(); + + m_foldoutInfo = EditorGUILayout.Foldout(m_foldoutInfo, "Information"); + if (m_foldoutInfo) + { + m_title.OnGUI(); + m_version.OnGUI(); + m_author.OnGUI(); + m_contact.OnGUI(); + m_reference.OnGUI(); + } + // EditorGUILayout.LabelField("License ", EditorStyles.boldLabel); + m_foldoutPermission = EditorGUILayout.Foldout(m_foldoutPermission, Msg(MessageKeys.PERSONATION)); + if (m_foldoutPermission) + { + var backup = EditorGUIUtility.labelWidth; + RightFixedPropField(m_AllowedUser, Msg(MessageKeys.ALLOWED_USER)); + RightFixedPropField(m_ViolentUssage, Msg(MessageKeys.VIOLENT_USAGE)); + RightFixedPropField(m_SexualUssage, Msg(MessageKeys.SEXUAL_USAGE)); + RightFixedPropField(m_CommercialUssage, Msg(MessageKeys.COMMERCIAL_USAGE)); + EditorGUILayout.PropertyField(m_OtherPermissionUrl, new GUIContent("Other License Url")); + EditorGUIUtility.labelWidth = backup; + } + + m_foldoutDistribution = EditorGUILayout.Foldout(m_foldoutDistribution, Msg(MessageKeys.REDISTRIBUTION_MODIFICATIONS)); + if (m_foldoutDistribution) + { + // var licenseType = m_LicenseType; + // EditorGUILayout.PropertyField(licenseType); + // if ((LicenseType)licenseType.intValue == LicenseType.Other) + // { + // EditorGUILayout.PropertyField(m_OtherLicenseUrl); + // } + } } } } diff --git a/Assets/VRM10/Editor/VRM10MetaObjectEditor.cs b/Assets/VRM10/Editor/VRM10MetaObjectEditor.cs deleted file mode 100644 index dcaa3dbcb..000000000 --- a/Assets/VRM10/Editor/VRM10MetaObjectEditor.cs +++ /dev/null @@ -1,291 +0,0 @@ -// using UnityEditor; -// using UnityEngine; -// using UniGLTF; -// using UniGLTF.M17N; - -// namespace UniVRM10 -// { -// [CustomEditor(typeof(VRM10ObjectMeta))] -// public class VRMM10etaObjectEditor : Editor -// { -// class ValidateProperty -// { -// public SerializedProperty m_prop; - -// public delegate (string, MessageType) Validator(SerializedProperty prop); -// Validator m_validator; - -// public ValidateProperty(SerializedProperty prop, Validator validator) -// { -// m_prop = prop; -// m_validator = validator; -// } - -// public void OnGUI() -// { -// // var old = m_prop.stringValue; -// if (m_prop.propertyType == SerializedPropertyType.Generic) -// { -// if (m_prop.arrayElementType != null) -// { -// EditorGUILayout.LabelField(m_prop.name); - -// var depth = m_prop.depth; -// var iterator = m_prop.Copy(); -// for (var enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false) -// { -// if (iterator.depth < depth) -// break; - -// depth = iterator.depth; - -// // using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath)) -// EditorGUILayout.PropertyField(iterator, true); -// } -// } -// else -// { -// throw new System.NotImplementedException(); -// } -// } -// else -// { -// EditorGUILayout.PropertyField(m_prop); -// } -// var (msg, msgType) = m_validator(m_prop); -// if (!string.IsNullOrEmpty(msg)) -// { -// EditorGUILayout.HelpBox(msg, msgType); -// } -// // return old != m_prop.stringValue; -// } -// } - -// VRM10ObjectMeta m_target; -// SerializedProperty m_Script; -// SerializedProperty m_exporterVersion; -// SerializedProperty m_thumbnail; -// ValidateProperty m_title; -// ValidateProperty m_version; -// ValidateProperty m_author; -// ValidateProperty m_contact; -// ValidateProperty m_reference; - -// SerializedProperty m_AllowedUser; -// SerializedProperty m_ViolentUssage; -// SerializedProperty m_SexualUssage; -// SerializedProperty m_CommercialUssage; -// SerializedProperty m_PoliticalOrReligiousUsage; -// SerializedProperty m_OtherPermissionUrl; - -// SerializedProperty m_LicenseType; -// SerializedProperty m_OtherLicenseUrl; - -// static string RequiredMessage(string name) -// { -// switch (LanguageGetter.Lang) -// { -// case Languages.ja: -// return $"必須項目。{name} を入力してください"; - -// case Languages.en: -// return $"{name} is required"; - -// default: -// throw new System.NotImplementedException(); -// } -// } - -// private void OnEnable() -// { -// if (target == null) -// { -// return; -// } -// m_target = (VRM10ObjectMeta)target; - -// m_Script = serializedObject.FindProperty("m_Script"); -// m_exporterVersion = serializedObject.FindProperty(nameof(m_target.ExporterVersion)); -// m_thumbnail = serializedObject.FindProperty(nameof(m_target.Thumbnail)); - -// m_title = new ValidateProperty(serializedObject.FindProperty(nameof(m_target.Name)), prop => -// { -// if (string.IsNullOrEmpty(prop.stringValue)) -// { -// return (RequiredMessage(prop.name), MessageType.Error); -// } -// return ("", MessageType.None); -// }); -// m_version = new ValidateProperty(serializedObject.FindProperty(nameof(m_target.Version)), prop => -// { -// // if (string.IsNullOrEmpty(prop.stringValue)) -// // { -// // return (RequiredMessage(prop.name), MessageType.Error); -// // } -// return ("", MessageType.None); -// }); -// m_author = new ValidateProperty(serializedObject.FindProperty(nameof(m_target.Authors)), prop => -// { -// if (prop.arraySize == 0) -// { -// return (RequiredMessage(prop.name), MessageType.Error); -// } -// return ("", MessageType.None); -// }); -// m_contact = new ValidateProperty(serializedObject.FindProperty(nameof(m_target.ContactInformation)), prop => -// { -// return ("", MessageType.None); -// }); -// m_reference = new ValidateProperty(serializedObject.FindProperty(nameof(m_target.References)), prop => -// { -// return ("", MessageType.None); -// }); - -// m_AllowedUser = serializedObject.FindProperty(nameof(m_target.AllowedUser)); -// m_ViolentUssage = serializedObject.FindProperty(nameof(m_target.ViolentUsage)); -// m_SexualUssage = serializedObject.FindProperty(nameof(m_target.SexualUsage)); -// m_CommercialUssage = serializedObject.FindProperty(nameof(m_target.CommercialUsage)); -// m_PoliticalOrReligiousUsage = serializedObject.FindProperty(nameof(m_target.PoliticalOrReligiousUsage)); -// m_OtherPermissionUrl = serializedObject.FindProperty(nameof(m_target.OtherLicenseUrl)); - -// // m_LicenseType = serializedObject.FindProperty(nameof(m_target.)); - -// m_OtherLicenseUrl = serializedObject.FindProperty(nameof(m_target.OtherLicenseUrl)); -// } - -// enum MessageKeys -// { -// [LangMsg(Languages.ja, "アバターの人格に関する許諾範囲")] -// [LangMsg(Languages.en, "Personation / Characterization Permission")] -// PERSONATION, - -// [LangMsg(Languages.ja, "アバターに人格を与えることの許諾範囲")] -// [LangMsg(Languages.en, "A person who can perform with this avatar")] -// ALLOWED_USER, - -// [LangMsg(Languages.ja, "このアバターを用いて暴力表現を演じることの許可")] -// [LangMsg(Languages.en, "Violent acts using this avatar")] -// VIOLENT_USAGE, - -// [LangMsg(Languages.ja, "このアバターを用いて性的表現を演じることの許可")] -// [LangMsg(Languages.en, "Sexuality acts using this avatar")] -// SEXUAL_USAGE, - -// [LangMsg(Languages.ja, "商用利用の許可")] -// [LangMsg(Languages.en, "For commercial use")] -// COMMERCIAL_USAGE, - -// [LangMsg(Languages.ja, "再配布・改変に関する許諾範囲")] -// [LangMsg(Languages.en, "Redistribution / Modifications License")] -// REDISTRIBUTION_MODIFICATIONS, - -// // [LangMsg(Languages.ja, "")] -// // [LangMsg(Languages.en, "")] -// } - -// static string Msg(MessageKeys key) -// { -// return LanguageGetter.Msg(key); -// } - -// bool m_foldoutInfo = true; -// bool m_foldoutPermission = true; -// bool m_foldoutDistribution = true; - -// public override void OnInspectorGUI() -// { -// if (target == null) -// { -// return; -// } - -// serializedObject.Update(); - -// if (VRMVersion.IsNewer(m_exporterVersion.stringValue)) -// { -// EditorGUILayout.HelpBox("Check UniVRM new version. https://github.com/dwango/UniVRM/releases", MessageType.Warning); -// } - -// // texture -// EditorGUILayout.BeginHorizontal(); -// { -// EditorGUILayout.BeginVertical(); -// GUI.enabled = false; -// EditorGUILayout.PropertyField(m_exporterVersion); -// GUI.enabled = true; -// EditorGUILayout.PropertyField(m_thumbnail); -// EditorGUILayout.EndVertical(); -// m_thumbnail.objectReferenceValue = TextureField("", (Texture2D)m_thumbnail.objectReferenceValue, 100); -// } -// EditorGUILayout.EndHorizontal(); - -// m_foldoutInfo = EditorGUILayout.Foldout(m_foldoutInfo, "Information"); -// if (m_foldoutInfo) -// { -// m_title.OnGUI(); -// m_version.OnGUI(); -// m_author.OnGUI(); -// m_contact.OnGUI(); -// m_reference.OnGUI(); -// } -// // EditorGUILayout.LabelField("License ", EditorStyles.boldLabel); -// m_foldoutPermission = EditorGUILayout.Foldout(m_foldoutPermission, Msg(MessageKeys.PERSONATION)); -// if (m_foldoutPermission) -// { -// var backup = EditorGUIUtility.labelWidth; -// RightFixedPropField(m_AllowedUser, Msg(MessageKeys.ALLOWED_USER)); -// RightFixedPropField(m_ViolentUssage, Msg(MessageKeys.VIOLENT_USAGE)); -// RightFixedPropField(m_SexualUssage, Msg(MessageKeys.SEXUAL_USAGE)); -// RightFixedPropField(m_CommercialUssage, Msg(MessageKeys.COMMERCIAL_USAGE)); -// EditorGUILayout.PropertyField(m_OtherPermissionUrl, new GUIContent("Other License Url")); -// EditorGUIUtility.labelWidth = backup; -// } - -// m_foldoutDistribution = EditorGUILayout.Foldout(m_foldoutDistribution, Msg(MessageKeys.REDISTRIBUTION_MODIFICATIONS)); -// if (m_foldoutDistribution) -// { -// // var licenseType = m_LicenseType; -// // EditorGUILayout.PropertyField(licenseType); -// // if ((LicenseType)licenseType.intValue == LicenseType.Other) -// // { -// // EditorGUILayout.PropertyField(m_OtherLicenseUrl); -// // } -// } - -// serializedObject.ApplyModifiedProperties(); -// } - -// static (Rect, Rect) FixedRight(Rect r, int width) -// { -// if (width > r.width) -// { -// width = (int)r.width; -// } -// return ( -// new Rect(r.x, r.y, r.width - width, r.height), -// new Rect(r.x + r.width - width, r.y, width, r.height) -// ); -// } - -// static void RightFixedPropField(SerializedProperty prop, string label) -// { -// var r = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, GUILayout.Height(EditorGUIUtility.singleLineHeight)); -// var (left, right) = FixedRight(r, 64); -// // Debug.Log($"{left}, {right}"); -// EditorGUI.LabelField(left, label); -// EditorGUI.PropertyField(right, prop, new GUIContent(""), false); -// } - -// private static Texture2D TextureField(string name, Texture2D texture, int size) -// { -// GUILayout.BeginHorizontal(); -// var style = new GUIStyle(GUI.skin.label); -// style.alignment = TextAnchor.UpperCenter; -// //style.fixedWidth = size; -// GUILayout.Label(name, style); -// var result = (Texture2D)EditorGUILayout.ObjectField(texture, typeof(Texture2D), false, GUILayout.Width(size), GUILayout.Height(size)); -// GUILayout.EndVertical(); -// return result; -// } -// } -// } diff --git a/Assets/VRM10/Editor/VRM10MetaObjectEditor.cs.meta b/Assets/VRM10/Editor/VRM10MetaObjectEditor.cs.meta deleted file mode 100644 index 8134e5641..000000000 --- a/Assets/VRM10/Editor/VRM10MetaObjectEditor.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 825701d5bd059444ca9fb17f5e283608 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From c6cb7e9df31b39aef4bd6143520cb2dc170ef521 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 21 Jun 2021 19:17:51 +0900 Subject: [PATCH 4/4] VRM10ExportDialog use VRM10MetaEditor --- .../SerializedPropertyEditor/SerializedPropertyEditor.cs | 2 +- Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs | 8 ++++---- Assets/VRM10/Editor/Vrm10ExportDialog.cs | 9 +++------ 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs b/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs index 0b89b8966..4224f0dd5 100644 --- a/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs +++ b/Assets/UniGLTF/Editor/SerializedPropertyEditor/SerializedPropertyEditor.cs @@ -27,7 +27,7 @@ namespace UniGLTF return new SerializedPropertyEditor(serializedObject, prop); } - public void OnGUI() + public void OnInspectorGUI() { RecursiveProperty(m_rootProperty); } diff --git a/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs b/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs index cfdb7329e..4398a599d 100644 --- a/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs +++ b/Assets/VRM10/Editor/Components/VRM10ObjectEditor.cs @@ -51,19 +51,19 @@ namespace UniVRM10 switch (_tab) { case Tabs.Meta: - m_meta.OnGUI(); + m_meta.OnInspectorGUI(); break; case Tabs.Expression: - m_expression.OnGUI(); + m_expression.OnInspectorGUI(); break; case Tabs.LookAt: - m_lookAt.OnGUI(); + m_lookAt.OnInspectorGUI(); break; case Tabs.FirstPerson: - m_firstPerson.OnGUI(); + m_firstPerson.OnInspectorGUI(); break; } serializedObject.ApplyModifiedProperties(); diff --git a/Assets/VRM10/Editor/Vrm10ExportDialog.cs b/Assets/VRM10/Editor/Vrm10ExportDialog.cs index dad131ef5..94e02e354 100644 --- a/Assets/VRM10/Editor/Vrm10ExportDialog.cs +++ b/Assets/VRM10/Editor/Vrm10ExportDialog.cs @@ -60,16 +60,13 @@ namespace UniVRM10 } if (m_metaEditor != null) { - UnityEditor.Editor.DestroyImmediate(m_metaEditor); m_metaEditor = null; } m_meta = value; } } VRM10Object m_tmpObject; - Editor m_metaEditor; - - + VRM10MetaEditor m_metaEditor; protected override void Initialize() { @@ -245,11 +242,11 @@ namespace UniVRM10 { if (m_meta != null) { - m_metaEditor = Editor.CreateEditor(Vrm); + m_metaEditor = VRM10MetaEditor.Create(new SerializedObject(Vrm)); } else { - m_metaEditor = Editor.CreateEditor(m_tmpObject); + m_metaEditor = VRM10MetaEditor.Create(new SerializedObject(m_tmpObject)); } } m_metaEditor.OnInspectorGUI();