Fix error of extracting

This commit is contained in:
Masataka SUMI 2021-05-25 18:22:44 +09:00
parent 68c8fed9dd
commit 6e85b42d65
3 changed files with 21 additions and 9 deletions

View File

@ -56,13 +56,14 @@ namespace UniGLTF
s_foldTextures = EditorGUILayout.Foldout(s_foldTextures, "Remapped Textures");
if (s_foldTextures)
{
importer.DrawRemapGUI<UnityEngine.Texture2D>(enumTextures(parser).Select(x => x.Key));
importer.DrawRemapGUI<UnityEngine.Texture>(enumTextures(parser).Select(x => x.Key));
}
if (GUILayout.Button("Clear"))
{
importer.ClearExternalObjects<UnityEngine.Material>();
importer.ClearExternalObjects<UnityEngine.Texture2D>();
importer.ClearExternalObjects(
typeof(UnityEngine.Material),
typeof(UnityEngine.Texture));
}
}

View File

@ -1,6 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using VRMShaders;
#if UNITY_2020_2_OR_NEWER
using UnityEditor.AssetImporters;
@ -13,11 +15,19 @@ namespace UniGLTF
{
public static class ScriptedImporterExtension
{
public static void ClearExternalObjects<T>(this ScriptedImporter importer) where T : UnityEngine.Object
public static void ClearExternalObjects(this ScriptedImporter importer, params Type[] targetTypes)
{
foreach (var externalObject in importer.GetExternalObjectMap().Where(x => x.Key.type == typeof(T)))
foreach (var targetType in targetTypes)
{
importer.RemoveRemap(externalObject.Key);
if (!typeof(UnityEngine.Object).IsAssignableFrom(targetType)) continue;
foreach (var (key, obj) in importer.GetExternalObjectMap())
{
if (key.type.IsAssignableFrom(targetType))
{
importer.RemoveRemap(key);
}
}
}
AssetDatabase.WriteImportSettingsIfDirty(importer.assetPath);

View File

@ -46,8 +46,9 @@ namespace UniVRM10
if (GUILayout.Button("Clear"))
{
importer.ClearExternalObjects<VRM10MetaObject>();
importer.ClearExternalObjects<VRM10Expression>();
importer.ClearExternalObjects(
typeof(VRM10MetaObject),
typeof(VRM10Expression));
}
}