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

66 lines
2.2 KiB
C#

using UnityEditor;
using System.Collections.Generic;
namespace FBXImporter
{
public class FBXDropWatcher : AssetPostprocessor
{
static readonly List<string> _pendingNewFBX = new List<string>();
static bool _dialogScheduled = false;
bool ShouldWatch()
{
return assetPath.StartsWith("Assets/")
&& assetPath.EndsWith(".fbx", System.StringComparison.OrdinalIgnoreCase)
&& !ProcessedFBXRegistry.IsRegistered(assetPath);
}
void OnPreprocessModel()
{
if (!ShouldWatch()) return;
var importer = assetImporter as ModelImporter;
importer.importCameras = false;
importer.importLights = false;
importer.importNormals = ModelImporterNormals.Import;
importer.importTangents = ModelImporterTangents.CalculateMikk;
importer.importBlendShapes = true;
importer.importVisibility = true;
importer.materialImportMode = ModelImporterMaterialImportMode.ImportViaMaterialDescription;
importer.materialLocation = ModelImporterMaterialLocation.External;
importer.materialName = ModelImporterMaterialName.BasedOnMaterialName;
importer.materialSearch = ModelImporterMaterialSearch.RecursiveUp;
importer.useFileScale = true;
importer.globalScale = 1f;
}
void OnPostprocessModel(UnityEngine.GameObject root)
{
if (!ShouldWatch()) return;
if (!_pendingNewFBX.Contains(assetPath))
_pendingNewFBX.Add(assetPath);
if (!_dialogScheduled)
{
_dialogScheduled = true;
EditorApplication.delayCall += ShowBatchDialog;
}
}
static void ShowBatchDialog()
{
_dialogScheduled = false;
if (_pendingNewFBX.Count == 0) return;
var batch = new List<string>(_pendingNewFBX);
_pendingNewFBX.Clear();
// Register all immediately — won't appear again regardless of user choice
ProcessedFBXRegistry.Register(batch);
FBXBatchDialog.Show(batch);
}
}
}