From cb0c2b7570e2adee9f9b2bee33df83a628177600 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 4 Aug 2021 14:37:23 +0900 Subject: [PATCH] Unity-2019 require ApplyRevertGUI call in OnInspectorGUI https://github.com/Unity-Technologies/UnityCsReference/blob/2019.4/Modules/AssetPipelineEditor/ImportSettings/AssetImporterEditor.cs#L443 --- .../GlbScriptedImporterEditor.cs | 5 +- .../GltfScriptedImporterEditor.cs | 7 +-- .../RemapScriptedImporterEditorBase.cs | 54 +++++++++++-------- .../ZipArchivedGltfScriptedImporterEditor.cs | 5 +- .../VrmScriptedImporterEditorGUI.cs | 12 +++-- 5 files changed, 44 insertions(+), 39 deletions(-) diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditor.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditor.cs index ef2914181..f08dce012 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditor.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GlbScriptedImporterEditor.cs @@ -16,7 +16,6 @@ namespace UniGLTF [CustomEditor(typeof(GlbScriptedImporter))] public class GlbScriptedImporterEditor : RemapScriptedImporterEditorBase { - GlbScriptedImporter m_importer; GltfData m_data; RemapEditorMaterial m_materialEditor; @@ -57,7 +56,7 @@ namespace UniGLTF case Tabs.Animation: m_animationEditor.OnGUI(m_importer, m_data); - RevertApplyRemapGUI(m_importer); + ApplyRevertGUI(); break; case Tabs.Materials: @@ -65,7 +64,7 @@ namespace UniGLTF new GltfTextureDescriptorGenerator(m_data), assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures", assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials"); - RevertApplyRemapGUI(m_importer); + ApplyRevertGUI(); break; } } diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditor.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditor.cs index a125bbc74..6406d5677 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditor.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditor.cs @@ -2,8 +2,6 @@ using UnityEditor; using UnityEngine; using System.IO; using System.Linq; -using System.Collections.Generic; -using VRMShaders; #if UNITY_2020_2_OR_NEWER using UnityEditor.AssetImporters; #else @@ -16,7 +14,6 @@ namespace UniGLTF [CustomEditor(typeof(GltfScriptedImporter))] public class GltfScriptedImporterEditor : RemapScriptedImporterEditorBase { - GltfScriptedImporter m_importer; GltfData m_data; RemapEditorMaterial m_materialEditor; @@ -57,7 +54,7 @@ namespace UniGLTF case Tabs.Animation: m_animationEditor.OnGUI(m_importer, m_data); - RevertApplyRemapGUI(m_importer); + ApplyRevertGUI(); break; case Tabs.Materials: @@ -65,7 +62,7 @@ namespace UniGLTF new GltfTextureDescriptorGenerator(m_data), assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures", assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials"); - RevertApplyRemapGUI(m_importer); + ApplyRevertGUI(); break; } } diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapScriptedImporterEditorBase.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapScriptedImporterEditorBase.cs index bb879e863..ee571362a 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapScriptedImporterEditorBase.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/RemapScriptedImporterEditorBase.cs @@ -7,8 +7,15 @@ using VRMShaders; namespace UniGLTF { + /// + /// https://github.com/Unity-Technologies/UnityCsReference/blob/2019.4/Modules/AssetPipelineEditor/ImportSettings/AssetImporterEditor.cs + /// + /// の作法に合わせる + /// public abstract class RemapScriptedImporterEditorBase : ScriptedImporterEditor { + protected ScriptedImporter m_importer; + /// /// Apply されていない変更を保持する /// @@ -33,45 +40,46 @@ namespace UniGLTF m_editMap.AddRange(value.Select(kv => new RemapEditorBase.SubAssetPair(kv.Key, kv.Value))); } - public void RevertRemap() + /// + /// Revert + /// + protected override void ResetValues() { m_editMap.Clear(); + + base.ResetValues(); } - public void ApplyRemap(ScriptedImporter importer) + public override bool HasModified() + { + if (m_editMap.Any()) + { + return true; + } + return base.HasModified(); + } + + /// + /// Apply + /// + protected override void Apply() { foreach (var kv in m_editMap) { if (kv.Object != null) { - importer.AddRemap(kv.ID, kv.Object); + m_importer.AddRemap(kv.ID, kv.Object); } else { - importer.RemoveRemap(kv.ID); + m_importer.RemoveRemap(kv.ID); } } m_editMap.Clear(); - AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath); - AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate); - } + AssetDatabase.WriteImportSettingsIfDirty(m_importer.assetPath); + AssetDatabase.ImportAsset(m_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(); + base.Apply(); } } } diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ZipArchivedGltfScriptedImporterEditor.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ZipArchivedGltfScriptedImporterEditor.cs index 19070ba77..542d09506 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ZipArchivedGltfScriptedImporterEditor.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ZipArchivedGltfScriptedImporterEditor.cs @@ -14,7 +14,6 @@ namespace UniGLTF [CustomEditor(typeof(ZipArchivedGltfScriptedImporter))] public class ZipArchivedGltfScriptedImporterEditor : RemapScriptedImporterEditorBase { - ZipArchivedGltfScriptedImporter m_importer; GltfData m_data; RemapEditorMaterial m_materialEditor; @@ -55,7 +54,7 @@ namespace UniGLTF case Tabs.Animation: m_animationEditor.OnGUI(m_importer, m_data); - RevertApplyRemapGUI(m_importer); + ApplyRevertGUI(); break; case Tabs.Materials: @@ -63,7 +62,7 @@ namespace UniGLTF new GltfTextureDescriptorGenerator(m_data), assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Textures", assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.Materials"); - RevertApplyRemapGUI(m_importer); + ApplyRevertGUI(); break; } } diff --git a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs index 261d34bcc..c0c13a1d8 100644 --- a/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs +++ b/Assets/VRM10/Editor/ScriptedImporter/VrmScriptedImporterEditorGUI.cs @@ -18,7 +18,6 @@ namespace UniVRM10 [CustomEditor(typeof(VrmScriptedImporter))] public class VrmScriptedImporterEditorGUI : RemapScriptedImporterEditorBase { - VrmScriptedImporter m_importer; VrmLib.Model m_model; RemapEditorMaterial m_materialEditor; @@ -64,8 +63,9 @@ namespace UniVRM10 { base.OnEnable(); - m_importer = target as VrmScriptedImporter; - if (!Vrm10Parser.TryParseOrMigrate(m_importer.assetPath, m_importer.MigrateToVrm1, out m_result)) + var importer = target as VrmScriptedImporter; + m_importer = importer; + if (!Vrm10Parser.TryParseOrMigrate(m_importer.assetPath, importer.MigrateToVrm1, out m_result)) { // error return; @@ -102,6 +102,7 @@ namespace UniVRM10 { case Vrm10FileType.Vrm1: EditorGUILayout.HelpBox(m_result.Message, MessageType.Info); + ApplyRevertGUI(); break; case Vrm10FileType.Vrm0: @@ -111,6 +112,7 @@ namespace UniVRM10 break; default: + ApplyRevertGUI(); break; } } @@ -122,7 +124,7 @@ namespace UniVRM10 m_materialEditor.OnGUI(m_importer, m_result.Data, new Vrm10TextureDescriptorGenerator(m_result.Data), assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Textures", assetPath => $"{Path.GetFileNameWithoutExtension(assetPath)}.vrm1.Materials"); - RevertApplyRemapGUI(m_importer); + ApplyRevertGUI(); } break; @@ -130,7 +132,7 @@ namespace UniVRM10 if (m_result.Data != null && m_result.Vrm != null) { m_vrmEditor.OnGUI(m_importer, m_result.Data, m_result.Vrm); - RevertApplyRemapGUI(m_importer); + ApplyRevertGUI(); } break; }