diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs index b9dc9b448..283a8aec8 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditorGUI.cs @@ -14,7 +14,7 @@ using UnityEditor.Experimental.AssetImporters; namespace UniGLTF { [CustomEditor(typeof(GlbScriptedImporter))] - public class GlbScriptedImporterEditorGUI : ScriptedImporterEditorBase + public class GlbScriptedImporterEditorGUI : RemapScriptedImporterEditorBase { GlbScriptedImporter m_importer; GltfParser m_parser; @@ -58,6 +58,7 @@ namespace UniGLTF case Tabs.Animation: m_animationEditor.OnGUI(m_importer, m_parser); + RevertApplyRemapGUI(m_importer); break; case Tabs.Materials: @@ -65,6 +66,7 @@ namespace UniGLTF new GltfTextureDescriptorGenerator(m_parser), assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures", assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials"); + RevertApplyRemapGUI(m_importer); break; } } diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs index bb9be9f46..8a40d3918 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs @@ -14,7 +14,7 @@ using UnityEditor.Experimental.AssetImporters; namespace UniGLTF { [CustomEditor(typeof(GltfScriptedImporter))] - public class GltfScriptedImporterEditorGUI : ScriptedImporterEditorBase + public class GltfScriptedImporterEditorGUI : RemapScriptedImporterEditorBase { GltfScriptedImporter m_importer; GltfParser m_parser; @@ -58,6 +58,7 @@ namespace UniGLTF case Tabs.Animation: m_animationEditor.OnGUI(m_importer, m_parser); + RevertApplyRemapGUI(m_importer); break; case Tabs.Materials: @@ -65,6 +66,7 @@ namespace UniGLTF new GltfTextureDescriptorGenerator(m_parser), assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures", assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials"); + RevertApplyRemapGUI(m_importer); break; } } diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs index 8d5f15d71..e3b9ac13d 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorAnimation.cs @@ -27,13 +27,6 @@ namespace UniGLTF } DrawRemapGUI(importer.GetExternalObjectMap()); - - if (GUILayout.Button("Clear")) - { - importer.ClearExternalObjects( - typeof(UnityEngine.AnimationClip) - ); - } } static string GetAndCreateFolder(string assetPath, string suffix) diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs index 2dcc6d49c..b18a8e03b 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorBase.cs @@ -25,6 +25,7 @@ namespace UniGLTF public String Name; public SubAssetKey Key => new SubAssetKey(s_typeMap[Type], Name); + public ScriptedImporter.SourceAssetIdentifier ID => new AssetImporter.SourceAssetIdentifier(s_typeMap[Type], Name); [SerializeField] public UnityEngine.Object Object; @@ -55,13 +56,6 @@ namespace UniGLTF m_setter = setter; } - 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( Dictionary externalObjectMap ) where T : UnityEngine.Object diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs index fecc9ee6d..0e9e1c8c0 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapEditorMaterial.cs @@ -53,13 +53,6 @@ namespace UniGLTF { DrawRemapGUI(importer.GetExternalObjectMap()); } - - if (GUILayout.Button("Clear")) - { - importer.ClearExternalObjects( - typeof(UnityEngine.Material), - typeof(UnityEngine.Texture)); - } } void ExtractMaterialsAndTextures(ScriptedImporter self, GltfParser parser, ITextureDescriptorGenerator textureDescriptorGenerator, Func textureDir, Func materialDir) diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapScriptedImporterEditorBase.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapScriptedImporterEditorBase.cs new file mode 100644 index 000000000..b0631954a --- /dev/null +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapScriptedImporterEditorBase.cs @@ -0,0 +1,76 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEditor; +using UnityEditor.Experimental.AssetImporters; +using UnityEngine; +using VRMShaders; + +namespace UniGLTF +{ + public abstract class RemapScriptedImporterEditorBase : ScriptedImporterEditor + { + /// + /// Apply されていない変更を保持する + /// + /// * Undo + /// + /// + /// + /// + /// + [SerializeField] + List m_editMap = new List(); + + protected Dictionary GetEditorMap() + { + return m_editMap.ToDictionary(x => x.Key, x => x.Object); + } + + protected void SetEditorMap(Dictionary value) + { + Undo.RecordObject(this, "update editorMap"); + m_editMap.Clear(); + m_editMap.AddRange(value.Select(kv => new RemapEditorBase.SubAssetPair(kv.Key, kv.Value))); + } + + public void RevertRemap() + { + m_editMap.Clear(); + } + + public void ApplyRemap(ScriptedImporter importer) + { + foreach (var kv in m_editMap) + { + if (kv.Object != null) + { + importer.AddRemap(kv.ID, kv.Object); + } + else + { + importer.RemoveRemap(kv.ID); + } + } + AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath); + AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate); + } + + public void RevertApplyRemapGUI(ScriptedImporter importer) + { + GUILayout.BeginHorizontal(); + GUILayout.FlexibleSpace(); + using (new EditorGUI.DisabledScope(m_editMap.Count == 0)) + { + if (GUILayout.Button("Revert")) + { + RevertRemap(); + } + if (GUILayout.Button("Apply")) + { + ApplyRemap(importer); + } + } + GUILayout.EndHorizontal(); + } + } +} diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterEditorBase.cs.meta b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapScriptedImporterEditorBase.cs.meta similarity index 83% rename from Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterEditorBase.cs.meta rename to Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapScriptedImporterEditorBase.cs.meta index 048be8338..364065f92 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterEditorBase.cs.meta +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapScriptedImporterEditorBase.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 3d0cae75bb03dd14fbe64fadd0eff64f +guid: a3af37d3219ffeb4a9bda4960fb20cbe MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterEditorBase.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterEditorBase.cs deleted file mode 100644 index b67839786..000000000 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterEditorBase.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using UnityEditor; -using UnityEditor.Experimental.AssetImporters; -using UnityEngine; -using VRMShaders; - -namespace UniGLTF -{ - public abstract class ScriptedImporterEditorBase : ScriptedImporterEditor - { - /// - /// Apply されていない変更を保持する - /// - /// - /// - /// - [SerializeField] - List m_editMap = new List(); - - protected Dictionary GetEditorMap() - { - return m_editMap.ToDictionary(x => x.Key, x => x.Object); - } - - protected void SetEditorMap(Dictionary value) - { - Undo.RecordObject(this, "update editorMap"); - m_editMap.Clear(); - m_editMap.AddRange(value.Select(kv => new RemapEditorBase.SubAssetPair(kv.Key, kv.Value))); - } - } -} diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterExtension.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterExtension.cs index 9f61cc4b9..d0a92a0b2 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterExtension.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterExtension.cs @@ -15,27 +15,27 @@ namespace UniGLTF { public static class ScriptedImporterExtension { - public static void ClearExternalObjects(this ScriptedImporter importer, params Type[] targetTypes) - { - foreach (var targetType in targetTypes) - { - if (!typeof(UnityEngine.Object).IsAssignableFrom(targetType)) - { - throw new NotImplementedException(); - } + // public static void ClearExternalObjects(this ScriptedImporter importer, params Type[] targetTypes) + // { + // foreach (var targetType in targetTypes) + // { + // if (!typeof(UnityEngine.Object).IsAssignableFrom(targetType)) + // { + // throw new NotImplementedException(); + // } - foreach (var (key, obj) in importer.GetExternalObjectMap()) - { - if (targetType.IsAssignableFrom(key.type)) - { - importer.RemoveRemap(key); - } - } - } + // foreach (var (key, obj) in importer.GetExternalObjectMap()) + // { + // if (targetType.IsAssignableFrom(key.type)) + // { + // importer.RemoveRemap(key); + // } + // } + // } - AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath); - AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate); - } + // AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath); + // AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate); + // } public static IEnumerable<(SubAssetKey, T)> GetSubAssets(this ScriptedImporter importer, string assetPath) where T : UnityEngine.Object { diff --git a/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs b/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs index dbb60e263..89c753b50 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/RemapEditorVrm.cs @@ -35,13 +35,6 @@ namespace UniVRM10 // expressions DrawRemapGUI(importer.GetExternalObjectMap()); - - if (GUILayout.Button("Clear")) - { - importer.ClearExternalObjects( - typeof(VRM10Object), - typeof(VRM10Expression)); - } } /// diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs index e2d77debb..e4d3eebc6 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs @@ -16,7 +16,7 @@ using UnityEditor.Experimental.AssetImporters; namespace UniVRM10 { [CustomEditor(typeof(VrmScriptedImporter))] - public class VrmScriptedImporterEditorGUI : ScriptedImporterEditorBase + public class VrmScriptedImporterEditorGUI : RemapScriptedImporterEditorBase { VrmScriptedImporter m_importer; GltfParser m_parser; @@ -84,6 +84,7 @@ namespace UniVRM10 m_materialEditor.OnGUI(m_importer, m_parser, new Vrm10TextureDescriptorGenerator(m_parser), assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Textures", assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Materials"); + RevertApplyRemapGUI(m_importer); } break; @@ -91,6 +92,7 @@ namespace UniVRM10 if (m_parser != null && m_vrm != null) { m_vrmEditor.OnGUI(m_importer, m_parser, m_vrm); + RevertApplyRemapGUI(m_importer); } break; }