using System.Linq; using UnityEditor; using UnityEngine; #if UNITY_2020_2_OR_NEWER using UnityEditor.AssetImporters; #else using UnityEditor.Experimental.AssetImporters; #endif namespace UniVRM10 { [CustomEditor(typeof(VrmScriptedImporter))] public class VrmScriptedImporterEditorGUI : ScriptedImporterEditor { private bool _isOpen = true; public override void OnInspectorGUI() { var importer = target as VrmScriptedImporter; EditorGUILayout.LabelField("Extract settings"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Materials And Textures"); GUI.enabled = !(importer.GetExternalUnityObjects().Any() && importer.GetExternalUnityObjects().Any()); if (GUILayout.Button("Extract")) { importer.ExtractMaterialsAndTextures(); } GUI.enabled = !GUI.enabled; if (GUILayout.Button("Clear")) { importer.ClearExternalObjects(); importer.ClearExternalObjects(); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Meta"); GUI.enabled = !importer.GetExternalUnityObjects().Any(); if (GUILayout.Button("Extract")) { importer.ExtractMeta(); } GUI.enabled = !GUI.enabled; if (GUILayout.Button("Clear")) { importer.ClearExternalObjects(); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Expressions"); GUI.enabled = !(importer.GetExternalUnityObjects().Any() && importer.GetExternalUnityObjects().Any()); if (GUILayout.Button("Extract")) { importer.ExtractExpressions(); } GUI.enabled = !GUI.enabled; if (GUILayout.Button("Clear")) { importer.ClearExternalObjects(); importer.ClearExternalObjects(); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); // ObjectMap DrawRemapGUI("Material Remap", importer); DrawRemapGUI("Texture Remap", importer); DrawRemapGUI("Meta Remap", importer); DrawRemapGUI("ExpressionAvatar Remap", importer); DrawRemapGUI("Expression Remap", importer); base.OnInspectorGUI(); } private void DrawRemapGUI(string title, VrmScriptedImporter importer) where T : UnityEngine.Object { EditorGUILayout.Foldout(_isOpen, title); EditorGUI.indentLevel++; var objects = importer.GetExternalObjectMap().Where(x => x.Key.type == typeof(T)); foreach (var obj in objects) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(obj.Key.name); var asset = EditorGUILayout.ObjectField(obj.Value, obj.Key.type, true) as T; if (asset != obj.Value) { importer.SetExternalUnityObject(obj.Key, asset); } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; } } }