Files
Ipseity-Demo/Assets/_Content/Scripts/Editor/FBXImporter/FBXBatchDialog.cs
T

107 lines
3.9 KiB
C#

using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.IO;
namespace FBXImporter
{
public class FBXBatchDialog : EditorWindow
{
private class FBXEntry
{
public string Path;
public string Name;
public FBXSource Source;
public bool ShouldProcess = true;
}
private List<FBXEntry> _entries = new List<FBXEntry>();
private Vector2 _scroll;
public static void Show(List<string> fbxPaths)
{
var window = GetWindow<FBXBatchDialog>(true, "FBX Importer — New Assets", true);
window.minSize = new Vector2(520, 320);
foreach (var path in fbxPaths)
window._entries.Add(new FBXEntry {
Path = path,
Name = Path.GetFileName(path),
Source = FBXSourceDetector.Detect(path),
ShouldProcess = true,
});
window.ShowModal();
}
void OnGUI()
{
GUILayout.Space(10);
GUILayout.Label($"{_entries.Count} new FBX detected", EditorStyles.boldLabel);
GUILayout.Label("All files are registered. Check which ones to process.", EditorStyles.miniLabel);
GUILayout.Space(8);
// Header
using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar))
{
GUILayout.Label("Process", GUILayout.Width(55));
GUILayout.Label("File", GUILayout.Width(200));
GUILayout.Label("Source", GUILayout.Width(70));
GUILayout.Label("Path", GUILayout.ExpandWidth(true));
}
// List
_scroll = EditorGUILayout.BeginScrollView(_scroll, GUILayout.ExpandHeight(true));
foreach (var entry in _entries)
{
using (new EditorGUILayout.HorizontalScope())
{
entry.ShouldProcess = EditorGUILayout.Toggle(entry.ShouldProcess, GUILayout.Width(55));
var style = new GUIStyle(EditorStyles.label)
{ normal = { textColor = entry.ShouldProcess ? Color.white : Color.gray } };
GUILayout.Label(entry.Name, style, GUILayout.Width(200));
GUILayout.Label(entry.Source.ToString(), EditorStyles.miniLabel, GUILayout.Width(70));
GUILayout.Label(entry.Path, EditorStyles.miniLabel, GUILayout.ExpandWidth(true));
}
}
EditorGUILayout.EndScrollView();
// Select all / none
GUILayout.Space(4);
using (new EditorGUILayout.HorizontalScope())
{
if (GUILayout.Button("All", GUILayout.Width(60))) _entries.ForEach(e => e.ShouldProcess = true);
if (GUILayout.Button("None", GUILayout.Width(60))) _entries.ForEach(e => e.ShouldProcess = false);
}
GUILayout.Space(8);
// Actions
using (new EditorGUILayout.HorizontalScope())
{
GUILayout.FlexibleSpace();
if (GUILayout.Button("Skip all", GUILayout.Width(80)))
{ Close(); return; }
int count = _entries.FindAll(e => e.ShouldProcess).Count;
using (new EditorGUI.DisabledScope(count == 0))
{
if (GUILayout.Button($"Process {count} FBX", GUILayout.Width(130)))
{ ProcessSelected(); Close(); }
}
}
GUILayout.Space(8);
}
void ProcessSelected()
{
foreach (var entry in _entries)
{
if (!entry.ShouldProcess) continue;
FBXImportDialog.Show(entry.Path, entry.Source);
}
}
}
}