static void OnGUIMaterial(GltfScriptedImporter importer, GltfParser parser) { var canExtract = !importer.GetExternalObjectMap().Any(x => x.Value is Material || x.Value is Texture2D); using (new TmpGuiEnable(canExtract)) { if (GUILayout.Button("Extract Materials And Textures ...")) { importer.ExtractMaterialsAndTextures(); } } // ObjectMap s_foldMaterials = EditorGUILayout.Foldout(s_foldMaterials, "Remapped Materials"); if (s_foldMaterials) { DrawRemapGUI <UnityEngine.Material>(importer, parser.GLTF.materials.Select(x => x.name)); } s_foldTextures = EditorGUILayout.Foldout(s_foldTextures, "Remapped Textures"); if (s_foldTextures) { DrawRemapGUI <UnityEngine.Texture2D>(importer, parser.EnumerateTextures().Select(x => x.Name)); } if (GUILayout.Button("Clear")) { importer.ClearExternalObjects <UnityEngine.Material>(); importer.ClearExternalObjects <UnityEngine.Texture2D>(); } }
static void DrawRemapGUI <T>(GltfScriptedImporter importer, IEnumerable <string> names) where T : UnityEngine.Object { EditorGUI.indentLevel++; var map = importer.GetExternalObjectMap() .Select(x => (x.Key.name, x.Value as T)) .Where(x => x.Item2 != null) .ToDictionary(x => x.Item1, x => x.Item2) ; foreach (var name in names) { if (string.IsNullOrEmpty(name)) { throw new System.ArgumentNullException(); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(name); map.TryGetValue(name, out T value); var asset = EditorGUILayout.ObjectField(value, typeof(T), true) as T; if (asset != value) { importer.SetExternalUnityObject(new AssetImporter.SourceAssetIdentifier(value), asset); } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; }