using System.Collections.Generic; using BriarQueen.Data.Assets; using BriarQueen.Framework.Registries; using UnityEditor; using UnityEngine; namespace BriarQueen.Editor.Drawers.Registries { [CustomEditor(typeof(AssetRegistry))] public class AssetRegistryFill : UnityEditor.Editor { public override void OnInspectorGUI() { DrawDefaultInspector(); EditorGUILayout.Space(); if (GUILayout.Button("Discover AssetEntry Assets")) { Populate((AssetRegistry)target); } } private static void Populate(AssetRegistry registry) { string[] guids = AssetDatabase.FindAssets("t:AssetEntry"); var scenes = new List(); var levels = new List(); var items = new List(); var ui = new List(); foreach (string guid in guids) { string path = AssetDatabase.GUIDToAssetPath(guid); var entry = AssetDatabase.LoadAssetAtPath(path); if (entry == null) continue; switch (entry.EntryType) { case AssetEntry.AssetEntryType.Scene: scenes.Add(entry); break; case AssetEntry.AssetEntryType.Level: levels.Add(entry); break; case AssetEntry.AssetEntryType.Item: items.Add(entry); break; case AssetEntry.AssetEntryType.UI: ui.Add(entry); break; } } scenes.Sort((a, b) => string.CompareOrdinal(a.name, b.name)); levels.Sort((a, b) => string.CompareOrdinal(a.name, b.name)); items.Sort((a, b) => string.CompareOrdinal(a.name, b.name)); ui.Sort((a, b) => string.CompareOrdinal(a.name, b.name)); Undo.RecordObject(registry, "Discover AssetEntry Assets"); registry.SetDiscoveredEntries(scenes, levels, items, ui); EditorUtility.SetDirty(registry); AssetDatabase.SaveAssets(); Debug.Log($"[AssetRegistry] Discovery complete. Scenes: {scenes.Count}, Levels: {levels.Count}, Items: {items.Count}, UI: {ui.Count}"); } } }