Allow reimporting model prefabs from Content window context menu
Some checks failed
Build Android / Game (Android, Release ARM64) (push) Has been cancelled
Build iOS / Game (iOS, Release ARM64) (push) Has been cancelled
Build Linux / Editor (Linux, Development x64) (push) Has been cancelled
Build Linux / Game (Linux, Release x64) (push) Has been cancelled
Build macOS / Editor (Mac, Development ARM64) (push) Has been cancelled
Build macOS / Game (Mac, Release ARM64) (push) Has been cancelled
Build Windows / Editor (Windows, Development x64) (push) Has been cancelled
Build Windows / Game (Windows, Release x64) (push) Has been cancelled
Tests / Tests (Linux) (push) Has been cancelled
Tests / Tests (Windows) (push) Has been cancelled

This commit is contained in:
2024-05-26 00:13:13 +03:00
parent 70f8492c01
commit 74dcea373c
2 changed files with 27 additions and 0 deletions

View File

@@ -73,6 +73,16 @@ namespace FlaxEditor.Content
return targetLocation.CanHaveAssets;
}
/// <inheritdoc />
public override bool CanReimport(ContentItem item)
{
if (item is not PrefabItem prefabItem)
return base.CanReimport(item);
var prefab = FlaxEngine.Content.Load<Prefab>(prefabItem.ID);
return prefab.GetDefaultInstance().GetScript<ModelPrefab>() != null;
}
/// <inheritdoc />
public override void Create(string outputPath, object arg)
{

View File

@@ -311,6 +311,23 @@ namespace FlaxEditor.Windows
{
if (selection[i] is BinaryAssetItem binaryAssetItem)
Editor.ContentImporting.Reimport(binaryAssetItem);
else if (selection[i] is PrefabItem prefabItem)
{
var prefab = FlaxEngine.Content.Load<Prefab>(prefabItem.ID);
var modelPrefab = prefab.GetDefaultInstance().GetScript<ModelPrefab>();
if (!modelPrefab)
continue;
var importPath = modelPrefab.ImportPath;
var editor = Editor.Instance;
if (editor.ContentImporting.GetReimportPath("Model Prefab", ref importPath))
continue;
var folder = editor.ContentDatabase.Find(Path.GetDirectoryName(prefab.Path)) as ContentFolder;
if (folder == null)
continue;
var importOptions = modelPrefab.ImportOptions;
importOptions.Type = FlaxEngine.Tools.ModelTool.ModelType.Prefab;
editor.ContentImporting.Import(importPath, folder, true, importOptions);
}
}
}