From 27bcb99812b030bceeddb9fb413bd33c44930198 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 7 Aug 2020 15:27:34 +0900 Subject: [PATCH] add VRMMetaObjectEditor --- .../VRM/UniVRM/Editor/Meta/VRMMetaEditor.cs | 129 ++---------------- .../UniVRM/Editor/Meta/VRMMetaObjectEditor.cs | 114 ++++++++++++++++ .../Editor/Meta/VRMMetaObjectEditor.cs.meta | 11 ++ 3 files changed, 133 insertions(+), 121 deletions(-) create mode 100644 Assets/VRM/UniVRM/Editor/Meta/VRMMetaObjectEditor.cs create mode 100644 Assets/VRM/UniVRM/Editor/Meta/VRMMetaObjectEditor.cs.meta diff --git a/Assets/VRM/UniVRM/Editor/Meta/VRMMetaEditor.cs b/Assets/VRM/UniVRM/Editor/Meta/VRMMetaEditor.cs index 339c98358..fac50451f 100644 --- a/Assets/VRM/UniVRM/Editor/Meta/VRMMetaEditor.cs +++ b/Assets/VRM/UniVRM/Editor/Meta/VRMMetaEditor.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; +using UnityEditor; namespace VRM @@ -8,135 +6,24 @@ namespace VRM [CustomEditor(typeof(VRMMeta))] public class VRMMetaEditor : Editor { - //VRMMeta m_target; - SerializedProperty m_ScriptProp; - + Editor m_Inspector; SerializedProperty m_VRMMetaObjectProp; - SerializedProperty VRMMetaObjectProp + + private void OnDestroy() { - get { return m_VRMMetaObjectProp; } - set - { - if (m_VRMMetaObjectProp == value) return; - m_VRMMetaObjectProp = value; - - // get props - Debug.Log("clear"); - m_propMap.Clear(); - } - } - - Dictionary m_propMap = new Dictionary(); - void InitMap(SerializedObject so) - { - if (VRMMetaObjectProp == null) return; - //if (m_propMap.Count > 0) return; - m_propMap.Clear(); - - for (var it = so.GetIterator(); it.NextVisible(true);) - { - if (it.name == "m_Script") continue; - //Debug.LogFormat("{0}", it.name); - m_propMap.Add(it.name, so.FindProperty(it.name)); - } + UnityEditor.Editor.DestroyImmediate(m_Inspector); } private void OnEnable() { - //m_target = (VRMMeta)target; - m_ScriptProp = serializedObject.FindProperty("m_Script"); m_VRMMetaObjectProp = serializedObject.FindProperty("Meta"); + m_Inspector = Editor.CreateEditor(m_VRMMetaObjectProp.objectReferenceValue); } public override void OnInspectorGUI() { - serializedObject.Update(); - EditorGUILayout.PropertyField(m_ScriptProp, true); - EditorGUILayout.PropertyField(m_VRMMetaObjectProp, true); - serializedObject.ApplyModifiedProperties(); - - EditorGUILayout.Space(); -#if true - if (m_VRMMetaObjectProp.objectReferenceValue != null) - { - VRMMetaObjectGUI(new SerializedObject(m_VRMMetaObjectProp.objectReferenceValue)); - } -#else - if(m_target!=null && m_target.Meta != null) - { - VRMMetaObjectGUI(new SerializedObject(m_target.Meta)); - } -#endif - } - - bool m_foldoutInfo = true; - bool m_foldoutPermission = true; - bool m_foldoutDistribution = true; - void VRMMetaObjectGUI(SerializedObject so) - { - InitMap(so); - if (m_propMap == null || m_propMap.Count == 0) return; - - so.Update(); - - GUI.enabled = false; - EditorGUILayout.PropertyField(m_propMap["ExporterVersion"]); - if (VRMVersion.IsNewer(m_propMap["ExporterVersion"].stringValue)) - { - EditorGUILayout.HelpBox("Check UniVRM new version. https://github.com/dwango/UniVRM/releases", MessageType.Warning); - } - GUI.enabled = true; - - m_foldoutInfo = EditorGUILayout.Foldout(m_foldoutInfo, "Information"); - if (m_foldoutInfo) - { - EditorGUILayout.PropertyField(m_propMap["Title"]); - EditorGUILayout.PropertyField(m_propMap["Version"]); - EditorGUILayout.PropertyField(m_propMap["Author"]); - EditorGUILayout.PropertyField(m_propMap["ContactInformation"]); - EditorGUILayout.PropertyField(m_propMap["Reference"]); - - var thumbnail = m_propMap["Thumbnail"]; - EditorGUILayout.PropertyField(thumbnail); - thumbnail.objectReferenceValue = TextureField("", (Texture2D)thumbnail.objectReferenceValue, 100); - } - - EditorGUILayout.LabelField("License ", EditorStyles.boldLabel); - - m_foldoutPermission = EditorGUILayout.Foldout(m_foldoutPermission, "Personation / Characterization Permission"); - if (m_foldoutPermission) - { - EditorGUILayout.PropertyField(m_propMap["AllowedUser"], new GUIContent("A person who can perform with this avatar"), false); - EditorGUILayout.PropertyField(m_propMap["ViolentUssage"], new GUIContent("Violent acts using this avatar")); - EditorGUILayout.PropertyField(m_propMap["SexualUssage"], new GUIContent("Sexuality acts using this avatar")); - EditorGUILayout.PropertyField(m_propMap["CommercialUssage"], new GUIContent("For commercial use")); - EditorGUILayout.PropertyField(m_propMap["OtherPermissionUrl"], new GUIContent("Other License Url")); - } - - m_foldoutDistribution = EditorGUILayout.Foldout(m_foldoutDistribution, "Redistribution / Modifications License"); - if (m_foldoutDistribution) - { - var licenseType = m_propMap["LicenseType"]; - EditorGUILayout.PropertyField(licenseType); - if ((LicenseType)licenseType.intValue == LicenseType.Other) - { - EditorGUILayout.PropertyField(m_propMap["OtherLicenseUrl"]); - } - } - - so.ApplyModifiedProperties(); - } - - 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; + EditorGUILayout.PropertyField(m_VRMMetaObjectProp); + m_Inspector.OnInspectorGUI(); } } } diff --git a/Assets/VRM/UniVRM/Editor/Meta/VRMMetaObjectEditor.cs b/Assets/VRM/UniVRM/Editor/Meta/VRMMetaObjectEditor.cs new file mode 100644 index 000000000..44a584869 --- /dev/null +++ b/Assets/VRM/UniVRM/Editor/Meta/VRMMetaObjectEditor.cs @@ -0,0 +1,114 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace VRM +{ + [CustomEditor(typeof(VRMMetaObject))] + public class VRMMetaObjectEditor : Editor + { + SerializedProperty m_ScriptProp; + Dictionary m_propMap = new Dictionary(); + void InitMap(SerializedObject so) + { + // if (VRMMetaObjectProp == null) return; + //if (m_propMap.Count > 0) return; + m_propMap.Clear(); + + for (var it = so.GetIterator(); it.NextVisible(true);) + { + if (it.name == "m_Script") continue; + //Debug.LogFormat("{0}", it.name); + m_propMap.Add(it.name, so.FindProperty(it.name)); + } + } + + private void OnEnable() + { + m_ScriptProp = serializedObject.FindProperty("m_Script"); + InitMap(serializedObject); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + GUI.enabled = false; + EditorGUILayout.PropertyField(m_ScriptProp, true); + GUI.enabled = true; + serializedObject.ApplyModifiedProperties(); + + EditorGUILayout.Space(); + VRMMetaObjectGUI(serializedObject); + } + + bool m_foldoutInfo = true; + bool m_foldoutPermission = true; + bool m_foldoutDistribution = true; + void VRMMetaObjectGUI(SerializedObject so) + { + InitMap(so); + if (m_propMap == null || m_propMap.Count == 0) return; + + so.Update(); + + GUI.enabled = false; + EditorGUILayout.PropertyField(m_propMap["ExporterVersion"]); + if (VRMVersion.IsNewer(m_propMap["ExporterVersion"].stringValue)) + { + EditorGUILayout.HelpBox("Check UniVRM new version. https://github.com/dwango/UniVRM/releases", MessageType.Warning); + } + GUI.enabled = true; + + m_foldoutInfo = EditorGUILayout.Foldout(m_foldoutInfo, "Information"); + if (m_foldoutInfo) + { + EditorGUILayout.PropertyField(m_propMap["Title"]); + EditorGUILayout.PropertyField(m_propMap["Version"]); + EditorGUILayout.PropertyField(m_propMap["Author"]); + EditorGUILayout.PropertyField(m_propMap["ContactInformation"]); + EditorGUILayout.PropertyField(m_propMap["Reference"]); + + var thumbnail = m_propMap["Thumbnail"]; + EditorGUILayout.PropertyField(thumbnail); + thumbnail.objectReferenceValue = TextureField("", (Texture2D)thumbnail.objectReferenceValue, 100); + } + + EditorGUILayout.LabelField("License ", EditorStyles.boldLabel); + + m_foldoutPermission = EditorGUILayout.Foldout(m_foldoutPermission, "Personation / Characterization Permission"); + if (m_foldoutPermission) + { + EditorGUILayout.PropertyField(m_propMap["AllowedUser"], new GUIContent("A person who can perform with this avatar"), false); + EditorGUILayout.PropertyField(m_propMap["ViolentUssage"], new GUIContent("Violent acts using this avatar")); + EditorGUILayout.PropertyField(m_propMap["SexualUssage"], new GUIContent("Sexuality acts using this avatar")); + EditorGUILayout.PropertyField(m_propMap["CommercialUssage"], new GUIContent("For commercial use")); + EditorGUILayout.PropertyField(m_propMap["OtherPermissionUrl"], new GUIContent("Other License Url")); + } + + m_foldoutDistribution = EditorGUILayout.Foldout(m_foldoutDistribution, "Redistribution / Modifications License"); + if (m_foldoutDistribution) + { + var licenseType = m_propMap["LicenseType"]; + EditorGUILayout.PropertyField(licenseType); + if ((LicenseType)licenseType.intValue == LicenseType.Other) + { + EditorGUILayout.PropertyField(m_propMap["OtherLicenseUrl"]); + } + } + + so.ApplyModifiedProperties(); + } + + 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/VRM/UniVRM/Editor/Meta/VRMMetaObjectEditor.cs.meta b/Assets/VRM/UniVRM/Editor/Meta/VRMMetaObjectEditor.cs.meta new file mode 100644 index 000000000..b14c584ee --- /dev/null +++ b/Assets/VRM/UniVRM/Editor/Meta/VRMMetaObjectEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c244f35fd2772004c9d51095f6326420 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: