Files
Ipseity-Demo/Assets/Unheimlich_POC/Scripts/Editor/FBXImporter/FBXContextMenu.cs
T
2026-03-24 21:11:48 +01:00

62 lines
2.4 KiB
C#

using UnityEditor;
using System.Linq;
namespace FBXImporter
{
public static class FBXContextMenu
{
[MenuItem("Assets/FBX Importer/Process this FBX", false, 1000)]
static void ProcessSingle()
{
foreach (var obj in Selection.objects)
{
string path = AssetDatabase.GetAssetPath(obj);
if (!path.EndsWith(".fbx", System.StringComparison.OrdinalIgnoreCase)) continue;
var source = FBXSourceDetector.Detect(path);
FBXImportDialog.Show(path, source);
}
}
[MenuItem("Assets/FBX Importer/Process this FBX", true)]
static bool ProcessSingleValidate() =>
Selection.objects.Any(o => AssetDatabase.GetAssetPath(o)
.EndsWith(".fbx", System.StringComparison.OrdinalIgnoreCase));
[MenuItem("Assets/FBX Importer/Remove from registry", false, 1001)]
static void RemoveFromRegistry()
{
foreach (var obj in Selection.objects)
{
string path = AssetDatabase.GetAssetPath(obj);
if (path.EndsWith(".fbx", System.StringComparison.OrdinalIgnoreCase))
ProcessedFBXRegistry.Unregister(path);
}
}
[MenuItem("Assets/FBX Importer/Remove from registry", true)]
static bool RemoveFromRegistryValidate() =>
Selection.objects.Any(o => AssetDatabase.GetAssetPath(o)
.EndsWith(".fbx", System.StringComparison.OrdinalIgnoreCase));
[MenuItem("Assets/FBX Importer/Create Asset Folder Structure", false, 1020)]
static void CreateFolderStructure()
{
string selectedPath = GetSelectedFolderPath();
if (string.IsNullOrEmpty(selectedPath)) return;
string parent = System.IO.Path.GetDirectoryName(selectedPath).Replace("\\", "/");
FolderSetup.Create(parent, System.IO.Path.GetFileName(selectedPath), false);
}
[MenuItem("Assets/FBX Importer/Create Asset Folder Structure", true)]
static bool CreateFolderStructureValidate() => !string.IsNullOrEmpty(GetSelectedFolderPath());
static string GetSelectedFolderPath()
{
if (Selection.activeObject == null) return null;
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
return AssetDatabase.IsValidFolder(path) ? path : null;
}
}
}