From 9b4e9a23e201dd1cc871015c5ec3ecb438308768 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Thu, 25 Feb 2021 17:47:00 +0900 Subject: [PATCH] TmpGuiEnable --- .../ScriptedImporter/GltfScriptedImporter.cs | 2 +- .../GltfScriptedImporterEditorGUI.cs | 31 ++++++++++++++----- .../ScriptedImporterExtension.cs | 1 + 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporter.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporter.cs index a6c63a846..9301ea1fd 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporter.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporter.cs @@ -12,7 +12,7 @@ namespace UniGLTF public class GltfScriptedImporter : ScriptedImporter { [SerializeField] - Axises m_reverseAxis; + Axises m_reverseAxis = default; const string TextureDirName = "Textures"; const string MaterialDirName = "Materials"; diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs index 1344b02a4..579ba7c36 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/GltfScriptedImporterEditorGUI.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEditor.Experimental.AssetImporters; @@ -51,11 +52,30 @@ namespace UniGLTF static bool s_foldMaterials; static bool s_foldTextures; + class TmpGuiEnable : IDisposable + { + bool m_backup; + public TmpGuiEnable(bool enable) + { + m_backup = GUI.enabled; + GUI.enabled = enable; + } + + public void Dispose() + { + GUI.enabled = m_backup; + } + } + static void OnGUIMaterial(GltfScriptedImporter importer, GltfParser parser) { - if (GUILayout.Button("Extract Materials And Textures ...")) + var canExtract = !importer.GetExternalObjectMap().Any(x => x.Value is Material || x.Value is Texture2D); + using (new TmpGuiEnable(canExtract)) { - importer.ExtractMaterialsAndTextures(); + if (GUILayout.Button("Extract Materials And Textures ...")) + { + importer.ExtractMaterialsAndTextures(); + } } // ObjectMap @@ -96,11 +116,6 @@ namespace UniGLTF EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(name); map.TryGetValue(name, out T value); - if (map.Any() && value == null) - { - var a = 0; - // Debug.Log($"{name}: {value}"); - } var asset = EditorGUILayout.ObjectField(value, typeof(T), true) as T; if (asset != value) { diff --git a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterExtension.cs b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterExtension.cs index a4b27162d..6328c67d8 100644 --- a/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterExtension.cs +++ b/Assets/UniGLTF/Editor/UniGLTF/ScriptedImporter/ScriptedImporterExtension.cs @@ -131,6 +131,7 @@ namespace UniGLTF { Path = targetPath, sRGB = true, + IsNormalMap = param.TextureType == GetTextureParam.NORMAL_PROP, }); } }