First commit for private source control. Older commits available on Github.
This commit is contained in:
69
Assets/Scripts/Editor/Drawers/Registries/ItemRegistryFill.cs
Normal file
69
Assets/Scripts/Editor/Drawers/Registries/ItemRegistryFill.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System.Collections.Generic;
|
||||
using BriarQueen.Framework.Managers.Player.Data;
|
||||
using BriarQueen.Framework.Registries;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BriarQueen.Editor.Drawers.Registries
|
||||
{
|
||||
[CustomEditor(typeof(ItemRegistry))]
|
||||
public class ItemRegistryFill : UnityEditor.Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (GUILayout.Button("Discover Item Assets"))
|
||||
{
|
||||
Populate((ItemRegistry)target);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Populate(ItemRegistry registry)
|
||||
{
|
||||
string[] guids = AssetDatabase.FindAssets("t:ItemDataSo");
|
||||
|
||||
var puzzleSlots = new List<ItemDataSo>();
|
||||
var pickupItems = new List<ItemDataSo>();
|
||||
var environmentInteractables = new List<ItemDataSo>();
|
||||
|
||||
foreach (string guid in guids)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
var entry = AssetDatabase.LoadAssetAtPath<ItemDataSo>(path);
|
||||
|
||||
if (entry == null)
|
||||
continue;
|
||||
|
||||
switch (entry.IdType)
|
||||
{
|
||||
case ItemDataSo.ItemIdType.PuzzleSlot:
|
||||
puzzleSlots.Add(entry);
|
||||
break;
|
||||
|
||||
case ItemDataSo.ItemIdType.Pickup:
|
||||
pickupItems.Add(entry);
|
||||
break;
|
||||
|
||||
case ItemDataSo.ItemIdType.Environment:
|
||||
environmentInteractables.Add(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
puzzleSlots.Sort((a, b) => string.CompareOrdinal(a.name, b.name));
|
||||
pickupItems.Sort((a, b) => string.CompareOrdinal(a.name, b.name));
|
||||
environmentInteractables.Sort((a, b) => string.CompareOrdinal(a.name, b.name));
|
||||
|
||||
Undo.RecordObject(registry, "Discover Item Assets");
|
||||
registry.SetDiscoveredEntries(puzzleSlots, pickupItems, environmentInteractables);
|
||||
EditorUtility.SetDirty(registry);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
Debug.Log(
|
||||
$"[ItemRegistry] Discovery complete. Puzzle Slots: {puzzleSlots.Count}, Pickup Items: {pickupItems.Count}, Environment Interactables: {environmentInteractables.Count}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user