diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorMaterial.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorMaterial.cs index 84a4d350e..ad8262bba 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorMaterial.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/EditorMaterial.cs @@ -33,14 +33,14 @@ namespace UniGLTF static bool s_foldMaterials = true; static bool s_foldTextures = true; - public static void OnGUI(ScriptedImporter importer, GltfParser parser, EnumerateAllTexturesDistinctFunc enumTextures) + public static void OnGUI(ScriptedImporter importer, GltfParser parser, EnumerateAllTexturesDistinctFunc enumTextures, Func textureDir, Func materialDir) { var hasExternal = importer.GetExternalObjectMap().Any(x => x.Value is Material || x.Value is Texture2D); using (new TmpGuiEnable(!hasExternal)) { if (GUILayout.Button("Extract Materials And Textures ...")) { - ExtractMaterialsAndTextures(importer, parser, enumTextures); + ExtractMaterialsAndTextures(importer, parser, enumTextures, textureDir, materialDir); } } @@ -85,7 +85,7 @@ namespace UniGLTF AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); } - static void ExtractMaterialsAndTextures(ScriptedImporter self, GltfParser parser, EnumerateAllTexturesDistinctFunc enumTextures) + static void ExtractMaterialsAndTextures(ScriptedImporter self, GltfParser parser, EnumerateAllTexturesDistinctFunc enumTextures, Func textureDir, Func materialDir) { if (string.IsNullOrEmpty(self.assetPath)) { @@ -99,12 +99,12 @@ namespace UniGLTF Action> onCompleted = _ => { AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); - self.ExtractMaterials(); + self.ExtractMaterials(materialDir); AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); }; var assetPath = UnityPath.FromFullpath(parser.TargetPath); - var dirName = $"{assetPath.FileNameWithoutExtension}.Textures"; + var dirName = textureDir(assetPath.Value); // $"{assetPath.FileNameWithoutExtension}.Textures"; TextureExtractor.ExtractTextures(parser, assetPath.Parent.Child(dirName), enumTextures, self.GetSubAssets(self.assetPath).ToArray(), @@ -113,13 +113,13 @@ namespace UniGLTF ); } - public static void ExtractMaterials(this ScriptedImporter importer) + public static void ExtractMaterials(this ScriptedImporter importer, Func materialDir) { if (string.IsNullOrEmpty(importer.assetPath)) { return; } - var path = $"{Path.GetDirectoryName(importer.assetPath)}/{Path.GetFileNameWithoutExtension(importer.assetPath)}.Materials"; + var path = $"{Path.GetDirectoryName(importer.assetPath)}/{materialDir(importer.assetPath)}"; // Path.GetFileNameWithoutExtension(importer.assetPath)}.Materials if (!Directory.Exists(path)) { Directory.CreateDirectory(path); diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs index 08f38013c..65e4d14d2 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs @@ -1,5 +1,6 @@ using UnityEditor; using UnityEngine; +using System.IO; #if UNITY_2020_2_OR_NEWER using UnityEditor.AssetImporters; #else @@ -48,7 +49,9 @@ namespace UniGLTF break; case Tabs.Materials: - EditorMaterial.OnGUI(m_importer, m_parser, GltfTextureEnumerator.EnumerateAllTexturesDistinct); + EditorMaterial.OnGUI(m_importer, m_parser, GltfTextureEnumerator.EnumerateAllTexturesDistinct, + 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 8e90514ab..f184f1cb6 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs @@ -1,5 +1,6 @@ using UnityEditor; using UnityEngine; +using System.IO; #if UNITY_2020_2_OR_NEWER using UnityEditor.AssetImporters; #else @@ -48,7 +49,9 @@ namespace UniGLTF break; case Tabs.Materials: - EditorMaterial.OnGUI(m_importer, m_parser, GltfTextureEnumerator.EnumerateAllTexturesDistinct); + EditorMaterial.OnGUI(m_importer, m_parser, GltfTextureEnumerator.EnumerateAllTexturesDistinct, + assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures", + assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials"); break; } } diff --git a/Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs b/Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs index af858b4b7..1a1caf646 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/EditorVrm.cs @@ -46,7 +46,6 @@ namespace UniVRM10 if (GUILayout.Button("Clear")) { importer.ClearExternalObjects(); - importer.ClearExternalObjects(); importer.ClearExternalObjects(); } } @@ -79,7 +78,7 @@ namespace UniVRM10 // meta { - var path = GetAndCreateFolder(importer.assetPath, ".Meta"); + var path = GetAndCreateFolder(importer.assetPath, ".vrm1.Meta"); foreach (var (key, asset) in importer.GetSubAssets(importer.assetPath)) { asset.ExtractSubAsset($"{path}/{asset.name}.asset", false); @@ -88,30 +87,12 @@ namespace UniVRM10 { // expressions - var path = GetAndCreateFolder(importer.assetPath, ".Expressions"); + var path = GetAndCreateFolder(importer.assetPath, ".vrm1.Expressions"); foreach (var (key, asset) in importer.GetSubAssets(importer.assetPath)) { asset.ExtractSubAsset($"{path}/{asset.name}.asset", false); } - } - { - // expressions - var path = GetAndCreateFolder(importer.assetPath, ".ExpressionAvatar"); - foreach (var (key, asset) in importer.GetSubAssets(importer.assetPath)) - { - asset.ExtractSubAsset($"{path}/{asset.name}.asset", false); - } - // external な expressionAvatar.Clips に 再代入する - var expressionAvatar = importer.GetExternalObjectMap().Select(x => x.Value as VRM10ExpressionAvatar).FirstOrDefault(x => x != null); - var expressions = importer.GetExternalObjectMap().Select(x => x.Value as VRM10Expression).Where(x => x != null).ToList(); - expressionAvatar.Clips = expressions; - var avatarPath = AssetDatabase.GetAssetPath(expressionAvatar); - if (!string.IsNullOrEmpty(avatarPath)) - { - EditorUtility.SetDirty(expressionAvatar); - AssetDatabase.WriteImportSettingsIfDirty(avatarPath); - } } AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate); diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs index ca62fabc0..1d8f69369 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs @@ -1,6 +1,7 @@ using UnityEditor; using UnityEngine; using UniGLTF; +using System.IO; #if UNITY_2020_2_OR_NEWER using UnityEditor.AssetImporters; #else @@ -68,7 +69,9 @@ namespace UniVRM10 case Tabs.Materials: if (m_parser != null) { - EditorMaterial.OnGUI(m_importer, m_parser, Vrm10TextureEnumerator.EnumerateAllTexturesDistinct); + EditorMaterial.OnGUI(m_importer, m_parser, Vrm10TextureEnumerator.EnumerateAllTexturesDistinct, + assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Textures", + assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Materials"); } break;