53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
using System.Linq;
|
|
using Data.ScriptableObjects;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace Editor
|
|
{
|
|
[CustomEditor(typeof(ItemDatabase))]
|
|
public class ItemDatabaseEditor : UnityEditor.Editor
|
|
{
|
|
public override void OnInspectorGUI()
|
|
{
|
|
base.OnInspectorGUI();
|
|
|
|
var database = (ItemDatabase)target;
|
|
|
|
if (GUILayout.Button("Validate Items")) ValidateItems(database);
|
|
}
|
|
|
|
private void ValidateItems(ItemDatabase database)
|
|
{
|
|
// Check for duplicate IDs
|
|
var duplicates = database.AllItems.GroupBy(x => x.ID)
|
|
.Where(g => g.Count() > 1)
|
|
.Select(g => g.Key);
|
|
|
|
if (duplicates.Any()) Debug.LogError("Duplicate IDs found: " + string.Join(", ", duplicates));
|
|
|
|
// Check for missing items
|
|
for (var i = 1; i <= database.AllItems.Count; i++)
|
|
if (!database.AllItems.Any(item => item.ID == i))
|
|
Debug.LogWarning($"Missing item ID: {i}");
|
|
}
|
|
|
|
|
|
[MenuItem("Tools/Load all Game Item")]
|
|
public static void LoadAllGameItems()
|
|
{
|
|
var database = AssetDatabase.LoadAssetAtPath<ItemDatabase>("Assets/Resources/GameItems/ItemDatabase.asset");
|
|
if (database != null)
|
|
{
|
|
database.LoadAllItems();
|
|
EditorUtility.SetDirty(database);
|
|
AssetDatabase.SaveAssets();
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError(
|
|
"ItemDatabase not found. Please create one at Assets/Resources/GameItems/ItemDatabase.asset");
|
|
}
|
|
}
|
|
}
|
|
} |