From 74dcea373c7d8b5f3c0096020e1d5e4406e6438c Mon Sep 17 00:00:00 2001 From: Ari Vuollet Date: Sun, 26 May 2024 00:13:13 +0300 Subject: [PATCH] Allow reimporting model prefabs from Content window context menu --- Source/Editor/Content/Proxy/PrefabProxy.cs | 10 ++++++++++ .../Editor/Windows/ContentWindow.ContextMenu.cs | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Source/Editor/Content/Proxy/PrefabProxy.cs b/Source/Editor/Content/Proxy/PrefabProxy.cs index c0c4e5c88..d2971f296 100644 --- a/Source/Editor/Content/Proxy/PrefabProxy.cs +++ b/Source/Editor/Content/Proxy/PrefabProxy.cs @@ -73,6 +73,16 @@ namespace FlaxEditor.Content return targetLocation.CanHaveAssets; } + /// + public override bool CanReimport(ContentItem item) + { + if (item is not PrefabItem prefabItem) + return base.CanReimport(item); + + var prefab = FlaxEngine.Content.Load(prefabItem.ID); + return prefab.GetDefaultInstance().GetScript() != null; + } + /// public override void Create(string outputPath, object arg) { diff --git a/Source/Editor/Windows/ContentWindow.ContextMenu.cs b/Source/Editor/Windows/ContentWindow.ContextMenu.cs index 4b21a2e6a..ffac4c822 100644 --- a/Source/Editor/Windows/ContentWindow.ContextMenu.cs +++ b/Source/Editor/Windows/ContentWindow.ContextMenu.cs @@ -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(prefabItem.ID); + var modelPrefab = prefab.GetDefaultInstance().GetScript(); + 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); + } } }