71 lines
1.5 KiB
C#
71 lines
1.5 KiB
C#
using Kryz.CharacterStats.Examples;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public class ItemIndexer : MonoBehaviour
|
|
{
|
|
#region Singleton
|
|
private static ItemIndexer _instance;
|
|
|
|
// Public reference to the singleton instance
|
|
public static ItemIndexer Instance
|
|
{
|
|
get
|
|
{
|
|
return _instance;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public List<Item> Items = new List<Item>();
|
|
|
|
protected void Awake()
|
|
{
|
|
// Ensure there's only one instance
|
|
if (_instance != null && _instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
// If this is the first instance, set it as the singleton
|
|
_instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
|
|
[ContextMenu("Refresh List")]
|
|
public void RefrehsList()
|
|
{
|
|
if (Items == null) return;
|
|
|
|
Items.Clear();
|
|
|
|
foreach (Item item in Resources.LoadAll<Item>("Items"))
|
|
{
|
|
#if UNITY_EDITOR
|
|
if (!AssetDatabase.Contains(item))
|
|
continue; // Skip if not a real asset
|
|
#endif
|
|
|
|
if (!Items.Contains(item))
|
|
{
|
|
Items.Add(item);
|
|
}
|
|
}
|
|
}
|
|
|
|
/*private void OnValidate()
|
|
{
|
|
if (Items == null) return;
|
|
|
|
foreach (Item item in Resources.FindObjectsOfTypeAll<Item>())
|
|
{
|
|
if (Items.Contains(item)) continue;
|
|
|
|
Items.Add(item);
|
|
}
|
|
}*/
|
|
}
|