From f6c0f475cd532571b552f778d412fe527e4434ac Mon Sep 17 00:00:00 2001 From: ousttrue Date: Fri, 18 Jun 2021 19:33:23 +0900 Subject: [PATCH] RemapEditorBase --- .../GlbScriptedImporterEditorGUI.cs | 7 ++- .../GltfScriptedImporterEditorGUI.cs | 7 ++- ...orAnimation.cs => RemapEditorAnimation.cs} | 8 ++-- .../RemapEditorAnimation.cs.meta} | 2 +- .../ScriptedImporter/RemapEditorBase.cs | 44 +++++++++++++++++++ ...mation.cs.meta => RemapEditorBase.cs.meta} | 2 +- ...itorMaterial.cs => RemapEditorMaterial.cs} | 24 +++++----- ...al.cs.meta => RemapEditorMaterial.cs.meta} | 2 +- .../ScriptedImporterExtension.cs | 27 ------------ .../{EditorVrm.cs => RemapEditorVrm.cs} | 8 ++-- .../ScriptedImporter/RemapEditorVrm.cs.meta | 11 +++++ .../VrmScriptedImporterEditorGUI.cs | 7 ++- 12 files changed, 91 insertions(+), 58 deletions(-) rename Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/{EditorAnimation.cs => RemapEditorAnimation.cs} (87%) rename Assets/{VRM10/Editor/ScriptedImporter/EditorVrm.cs.meta => UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs.meta} (83%) create mode 100644 Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs rename Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/{EditorAnimation.cs.meta => RemapEditorBase.cs.meta} (83%) rename Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/{EditorMaterial.cs => RemapEditorMaterial.cs} (70%) rename Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/{EditorMaterial.cs.meta => RemapEditorMaterial.cs.meta} (83%) rename Assets/VRM10/Editor/ScriptedImporter/{EditorVrm.cs => RemapEditorVrm.cs} (87%) create mode 100644 Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs.meta diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs index f762ebfd3..e5facd50c 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs @@ -16,6 +16,9 @@ namespace UniGLTF GlbScriptedImporter m_importer; GltfParser m_parser; + RemapEditorMaterial m_materialEditor = new RemapEditorMaterial(); + RemapEditorAnimation m_animationEditor = new RemapEditorAnimation(); + public override void OnEnable() { base.OnEnable(); @@ -45,11 +48,11 @@ namespace UniGLTF break; case Tabs.Animation: - EditorAnimation.OnGUIAnimation(m_importer, m_parser); + m_animationEditor.OnGUI(m_importer, m_parser); break; case Tabs.Materials: - EditorMaterial.OnGUI(m_importer, m_parser, new GltfTextureDescriptorGenerator(m_parser), + m_materialEditor.OnGUI(m_importer, m_parser, new GltfTextureDescriptorGenerator(m_parser), assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures", assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials"); break; diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs index 150d94f11..33cd5c599 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs @@ -16,6 +16,9 @@ namespace UniGLTF GltfScriptedImporter m_importer; GltfParser m_parser; + RemapEditorMaterial m_materialEditor = new RemapEditorMaterial(); + RemapEditorAnimation m_animationEditor = new RemapEditorAnimation(); + public override void OnEnable() { base.OnEnable(); @@ -45,11 +48,11 @@ namespace UniGLTF break; case Tabs.Animation: - EditorAnimation.OnGUIAnimation(m_importer, m_parser); + m_animationEditor.OnGUI(m_importer, m_parser); break; case Tabs.Materials: - EditorMaterial.OnGUI(m_importer, m_parser, new GltfTextureDescriptorGenerator(m_parser), + m_materialEditor.OnGUI(m_importer, m_parser, new GltfTextureDescriptorGenerator(m_parser), assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures", assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials"); break; diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorAnimation.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs similarity index 87% rename from Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorAnimation.cs rename to Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs index 632b65ccb..167e433da 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorAnimation.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs @@ -8,9 +8,9 @@ using VRMShaders; namespace UniGLTF { - public static class EditorAnimation + public class RemapEditorAnimation: RemapEditorBase { - public static void OnGUIAnimation(ScriptedImporter importer, GltfParser parser) + public void OnGUI(ScriptedImporter importer, GltfParser parser) { var hasExternal = importer.GetExternalObjectMap().Any(x => x.Value is AnimationClip); using (new EditorGUI.DisabledScope(hasExternal)) @@ -21,7 +21,7 @@ namespace UniGLTF } } - importer.DrawRemapGUI(AnimationImporterUtil.EnumerateSubAssetKeys(parser.GLTF)); + DrawRemapGUI(importer, AnimationImporterUtil.EnumerateSubAssetKeys(parser.GLTF)); if (GUILayout.Button("Clear")) { @@ -58,6 +58,6 @@ namespace UniGLTF } AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate); - } + } } } diff --git a/Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs.meta b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs.meta similarity index 83% rename from Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs.meta rename to Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs.meta index d523d2332..a0014f3bc 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs.meta +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: a15559f8a5ba86841a1ef6e08d37569a +guid: 11ced9da7136c3546bb9c65e3e35bb34 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs new file mode 100644 index 000000000..ad7989cd5 --- /dev/null +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEditor.Experimental.AssetImporters; +using VRMShaders; + +namespace UniGLTF +{ + public abstract class RemapEditorBase + { + void RemapAndReload(ScriptedImporter self, UnityEditor.AssetImporter.SourceAssetIdentifier sourceAssetIdentifier, T obj) where T : UnityEngine.Object + { + self.AddRemap(sourceAssetIdentifier, obj); + AssetDatabase.WriteImportSettingsIfDirty(self.assetPath); + AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); + } + + protected void DrawRemapGUI(ScriptedImporter importer, IEnumerable keys) where T : UnityEngine.Object + { + EditorGUI.indentLevel++; + { + var map = importer.GetExternalObjectMap(); + foreach (var key in keys) + { + if (string.IsNullOrEmpty(key.Name)) + { + continue; + } + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.PrefixLabel(key.Name); + map.TryGetValue(new AssetImporter.SourceAssetIdentifier(key.Type, key.Name), out UnityEngine.Object value); + var asset = EditorGUILayout.ObjectField(value, typeof(T), true) as T; + if (asset != value) + { + // update + RemapAndReload(importer, new AssetImporter.SourceAssetIdentifier(key.Type, key.Name), asset); + } + EditorGUILayout.EndHorizontal(); + } + } + EditorGUI.indentLevel--; + } + } +} diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorAnimation.cs.meta b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs.meta similarity index 83% rename from Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorAnimation.cs.meta rename to Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs.meta index c426102d8..5203ba494 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorAnimation.cs.meta +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 005298fbae4759b4896174bb6e129e9d +guid: 43b33bc54de8f3a4b82690bf090ed661 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorMaterial.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs similarity index 70% rename from Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorMaterial.cs rename to Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs index 60a93285d..1c6e5134c 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorMaterial.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs @@ -14,12 +14,15 @@ using UnityEditor.Experimental.AssetImporters; namespace UniGLTF { - public static class EditorMaterial + /// + /// Material, Texture の Remap, Extract + /// + public class RemapEditorMaterial: RemapEditorBase { static bool s_foldMaterials = true; static bool s_foldTextures = true; - public static void OnGUI(ScriptedImporter importer, GltfParser parser, ITextureDescriptorGenerator textureDescriptorGenerator, Func textureDir, Func materialDir) + public void OnGUI(ScriptedImporter importer, GltfParser parser, ITextureDescriptorGenerator textureDescriptorGenerator, Func textureDir, Func materialDir) { var hasExternal = importer.GetExternalObjectMap().Any(x => x.Value is Material || x.Value is Texture2D); using (new EditorGUI.DisabledScope(hasExternal)) @@ -36,13 +39,13 @@ namespace UniGLTF s_foldMaterials = EditorGUILayout.Foldout(s_foldMaterials, "Remapped Materials"); if (s_foldMaterials) { - importer.DrawRemapGUI(parser.GLTF.materials.Select(x => new SubAssetKey(typeof(Material), x.name))); + DrawRemapGUI(importer, parser.GLTF.materials.Select(x => new SubAssetKey(typeof(Material), x.name))); } s_foldTextures = EditorGUILayout.Foldout(s_foldTextures, "Remapped Textures"); if (s_foldTextures) { - importer.DrawRemapGUI(textureDescriptorGenerator.Get().GetEnumerable().Select(x => x.SubAssetKey)); + DrawRemapGUI(importer, textureDescriptorGenerator.Get().GetEnumerable().Select(x => x.SubAssetKey)); } if (GUILayout.Button("Clear")) @@ -53,14 +56,7 @@ namespace UniGLTF } } - public static void SetExternalUnityObject(this ScriptedImporter self, UnityEditor.AssetImporter.SourceAssetIdentifier sourceAssetIdentifier, T obj) where T : UnityEngine.Object - { - self.AddRemap(sourceAssetIdentifier, obj); - AssetDatabase.WriteImportSettingsIfDirty(self.assetPath); - AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); - } - - static void ExtractMaterialsAndTextures(ScriptedImporter self, GltfParser parser, ITextureDescriptorGenerator textureDescriptorGenerator, Func textureDir, Func materialDir) + void ExtractMaterialsAndTextures(ScriptedImporter self, GltfParser parser, ITextureDescriptorGenerator textureDescriptorGenerator, Func textureDir, Func materialDir) { if (string.IsNullOrEmpty(self.assetPath)) { @@ -74,7 +70,7 @@ namespace UniGLTF Action> onCompleted = _ => { AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); - self.ExtractMaterials(materialDir); + ExtractMaterials(self, materialDir); AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); }; @@ -90,7 +86,7 @@ namespace UniGLTF ); } - public static void ExtractMaterials(this ScriptedImporter importer, Func materialDir) + public void ExtractMaterials(ScriptedImporter importer, Func materialDir) { if (string.IsNullOrEmpty(importer.assetPath)) { diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorMaterial.cs.meta b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs.meta similarity index 83% rename from Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorMaterial.cs.meta rename to Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs.meta index ae9423568..131cb03c4 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorMaterial.cs.meta +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: d87d4a592573eb048916575e202af37f +guid: 85720aed7aabf5e4c86c9ea492f05f00 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterExtension.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterExtension.cs index 834e09777..9f61cc4b9 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterExtension.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterExtension.cs @@ -46,33 +46,6 @@ namespace UniGLTF .Select(x => (new SubAssetKey(typeof(T), x.name), x as T)); } - public static void DrawRemapGUI(this ScriptedImporter importer, IEnumerable keys) where T : UnityEngine.Object - { - EditorGUI.indentLevel++; - { - var map = importer.GetExternalObjectMap(); - foreach (var key in keys) - { - if (string.IsNullOrEmpty(key.Name)) - { - continue; - } - - EditorGUILayout.BeginHorizontal(); - EditorGUILayout.PrefixLabel(key.Name); - map.TryGetValue(new AssetImporter.SourceAssetIdentifier(key.Type, key.Name), out UnityEngine.Object value); - var asset = EditorGUILayout.ObjectField(value, typeof(T), true) as T; - if (asset != value) - { - // update - importer.SetExternalUnityObject(new AssetImporter.SourceAssetIdentifier(key.Type, key.Name), asset); - } - EditorGUILayout.EndHorizontal(); - } - } - EditorGUI.indentLevel--; - } - /// /// subAsset を 指定された path に extract する /// diff --git a/Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs b/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs similarity index 87% rename from Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs rename to Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs index 8bc8507a6..6819235f5 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs @@ -14,9 +14,9 @@ using UnityEditor.Experimental.AssetImporters; namespace UniVRM10 { - public static class EditorVrm + public class RemapEditorVrm: RemapEditorBase { - public static void OnGUI(ScriptedImporter importer, GltfParser parser, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm) + public void OnGUI(ScriptedImporter importer, GltfParser parser, UniGLTF.Extensions.VRMC_vrm.VRMC_vrm vrm) { var hasExternal = importer.GetExternalObjectMap().Any(x => x.Value is VRM10Object || x.Value is VRM10Expression); using (new EditorGUI.DisabledScope(hasExternal)) @@ -28,10 +28,10 @@ namespace UniVRM10 } // meta - importer.DrawRemapGUI(new SubAssetKey[] { VRM10Object.SubAssetKey }); + DrawRemapGUI(importer, new SubAssetKey[] { VRM10Object.SubAssetKey }); // expressions - importer.DrawRemapGUI(vrm.Expressions.Select(x => ExpressionKey.CreateFromVrm10(x).SubAssetKey)); + DrawRemapGUI(importer, vrm.Expressions.Select(x => ExpressionKey.CreateFromVrm10(x).SubAssetKey)); if (GUILayout.Button("Clear")) { diff --git a/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs.meta b/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs.meta new file mode 100644 index 000000000..d6df07649 --- /dev/null +++ b/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d312fe4d8589d4d4a99768165d55f1b5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs index 2cd336bcd..558c1f7e6 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs @@ -20,6 +20,9 @@ namespace UniVRM10 VrmLib.Model m_model; UniGLTF.Extensions.VRMC_vrm.VRMC_vrm m_vrm; + RemapEditorMaterial m_materialEditor = new RemapEditorMaterial(); + RemapEditorVrm m_vrmEditor = new RemapEditorVrm(); + string m_message; public override void OnEnable() @@ -66,7 +69,7 @@ namespace UniVRM10 case Tabs.Materials: if (m_parser != null && m_vrm != null) { - EditorMaterial.OnGUI(m_importer, m_parser, new Vrm10TextureDescriptorGenerator(m_parser), + m_materialEditor.OnGUI(m_importer, m_parser, new Vrm10TextureDescriptorGenerator(m_parser), assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Textures", assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Materials"); } @@ -75,7 +78,7 @@ namespace UniVRM10 case Tabs.Vrm: if (m_parser != null && m_vrm != null) { - EditorVrm.OnGUI(m_importer, m_parser, m_vrm); + m_vrmEditor.OnGUI(m_importer, m_parser, m_vrm); } break; }