From c392bd27e31c26fbc497e6dbc20d0b8714f96fb2 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 6 Apr 2018 21:46:34 +0900 Subject: [PATCH] add BlendShapeClipEditor --- .../Editor/BlendShapeBindingPropertyDrawer.cs | 31 ++++++++++ .../BlendShapeBindingPropertyDrawer.cs.meta | 12 ++++ .../BlendShape/Editor/BlendShapeClipEditor.cs | 58 +++++++++++++++++-- .../MaterialValueBindingPropertyDrawer.cs | 31 ++++++++++ ...MaterialValueBindingPropertyDrawer.cs.meta | 12 ++++ 5 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 Scripts/BlendShape/Editor/BlendShapeBindingPropertyDrawer.cs create mode 100644 Scripts/BlendShape/Editor/BlendShapeBindingPropertyDrawer.cs.meta create mode 100644 Scripts/BlendShape/Editor/MaterialValueBindingPropertyDrawer.cs create mode 100644 Scripts/BlendShape/Editor/MaterialValueBindingPropertyDrawer.cs.meta diff --git a/Scripts/BlendShape/Editor/BlendShapeBindingPropertyDrawer.cs b/Scripts/BlendShape/Editor/BlendShapeBindingPropertyDrawer.cs new file mode 100644 index 000000000..005458e41 --- /dev/null +++ b/Scripts/BlendShape/Editor/BlendShapeBindingPropertyDrawer.cs @@ -0,0 +1,31 @@ +using UnityEditor; +using UnityEngine; + + +namespace VRM +{ + [CustomPropertyDrawer(typeof(BlendShapeBinding))] + public class BlendShapeBindingPropertyDrawer : PropertyDrawer + { + public static int GUIElementHeight = 60; + + public override void OnGUI(Rect position, + SerializedProperty property, GUIContent label) + { + using (new EditorGUI.PropertyScope(position, label, property)) + { + var y = position.y; + for (var depth = property.depth; + property.NextVisible(true) && property.depth >= depth; + ) + { + { + var height = EditorGUI.GetPropertyHeight(property); + EditorGUI.PropertyField(new Rect(position.x, y, position.width, height), property, false); + y += height; + } + } + } + } + } +} diff --git a/Scripts/BlendShape/Editor/BlendShapeBindingPropertyDrawer.cs.meta b/Scripts/BlendShape/Editor/BlendShapeBindingPropertyDrawer.cs.meta new file mode 100644 index 000000000..a5bc5a740 --- /dev/null +++ b/Scripts/BlendShape/Editor/BlendShapeBindingPropertyDrawer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 128cbb6916bbc7b4f89deb96d22af39e +timeCreated: 1522997334 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/BlendShape/Editor/BlendShapeClipEditor.cs b/Scripts/BlendShape/Editor/BlendShapeClipEditor.cs index deaeb0064..f42502e84 100644 --- a/Scripts/BlendShape/Editor/BlendShapeClipEditor.cs +++ b/Scripts/BlendShape/Editor/BlendShapeClipEditor.cs @@ -1,4 +1,5 @@ using UnityEditor; +using UnityEditorInternal; using UnityEngine; @@ -7,13 +8,47 @@ namespace VRM [CustomEditor(typeof(BlendShapeClip))] public class BlendShapeClipEditor : Editor { + #region for Editor + SerializedProperty m_BlendShapeNameProp; + SerializedProperty m_PresetProp; + SerializedProperty m_ValuesProp; + ReorderableList m_ValuesList; + SerializedProperty m_MaterialValuesProp; + ReorderableList m_MaterialValuesList; + #endregion + + #region for Preview GameObject m_prefab; PreviewFaceRenderer m_renderer; - BlendShapeClip m_target; + #endregion private void OnEnable() { - m_target = (BlendShapeClip)target; + m_BlendShapeNameProp = serializedObject.FindProperty("BlendShapeName"); + m_PresetProp = serializedObject.FindProperty("Preset"); + m_ValuesProp = serializedObject.FindProperty("Values"); + + m_ValuesList = new ReorderableList(serializedObject, m_ValuesProp); + m_ValuesList.elementHeight = BlendShapeBindingPropertyDrawer.GUIElementHeight; + m_ValuesList.drawElementCallback = + (rect, index, isActive, isFocused) => { + var element = m_ValuesProp.GetArrayElementAtIndex(index); + rect.height -= 4; + rect.y += 2; + EditorGUI.PropertyField(rect, element); + }; + + m_MaterialValuesProp = serializedObject.FindProperty("MaterialValues"); + m_MaterialValuesList = new ReorderableList(serializedObject, m_MaterialValuesProp); + m_MaterialValuesList.elementHeight = MaterialValueBindingPropertyDrawer.GUIElementHeight; + m_MaterialValuesList.drawElementCallback = + (rect, index, isActive, isFocused) => { + var element = m_MaterialValuesProp.GetArrayElementAtIndex(index); + rect.height -= 4; + rect.y += 2; + EditorGUI.PropertyField(rect, element); + }; + var assetPath = AssetDatabase.GetAssetPath(target); //Debug.LogFormat("BlendShapeClipEditor: {0}", assetPath); @@ -48,10 +83,25 @@ namespace VRM public override void OnInspectorGUI() { - base.OnInspectorGUI(); + //base.OnInspectorGUI(); //攻撃力の数値をラベルとして表示する //EditorGUILayout.LabelField("攻撃力", character.攻撃力.ToString()); + + serializedObject.Update(); + + EditorGUILayout.PropertyField(m_BlendShapeNameProp, true); + EditorGUILayout.PropertyField(m_PresetProp, true); + + EditorGUILayout.LabelField("BlendShapeBindings", EditorStyles.boldLabel); + //EditorGUILayout.PropertyField(m_ValuesProp, true); + m_ValuesList.DoLayoutList(); + + EditorGUILayout.LabelField("MaterialValueBindings", EditorStyles.boldLabel); + //EditorGUILayout.PropertyField(m_BlendShapeNameProp); + m_MaterialValuesList.DoLayoutList(); + + serializedObject.ApplyModifiedProperties(); } // very important to override this, it tells Unity to render an ObjectPreview at the bottom of the inspector @@ -83,7 +133,7 @@ namespace VRM GUI.DrawTexture(r, image, ScaleMode.StretchToFill, false); // draw the RenderTexture in the ObjectPreview pane EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40f), - BlendShapeKey.CreateFrom(m_target).ToString()); + BlendShapeKey.CreateFrom((BlendShapeClip)target).ToString()); } } } diff --git a/Scripts/BlendShape/Editor/MaterialValueBindingPropertyDrawer.cs b/Scripts/BlendShape/Editor/MaterialValueBindingPropertyDrawer.cs new file mode 100644 index 000000000..7381c302e --- /dev/null +++ b/Scripts/BlendShape/Editor/MaterialValueBindingPropertyDrawer.cs @@ -0,0 +1,31 @@ +using UnityEditor; +using UnityEngine; + + +namespace VRM +{ + [CustomPropertyDrawer(typeof(MaterialValueBinding))] + public class MaterialValueBindingPropertyDrawer : PropertyDrawer + { + public static int GUIElementHeight = 90; + + public override void OnGUI(Rect position, + SerializedProperty property, GUIContent label) + { + using (new EditorGUI.PropertyScope(position, label, property)) + { + var y = position.y; + for (var depth = property.depth; + property.NextVisible(true) && property.depth >= depth; + ) + { + { + var height = EditorGUI.GetPropertyHeight(property); + EditorGUI.PropertyField(new Rect(position.x, y, position.width, height), property, false); + y += height; + } + } + } + } + } +} diff --git a/Scripts/BlendShape/Editor/MaterialValueBindingPropertyDrawer.cs.meta b/Scripts/BlendShape/Editor/MaterialValueBindingPropertyDrawer.cs.meta new file mode 100644 index 000000000..e4c120c50 --- /dev/null +++ b/Scripts/BlendShape/Editor/MaterialValueBindingPropertyDrawer.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 06e4436c683663e40abfdce36b92e11d +timeCreated: 1522997334 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: