Skip to content

Commit 0153370

Browse files
committed
improved performance when extracting all materials from importer
1 parent cbda574 commit 0153370

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Editor/Scripts/GLTFImporterInspector.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,32 @@ private void RemappingUI<T>(GLTFImporter t, SerializedProperty importedData, str
263263
// TODO this also counts old remaps that are not used anymore
264264
var remapCount = externalObjectMap.Values.Count(x => x is T);
265265

266+
void ExtractAssets(T[] subAssets, bool importImmediately)
267+
{
268+
var assetPath = AssetDatabase.GetAssetPath(subAssets[0]);
269+
var assetImporter = AssetImporter.GetAtPath(assetPath);
270+
foreach (var subAsset in subAssets)
271+
{
272+
if (!subAsset) return;
273+
var filename = SanitizePath(subAsset.name);
274+
var dirName = Path.GetDirectoryName(t.assetPath) + "/" + subDirectoryName;
275+
if (!Directory.Exists(dirName))
276+
Directory.CreateDirectory(dirName);
277+
var destinationPath = dirName + "/" + filename + fileExtension;
278+
279+
var clone = Instantiate(subAsset);
280+
AssetDatabase.CreateAsset(clone, destinationPath);
281+
282+
assetImporter.AddRemap(new AssetImporter.SourceAssetIdentifier(subAsset), clone);
283+
}
284+
285+
if (importImmediately)
286+
{
287+
AssetDatabase.WriteImportSettingsIfDirty(assetPath);
288+
AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
289+
}
290+
}
291+
266292
void ExtractAsset(T subAsset, bool importImmediately)
267293
{
268294
if (!subAsset) return;

0 commit comments

Comments
 (0)