From 89073efdba3a95f8557775b31db90c9e5a50abc0 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 29 Jul 2021 17:13:42 +0900 Subject: [PATCH 1/5] remove unused --- .../Expression/ExpressionSelector.cs | 148 ------------------ .../Expression/ExpressionSelector.cs.meta | 11 -- .../Expression/ReorderableExpressionList.cs | 84 ---------- .../ReorderableExpressionList.cs.meta | 11 -- 4 files changed, 254 deletions(-) delete mode 100644 Assets/VRM10/Editor/Components/Expression/ExpressionSelector.cs delete mode 100644 Assets/VRM10/Editor/Components/Expression/ExpressionSelector.cs.meta delete mode 100644 Assets/VRM10/Editor/Components/Expression/ReorderableExpressionList.cs delete mode 100644 Assets/VRM10/Editor/Components/Expression/ReorderableExpressionList.cs.meta diff --git a/Assets/VRM10/Editor/Components/Expression/ExpressionSelector.cs b/Assets/VRM10/Editor/Components/Expression/ExpressionSelector.cs deleted file mode 100644 index 6c32d7ba3d..0000000000 --- a/Assets/VRM10/Editor/Components/Expression/ExpressionSelector.cs +++ /dev/null @@ -1,148 +0,0 @@ -using System; -using System.Linq; -using UnityEngine; -using UnityEditor; -using System.IO; - -namespace UniVRM10 -{ - /// - /// ExpressionAvatarEditorの部品 - /// - class ExpressionClipSelector - { - VRM10ObjectExpression m_avatar; - - int m_mode; - static readonly string[] MODES = new string[]{ - "Button", - "List" - }; - - ReorderableExpressionList m_clipList; - - public VRM10Expression GetSelected() - { - var clips = m_avatar.Clips.ToArray(); - if (m_avatar == null || clips == null || clips.Length == 0) - { - return null; - } - if (m_selectedIndex < 0 || m_selectedIndex >= clips.Length) - { - return null; - } - return clips[m_selectedIndex]; - } - - public event Action Selected; - void RaiseSelected(int index) - { - m_clipList.Select(index); - var clip = GetSelected(); - var handle = Selected; - if (handle == null) - { - return; - } - handle(clip); - } - - int m_selectedIndex; - int SelectedIndex - { - get { return m_selectedIndex; } - set - { - // これで更新するべし - if (m_selectedIndex == value) return; - m_selectedIndex = value; - RaiseSelected(value); - } - } - - public ExpressionClipSelector(VRM10ObjectExpression avatar, string dir, SerializedObject serializedObject) - { - avatar.RemoveNullClip(); - - m_avatar = avatar; - - var prop = serializedObject.FindProperty("Clips"); - m_clipList = new ReorderableExpressionList(serializedObject, prop, dir); - - m_clipList.Selected += (selected) => - { - var clips = avatar.Clips.ToArray(); - SelectedIndex = Array.IndexOf(clips, selected); - }; - } - - public void DrawGUI(string dir) - { - var backup = GUI.enabled; - try - { - GUI.enabled = true; - EditorGUILayout.Space(); - EditorGUILayout.LabelField("Select Expression", EditorStyles.boldLabel); - - m_mode = GUILayout.Toolbar(m_mode, MODES); - switch (m_mode) - { - case 0: - SelectGUI(dir); - break; - - case 1: - m_clipList.GUI(); - break; - - default: - throw new NotImplementedException(); - } - } - finally - { - GUI.enabled = backup; - } - } - - void SelectGUI(string dir) - { - if (m_avatar != null && m_avatar.Clips != null) - { - var array = m_avatar.Clips - .Select(x => x != null - ? ExpressionKey.CreateFromClip(x).ToString() - : "null" - ).ToArray(); - SelectedIndex = GUILayout.SelectionGrid(SelectedIndex, array, 4); - } - - // if (GUILayout.Button("Add Expression")) - // { - // var path = EditorUtility.SaveFilePanel( - // "Create Expression", - // dir, - // string.Format("Expression#{0}.asset", m_avatar.Clips.Count), - // "asset"); - // if (!string.IsNullOrEmpty(path)) - // { - // var clip = ExpressionEditorBase.CreateExpression(path.ToUnityRelativePath()); - // //clip.Prefab = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(target)); - - // m_avatar.Clips.Add(clip); - // } - // } - } - - public void DuplicateWarn() - { - var key = ExpressionKey.CreateFromClip(GetSelected()); - if (m_avatar.Clips.Where(x => key.Match(x)).Count() > 1) - { - EditorGUILayout.HelpBox("duplicate clip: " + key, MessageType.Error); - } - } - } -} diff --git a/Assets/VRM10/Editor/Components/Expression/ExpressionSelector.cs.meta b/Assets/VRM10/Editor/Components/Expression/ExpressionSelector.cs.meta deleted file mode 100644 index d6d2bac846..0000000000 --- a/Assets/VRM10/Editor/Components/Expression/ExpressionSelector.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6d4d5da207577eb48ad767ff59bcf8b4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/VRM10/Editor/Components/Expression/ReorderableExpressionList.cs b/Assets/VRM10/Editor/Components/Expression/ReorderableExpressionList.cs deleted file mode 100644 index cd69a46c31..0000000000 --- a/Assets/VRM10/Editor/Components/Expression/ReorderableExpressionList.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.IO; -using UnityEditor; -using UnityEditorInternal; -using UnityEngine; - -namespace UniVRM10 -{ - class ReorderableExpressionList - { - ReorderableList m_list; - - public event Action Selected; - void RaiseSelected(VRM10Expression selected) - { - var handler = Selected; - if (handler == null) - { - return; - } - handler(selected); - } - - public void Select(int index) - { - m_list.index = index; - } - - public ReorderableExpressionList(SerializedObject serializedObject, SerializedProperty prop, string dir) - { - m_list = new ReorderableList(serializedObject, prop); - - m_list.drawHeaderCallback = (rect) => - EditorGUI.LabelField(rect, "Expressions"); - - m_list.drawElementCallback = (rect, index, isActive, isFocused) => - { - var element = prop.GetArrayElementAtIndex(index); - rect.height -= 4; - rect.y += 2; - EditorGUI.PropertyField(rect, element); - }; - - m_list.onAddCallback += (list) => - { - // Add slot - prop.arraySize++; - // select last item - list.index = prop.arraySize - 1; - // get last item - var element = prop.GetArrayElementAtIndex(list.index); - element.objectReferenceValue = null; - - // var dir = Path.GetDirectoryName(AssetDatabase.GetAssetPath(target)); - var path = EditorUtility.SaveFilePanel( - "Create Expression", - dir, - string.Format("Expression#{0}.asset", list.count), - "asset"); - if (!string.IsNullOrEmpty(path)) - { - var clip = ExpressionEditorBase.CreateExpression(path.ToUnityRelativePath()); - //clip.Prefab = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(target)); - - element.objectReferenceValue = clip; - } - }; - - m_list.onSelectCallback += (list) => - { - var a = list.serializedProperty; - var selected = a.GetArrayElementAtIndex(list.index); - RaiseSelected((VRM10Expression)selected.objectReferenceValue); - }; - - //m_clipList.onCanRemoveCallback += list => true; - } - - public void GUI() - { - m_list.DoLayoutList(); - } - } -} diff --git a/Assets/VRM10/Editor/Components/Expression/ReorderableExpressionList.cs.meta b/Assets/VRM10/Editor/Components/Expression/ReorderableExpressionList.cs.meta deleted file mode 100644 index 55b093fb48..0000000000 --- a/Assets/VRM10/Editor/Components/Expression/ReorderableExpressionList.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a5a5707cea4226d40af879c4c9778002 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: From 9fd371563cb9226a8cb77ad0c53e5989c8a7b7b0 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 29 Jul 2021 17:19:08 +0900 Subject: [PATCH 2/5] remove inheritance --- .../Expression/ExpressionEditorBase.cs | 272 ------------------ .../Expression/ExpressionEditorBase.cs.meta | 11 - .../Expression/VRM10ExpressionEditor.cs | 260 ++++++++++++++++- 3 files changed, 250 insertions(+), 293 deletions(-) delete mode 100644 Assets/VRM10/Editor/Components/Expression/ExpressionEditorBase.cs delete mode 100644 Assets/VRM10/Editor/Components/Expression/ExpressionEditorBase.cs.meta diff --git a/Assets/VRM10/Editor/Components/Expression/ExpressionEditorBase.cs b/Assets/VRM10/Editor/Components/Expression/ExpressionEditorBase.cs deleted file mode 100644 index 9bc93ce57c..0000000000 --- a/Assets/VRM10/Editor/Components/Expression/ExpressionEditorBase.cs +++ /dev/null @@ -1,272 +0,0 @@ -using System.IO; -using UnityEditor; -using UnityEngine; - -namespace UniVRM10 -{ - /// - /// Prefabをインスタンス化してPreviewに表示する - /// - /// * https://github.com/Unity-Technologies/UnityCsReference/blob/11bcfd801fccd2a52b09bb6fd636c1ddcc9f1705/Editor/Mono/Inspector/ModelInspector.cs - /// - /// - public abstract class ExpressionEditorBase : Editor - { - /// - /// PreviewRenderUtilityを管理する。 - /// - /// * PreviewRenderUtility.m_cameraのUnityVersionによる切り分け - /// - /// - PreviewFaceRenderer m_renderer; - - /// - /// Prefabをインスタンス化したシーンを管理する。 - /// - /// * ExpressionのBake - /// * MaterialMorphの適用 - /// * Previewカメラのコントロール - /// * Previewライティングのコントロール - /// - /// - PreviewSceneManager m_scene; - protected PreviewSceneManager PreviewSceneManager - { - get { return m_scene; } - } - - /// - /// Previewシーンに表示するPrefab - /// - GameObject m_prefab; - protected GameObject Prefab - { - get { return m_prefab; } - private set - { - if (m_prefab == value) return; - - //Debug.LogFormat("Prefab = {0}", value); - m_prefab = value; - - if (m_scene != null) - { - //Debug.LogFormat("OnDestroy"); - GameObject.DestroyImmediate(m_scene.gameObject); - m_scene = null; - } - - if (m_prefab != null) - { - m_scene = UniVRM10.PreviewSceneManager.GetOrCreate(m_prefab); - if (m_scene != null) - { - m_scene.gameObject.SetActive(false); - } - - Bake(); - } - } - } - - protected abstract VRM10Expression CurrentExpression(); - - /// - /// Preview シーンに Expression を適用する - /// - protected void Bake() - { - if (m_scene != null) - { - //Debug.Log("Bake"); - m_scene.Bake(CurrentExpression(), 1.0f); - } - } - - protected abstract GameObject GetPrefab(); - - protected virtual void OnEnable() - { - m_renderer = new PreviewFaceRenderer(); - - Prefab = GetPrefab(); - } - - protected virtual void OnDisable() - { - if (m_renderer != null) - { - m_renderer.Dispose(); - m_renderer = null; - } - ClearScene(); - } - - protected virtual void OnDestroy() - { - // 2018/2019 で OnDisable/OnDestroy の呼ばれ方が違う? - ClearScene(); - } - - void ClearScene() - { - if (m_scene != null) - { - //Debug.LogFormat("OnDestroy"); - m_scene.Clean(); - GameObject.DestroyImmediate(m_scene.gameObject); - m_scene = null; - } - } - - protected static void Separator() - { - EditorGUILayout.Space(); - EditorGUILayout.BeginHorizontal(); - //GUILayout.Space(); - GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1)); - EditorGUILayout.EndHorizontal(); - EditorGUILayout.Space(); - } - - public override void OnInspectorGUI() - { - //base.OnInspectorGUI(); - - Prefab = (GameObject)EditorGUILayout.ObjectField("Preview Prefab", Prefab, typeof(GameObject), false); - - //Separator(); - } - - private static int sliderHash = "Slider".GetHashCode(); - float m_yaw = 180.0f; - float m_pitch; - Vector3 m_position = new Vector3(0, 0, -0.8f); - - // very important to override this, it tells Unity to render an ObjectPreview at the bottom of the inspector - public override bool HasPreviewGUI() { return true; } - - public RenderTexture PreviewTexture; - - // the main ObjectPreview function... it's called constantly, like other IMGUI On*GUI() functions - public override void OnPreviewGUI(Rect r, GUIStyle background) - { - // if this is happening, you have bigger problems - if (!ShaderUtil.hardwareSupportsRectRenderTexture) - { - if (Event.current.type == EventType.Repaint) - { - EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40f), - "Mesh preview requires\nrender texture support"); - } - return; - } - - var src = r; - - var min = Mathf.Min(r.width, r.height); - r.width = min; - r.height = min; - r.x = src.x + (src.width - min) / 2; - r.y = src.y + (src.height - min) / 2; - - //previewDir = Drag2D(previewDir, r); - { - int controlId = GUIUtility.GetControlID(sliderHash, FocusType.Passive); - Event e = Event.current; - switch (e.GetTypeForControl(controlId)) - { - case EventType.MouseDown: - if (r.Contains(e.mousePosition) && (double)r.width > 50.0) - { - GUIUtility.hotControl = controlId; - e.Use(); - EditorGUIUtility.SetWantsMouseJumping(1); - break; - } - break; - - case EventType.MouseUp: - if (GUIUtility.hotControl == controlId) - GUIUtility.hotControl = 0; - EditorGUIUtility.SetWantsMouseJumping(0); - break; - - case EventType.MouseDrag: - if (GUIUtility.hotControl == controlId) - { - if (e.button == 2) - { - var shift = e.delta * (!e.shift ? 1f : 3f) / Mathf.Min(r.width, r.height); - m_position.x -= shift.x; - m_position.y += shift.y; - e.Use(); - GUI.changed = true; - } - else if ( - e.button == 0 || - e.button == 1) - { - var shift = e.delta * (!e.shift ? 1f : 3f) / Mathf.Min(r.width, r.height) * 140f; - m_yaw += shift.x; - m_pitch += shift.y; - m_pitch = Mathf.Clamp(m_pitch, -90f, 90f); - e.Use(); - GUI.changed = true; - } - break; - } - break; - - case EventType.ScrollWheel: - //Debug.LogFormat("wheel: {0}", current.delta); - if (r.Contains(e.mousePosition)) - { - if (e.delta.y > 0) - { - m_position.z *= 1.1f; - Repaint(); - } - else if (e.delta.y < 0) - { - m_position.z *= 0.9f; - Repaint(); - } - } - break; - } - //return scrollPosition; - } - //Debug.LogFormat("{0}", previewDir); - - if (Event.current.type != EventType.Repaint) - { - // if we don't need to update yet, then don't - return; - } - - if (m_renderer != null && m_scene != null) - { - PreviewTexture = m_renderer.Render(r, background, m_scene, m_yaw, m_pitch, m_position) as RenderTexture; - if (PreviewTexture != null) - { - // draw the RenderTexture in the ObjectPreview pane - GUI.DrawTexture(r, PreviewTexture, ScaleMode.StretchToFill, false); - } - } - } - - public static VRM10Expression CreateExpression(string path) - { - //Debug.LogFormat("{0}", path); - var clip = ScriptableObject.CreateInstance(); - clip.ExpressionName = Path.GetFileNameWithoutExtension(path); - AssetDatabase.CreateAsset(clip, path); - AssetDatabase.ImportAsset(path); - return clip; - //Clips.Add(clip); - //EditorUtility.SetDirty(this); - //AssetDatabase.SaveAssets(); - } - } -} diff --git a/Assets/VRM10/Editor/Components/Expression/ExpressionEditorBase.cs.meta b/Assets/VRM10/Editor/Components/Expression/ExpressionEditorBase.cs.meta deleted file mode 100644 index 9e2ce3b385..0000000000 --- a/Assets/VRM10/Editor/Components/Expression/ExpressionEditorBase.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6a64fbc26ee3c274fbfd9bce32f0b5dd -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/VRM10/Editor/Components/Expression/VRM10ExpressionEditor.cs b/Assets/VRM10/Editor/Components/Expression/VRM10ExpressionEditor.cs index 1e2fad39a9..b5421ee8ef 100644 --- a/Assets/VRM10/Editor/Components/Expression/VRM10ExpressionEditor.cs +++ b/Assets/VRM10/Editor/Components/Expression/VRM10ExpressionEditor.cs @@ -8,26 +8,263 @@ namespace UniVRM10 { [CustomEditor(typeof(VRM10Expression))] - public class ExpressionEditor : ExpressionEditorBase + public class ExpressionEditor : Editor { - SerializedExpressionEditor m_serializedEditor; + /// + /// PreviewRenderUtilityを管理する。 + /// + /// * PreviewRenderUtility.m_cameraのUnityVersionによる切り分け + /// + /// + PreviewFaceRenderer m_renderer; - VRM10Expression m_target; - protected override VRM10Expression CurrentExpression() + /// + /// Prefabをインスタンス化したシーンを管理する。 + /// + /// * ExpressionのBake + /// * MaterialMorphの適用 + /// * Previewカメラのコントロール + /// * Previewライティングのコントロール + /// + /// + PreviewSceneManager m_scene; + PreviewSceneManager PreviewSceneManager { - return m_target; + get { return m_scene; } } - protected override GameObject GetPrefab() + /// + /// Previewシーンに表示するPrefab + /// + GameObject m_prefab; + GameObject Prefab { - return m_target.Prefab; + get { return m_prefab; } + set + { + if (m_prefab == value) return; + + //Debug.LogFormat("Prefab = {0}", value); + m_prefab = value; + + if (m_scene != null) + { + //Debug.LogFormat("OnDestroy"); + GameObject.DestroyImmediate(m_scene.gameObject); + m_scene = null; + } + + if (m_prefab != null) + { + m_scene = UniVRM10.PreviewSceneManager.GetOrCreate(m_prefab); + if (m_scene != null) + { + m_scene.gameObject.SetActive(false); + } + + Bake(); + } + } } - protected override void OnEnable() + /// + /// Preview シーンに Expression を適用する + /// + void Bake() + { + if (m_scene != null) + { + //Debug.Log("Bake"); + m_scene.Bake(CurrentExpression(), 1.0f); + } + } + + void OnEnable() { m_target = (VRM10Expression)target; + m_renderer = new PreviewFaceRenderer(); + Prefab = GetPrefab(); + } + + void OnDisable() + { + if (m_renderer != null) + { + m_renderer.Dispose(); + m_renderer = null; + } + ClearScene(); + } + + void OnDestroy() + { + // 2018/2019 で OnDisable/OnDestroy の呼ばれ方が違う? + ClearScene(); + } + + void ClearScene() + { + if (m_scene != null) + { + //Debug.LogFormat("OnDestroy"); + m_scene.Clean(); + GameObject.DestroyImmediate(m_scene.gameObject); + m_scene = null; + } + } + + static void Separator() + { + EditorGUILayout.Space(); + EditorGUILayout.BeginHorizontal(); + //GUILayout.Space(); + GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1)); + EditorGUILayout.EndHorizontal(); + EditorGUILayout.Space(); + } + + private static int sliderHash = "Slider".GetHashCode(); + float m_yaw = 180.0f; + float m_pitch; + Vector3 m_position = new Vector3(0, 0, -0.8f); + + // very important to override this, it tells Unity to render an ObjectPreview at the bottom of the inspector + public override bool HasPreviewGUI() { return true; } - base.OnEnable(); + public RenderTexture PreviewTexture; + + // the main ObjectPreview function... it's called constantly, like other IMGUI On*GUI() functions + public override void OnPreviewGUI(Rect r, GUIStyle background) + { + // if this is happening, you have bigger problems + if (!ShaderUtil.hardwareSupportsRectRenderTexture) + { + if (Event.current.type == EventType.Repaint) + { + EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40f), + "Mesh preview requires\nrender texture support"); + } + return; + } + + var src = r; + + var min = Mathf.Min(r.width, r.height); + r.width = min; + r.height = min; + r.x = src.x + (src.width - min) / 2; + r.y = src.y + (src.height - min) / 2; + + //previewDir = Drag2D(previewDir, r); + { + int controlId = GUIUtility.GetControlID(sliderHash, FocusType.Passive); + Event e = Event.current; + switch (e.GetTypeForControl(controlId)) + { + case EventType.MouseDown: + if (r.Contains(e.mousePosition) && (double)r.width > 50.0) + { + GUIUtility.hotControl = controlId; + e.Use(); + EditorGUIUtility.SetWantsMouseJumping(1); + break; + } + break; + + case EventType.MouseUp: + if (GUIUtility.hotControl == controlId) + GUIUtility.hotControl = 0; + EditorGUIUtility.SetWantsMouseJumping(0); + break; + + case EventType.MouseDrag: + if (GUIUtility.hotControl == controlId) + { + if (e.button == 2) + { + var shift = e.delta * (!e.shift ? 1f : 3f) / Mathf.Min(r.width, r.height); + m_position.x -= shift.x; + m_position.y += shift.y; + e.Use(); + GUI.changed = true; + } + else if ( + e.button == 0 || + e.button == 1) + { + var shift = e.delta * (!e.shift ? 1f : 3f) / Mathf.Min(r.width, r.height) * 140f; + m_yaw += shift.x; + m_pitch += shift.y; + m_pitch = Mathf.Clamp(m_pitch, -90f, 90f); + e.Use(); + GUI.changed = true; + } + break; + } + break; + + case EventType.ScrollWheel: + //Debug.LogFormat("wheel: {0}", current.delta); + if (r.Contains(e.mousePosition)) + { + if (e.delta.y > 0) + { + m_position.z *= 1.1f; + Repaint(); + } + else if (e.delta.y < 0) + { + m_position.z *= 0.9f; + Repaint(); + } + } + break; + } + //return scrollPosition; + } + //Debug.LogFormat("{0}", previewDir); + + if (Event.current.type != EventType.Repaint) + { + // if we don't need to update yet, then don't + return; + } + + if (m_renderer != null && m_scene != null) + { + PreviewTexture = m_renderer.Render(r, background, m_scene, m_yaw, m_pitch, m_position) as RenderTexture; + if (PreviewTexture != null) + { + // draw the RenderTexture in the ObjectPreview pane + GUI.DrawTexture(r, PreviewTexture, ScaleMode.StretchToFill, false); + } + } + } + + public static VRM10Expression CreateExpression(string path) + { + //Debug.LogFormat("{0}", path); + var clip = ScriptableObject.CreateInstance(); + clip.ExpressionName = Path.GetFileNameWithoutExtension(path); + AssetDatabase.CreateAsset(clip, path); + AssetDatabase.ImportAsset(path); + return clip; + //Clips.Add(clip); + //EditorUtility.SetDirty(this); + //AssetDatabase.SaveAssets(); + } + + SerializedExpressionEditor m_serializedEditor; + + VRM10Expression m_target; + VRM10Expression CurrentExpression() + { + return m_target; + } + + GameObject GetPrefab() + { + return m_target.Prefab; } float m_previewSlider = 1.0f; @@ -88,7 +325,8 @@ public override void OnInspectorGUI() var changed = false; EditorGUILayout.BeginVertical(); - base.OnInspectorGUI(); + + Prefab = (GameObject)EditorGUILayout.ObjectField("Preview Prefab", Prefab, typeof(GameObject), false); EditorGUILayout.LabelField("Preview Weight"); var previewSlider = EditorGUILayout.Slider(m_previewSlider, 0, 1.0f); @@ -118,6 +356,8 @@ public override void OnInspectorGUI() { PreviewSceneManager.Bake(bakeValue, m_previewSlider); } + + serializedObject.ApplyModifiedProperties(); } } } From c1c778e9071f00136717ea5010b238da7aa5ba1c Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 29 Jul 2021 17:42:21 +0900 Subject: [PATCH 3/5] =?UTF-8?q?*=20PreviewPrefab=20=E3=81=AE=20ObjectField?= =?UTF-8?q?=20=E3=82=92=E5=B8=B8=E6=99=82=E8=A1=A8=E7=A4=BA=20*=20m=5Fscen?= =?UTF-8?q?e=20=E3=81=AE=E3=83=A9=E3=82=A4=E3=83=95=E3=82=B5=E3=82=A4?= =?UTF-8?q?=E3=82=AF=E3=83=AB=E3=82=92=E6=95=B4=E7=90=86(=E7=94=9F?= =?UTF-8?q?=E6=88=90=E3=82=92=E9=81=85=E5=BB=B6=E3=80=82OnDestroy=E3=81=A8?= =?UTF-8?q?Prefab=E3=81=8C=E5=A4=89=E6=9B=B4=E3=81=95=E3=82=8C=E3=81=9F?= =?UTF-8?q?=E6=99=82=E3=81=AB=E7=A0=B4=E6=A3=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Expression/VRM10ExpressionEditor.cs | 131 +++++++----------- 1 file changed, 51 insertions(+), 80 deletions(-) diff --git a/Assets/VRM10/Editor/Components/Expression/VRM10ExpressionEditor.cs b/Assets/VRM10/Editor/Components/Expression/VRM10ExpressionEditor.cs index b5421ee8ef..117ffcfb4b 100644 --- a/Assets/VRM10/Editor/Components/Expression/VRM10ExpressionEditor.cs +++ b/Assets/VRM10/Editor/Components/Expression/VRM10ExpressionEditor.cs @@ -11,7 +11,7 @@ namespace UniVRM10 public class ExpressionEditor : Editor { /// - /// PreviewRenderUtilityを管理する。 + /// Preview(Inspectorの下方)を描画するクラス /// /// * PreviewRenderUtility.m_cameraのUnityVersionによる切り分け /// @@ -19,7 +19,8 @@ public class ExpressionEditor : Editor PreviewFaceRenderer m_renderer; /// - /// Prefabをインスタンス化したシーンを管理する。 + /// Previewを描画するのにシーンが必用である。 + /// m_target.Prefabをインスタンス化したシーンを管理する。 /// /// * ExpressionのBake /// * MaterialMorphの適用 @@ -28,62 +29,45 @@ public class ExpressionEditor : Editor /// /// PreviewSceneManager m_scene; - PreviewSceneManager PreviewSceneManager - { - get { return m_scene; } - } /// - /// Previewシーンに表示するPrefab + /// Preview シーンに Expression を適用する /// - GameObject m_prefab; - GameObject Prefab + void Bake() { - get { return m_prefab; } - set + if (m_scene != null) { - if (m_prefab == value) return; - - //Debug.LogFormat("Prefab = {0}", value); - m_prefab = value; - - if (m_scene != null) - { - //Debug.LogFormat("OnDestroy"); - GameObject.DestroyImmediate(m_scene.gameObject); - m_scene = null; - } - - if (m_prefab != null) - { - m_scene = UniVRM10.PreviewSceneManager.GetOrCreate(m_prefab); - if (m_scene != null) - { - m_scene.gameObject.SetActive(false); - } - - Bake(); - } + //Debug.Log("Bake"); + m_scene.Bake(CurrentExpression(), 1.0f); } } - /// - /// Preview シーンに Expression を適用する - /// - void Bake() + void ClearScene() { if (m_scene != null) { - //Debug.Log("Bake"); - m_scene.Bake(CurrentExpression(), 1.0f); + //Debug.LogFormat("OnDestroy"); + m_scene.Clean(); + GameObject.DestroyImmediate(m_scene.gameObject); + m_scene = null; } } + void PrefabGUI() + { + var prefab = (GameObject)EditorGUILayout.ObjectField("Preview Prefab", m_target.Prefab, typeof(GameObject), false); + if (prefab == m_target.Prefab) + { + return; + } + ClearScene(); + m_target.Prefab = prefab; + } + void OnEnable() { m_target = (VRM10Expression)target; m_renderer = new PreviewFaceRenderer(); - Prefab = GetPrefab(); } void OnDisable() @@ -102,17 +86,6 @@ void OnDestroy() ClearScene(); } - void ClearScene() - { - if (m_scene != null) - { - //Debug.LogFormat("OnDestroy"); - m_scene.Clean(); - GameObject.DestroyImmediate(m_scene.gameObject); - m_scene = null; - } - } - static void Separator() { EditorGUILayout.Space(); @@ -262,11 +235,6 @@ VRM10Expression CurrentExpression() return m_target; } - GameObject GetPrefab() - { - return m_target.Prefab; - } - float m_previewSlider = 1.0f; static Texture2D SaveResizedImage(RenderTexture rt, UnityPath path, int size) @@ -310,51 +278,54 @@ static Texture2D SaveResizedImage(RenderTexture rt, UnityPath path, int size) public override void OnInspectorGUI() { - if (PreviewSceneManager == null) - { - return; - } + var changed = false; serializedObject.Update(); - if (m_serializedEditor == null) - { - m_serializedEditor = new SerializedExpressionEditor(serializedObject, PreviewSceneManager); - } - EditorGUILayout.BeginHorizontal(); - - var changed = false; EditorGUILayout.BeginVertical(); - - Prefab = (GameObject)EditorGUILayout.ObjectField("Preview Prefab", Prefab, typeof(GameObject), false); + PrefabGUI(); EditorGUILayout.LabelField("Preview Weight"); var previewSlider = EditorGUILayout.Slider(m_previewSlider, 0, 1.0f); - - EditorGUILayout.EndVertical(); - - if (m_serializedEditor.IsBinary) + if (m_target.IsBinary) { previewSlider = Mathf.Round(previewSlider); } - if (previewSlider != m_previewSlider) { m_previewSlider = previewSlider; changed = true; } - + EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); Separator(); - // EditorGUILayout.Space(); - if (m_serializedEditor.Draw(out VRM10Expression bakeValue)) + if (m_scene == null) { - changed = true; + if (m_target.Prefab != null) + { + m_scene = UniVRM10.PreviewSceneManager.GetOrCreate(m_target.Prefab); + if (m_scene != null) + { + m_scene.gameObject.SetActive(false); + } + Bake(); + } } - if (changed && PreviewSceneManager != null) + if (m_scene != null) { - PreviewSceneManager.Bake(bakeValue, m_previewSlider); + if (m_serializedEditor == null) + { + m_serializedEditor = new SerializedExpressionEditor(serializedObject, m_scene); + } + if (m_serializedEditor.Draw(out VRM10Expression bakeValue)) + { + changed = true; + } + if (changed) + { + m_scene.Bake(bakeValue, m_previewSlider); + } } serializedObject.ApplyModifiedProperties(); From a7d0880295ff38ecadab2f4b7f4f0122bcfe7f52 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 29 Jul 2021 17:50:54 +0900 Subject: [PATCH 4/5] null check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 何故か null の時がある --- .../UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs index b91a57190e..169e13a5a1 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs @@ -81,7 +81,7 @@ protected bool CanExtract(ScriptedImporter importer) { foreach (var key in m_keys) { - if (k.type.IsAssignableFrom(key.Type)) + if (k.type != null && k.type.IsAssignableFrom(key.Type)) { return false; } From 819fb95a25e33415f9591a1fea12ba846f9dceff Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 29 Jul 2021 17:51:38 +0900 Subject: [PATCH 5/5] =?UTF-8?q?Extract=20=E6=99=82=E3=81=AB=20VRM10Express?= =?UTF-8?q?ion.Prefab=20=E3=82=92=E3=82=BB=E3=83=83=E3=83=88=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs b/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs index 669668b19a..86a952ceb6 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs @@ -58,12 +58,18 @@ public static void Extract(ScriptedImporter importer, GltfData data) var path = GetAndCreateFolder(importer.assetPath, ".vrm1.Assets"); + var assets = AssetDatabase.LoadAllAssetsAtPath(importer.assetPath); + var prefab = assets.First(x => x is GameObject) as GameObject; + // expression を extract し置き換え map を作る var map = new Dictionary(); - foreach (var asset in AssetDatabase.LoadAllAssetsAtPath(importer.assetPath)) + foreach (var asset in assets) { if (asset is VRM10Expression expression) { + // preview用のprefab + expression.Prefab = prefab; + var clone = ExtractSubAsset(asset, $"{path}/{asset.name}.asset", false); map.Add(expression, clone as VRM10Expression); }