Files
test/Assets/ModelRenderer/Editor/CombinedActionSOGfxRemover.cs
2026-05-29 10:02:16 +07:00

166 lines
6.1 KiB
C#

// UTF-8 with BOM — required for Chinese character paths
using System.Collections.Generic;
using System.Linq;
using BrewMonster.Scripts.ECModel;
using UnityEditor;
using UnityEngine;
public class CombinedActionSOGfxRemover : EditorWindow
{
CombinedActionSO _combinedActionSo;
CombinedActionGfxPhase _phaseFilter = CombinedActionGfxPhase.All;
string _actionFilter = string.Empty;
string _basenameFilter = string.Empty;
Vector2 _scrollPos;
readonly List<CombinedActionGfxEntry> _entries = new();
GUIStyle _headerStyle;
GUIStyle HeaderStyle => _headerStyle ??= new GUIStyle(EditorStyles.boldLabel) { fontSize = 14 };
[MenuItem("Tools/Brew Monster/Combined Action GFX Event Remover")]
public static void ShowWindow()
{
var win = GetWindow<CombinedActionSOGfxRemover>(false, "GFX Event Remover", true);
win.minSize = new Vector2(760, 420);
}
void OnEnable()
{
RefreshEntries();
}
void OnGUI()
{
EditorGUILayout.Space(6);
EditorGUILayout.LabelField("Combined Action GFX Event Remover", HeaderStyle);
EditorGUILayout.LabelField(
"Browse and remove FX/GFX events from CombinedActionSO assets.",
EditorStyles.miniLabel);
EditorGUILayout.Space(4);
EditorGUI.BeginChangeCheck();
_combinedActionSo = (CombinedActionSO)EditorGUILayout.ObjectField(
"Combined Action SO",
_combinedActionSo,
typeof(CombinedActionSO),
false);
if (EditorGUI.EndChangeCheck())
RefreshEntries();
using (new EditorGUILayout.HorizontalScope())
{
_phaseFilter = (CombinedActionGfxPhase)EditorGUILayout.EnumPopup("Phase", _phaseFilter);
if (GUILayout.Button("Refresh", GUILayout.Width(80)))
RefreshEntries();
}
_actionFilter = EditorGUILayout.TextField("Filter action name", _actionFilter);
_basenameFilter = EditorGUILayout.TextField("Filter gfx basename", _basenameFilter);
DrawBulkRemoveRow();
DrawSeparator();
DrawEntryTable();
}
void DrawBulkRemoveRow()
{
using (new EditorGUI.DisabledScope(_combinedActionSo == null || string.IsNullOrWhiteSpace(_basenameFilter)))
{
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Bulk remove", GUILayout.Width(100));
if (GUILayout.Button("Remove basename from Attack actions", GUILayout.Height(22)))
{
int removed = CombinedActionGfxQuery.RemoveMatchingBasenameFromPhase(
_combinedActionSo,
_basenameFilter.Trim(),
CombinedActionGfxPhase.Attack);
Debug.Log($"[GFX Event Remover] Removed {removed} Attack GFX row(s) matching basename '{_basenameFilter.Trim()}'.");
RefreshEntries();
}
if (GUILayout.Button("Remove basename from Cast actions", GUILayout.Height(22)))
{
int removed = CombinedActionGfxQuery.RemoveMatchingBasenameFromPhase(
_combinedActionSo,
_basenameFilter.Trim(),
CombinedActionGfxPhase.Cast);
Debug.Log($"[GFX Event Remover] Removed {removed} Cast GFX row(s) matching basename '{_basenameFilter.Trim()}'.");
RefreshEntries();
}
EditorGUILayout.EndHorizontal();
}
}
void DrawEntryTable()
{
IEnumerable<CombinedActionGfxEntry> visible = _entries.Where(entry =>
CombinedActionGfxQuery.MatchesFilters(entry, _phaseFilter, _actionFilter, _basenameFilter));
int visibleCount = visible.Count();
EditorGUILayout.LabelField($"GFX rows: {visibleCount} / {_entries.Count}", EditorStyles.boldLabel);
if (_combinedActionSo == null)
{
EditorGUILayout.HelpBox("Assign a CombinedActionSO asset to begin.", MessageType.Info);
return;
}
if (visibleCount == 0)
{
EditorGUILayout.HelpBox("No GFX rows match the current filters.", MessageType.Warning);
return;
}
_scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
foreach (CombinedActionGfxEntry entry in visible)
DrawEntryRow(entry);
EditorGUILayout.EndScrollView();
}
void DrawEntryRow(CombinedActionGfxEntry entry)
{
using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
{
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.LabelField(CombinedActionGfxQuery.GetPhaseLabel(entry.Phase), GUILayout.Width(56));
EditorGUILayout.LabelField(entry.GfxBasename, EditorStyles.boldLabel, GUILayout.Width(180));
EditorGUILayout.SelectableLabel(entry.Path, EditorStyles.miniLabel, GUILayout.Height(16));
if (GUILayout.Button("Remove", GUILayout.Width(72)))
{
if (EditorUtility.DisplayDialog(
"Remove GFX event",
$"Remove '{entry.GfxBasename}' from action '{entry.ActionName}'?",
"Remove",
"Cancel") &&
CombinedActionGfxQuery.RemoveEntry(_combinedActionSo, entry))
{
Debug.Log(
$"[GFX Event Remover] Removed '{entry.GfxBasename}' from action '{entry.ActionName}'.");
RefreshEntries();
}
}
}
EditorGUILayout.LabelField(entry.ActionName, EditorStyles.miniLabel);
}
}
void RefreshEntries()
{
_entries.Clear();
if (_combinedActionSo == null)
return;
_entries.AddRange(CombinedActionGfxQuery.Scan(_combinedActionSo));
Repaint();
}
static void DrawSeparator()
{
var rect = EditorGUILayout.GetControlRect(false, 1);
EditorGUI.DrawRect(rect, new Color(0.5f, 0.5f, 0.5f, 0.35f));
EditorGUILayout.Space(4);
}
}