82 lines
2.1 KiB
C#
82 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public class AbilityIndexer : MonoBehaviour
|
|
{
|
|
#region Singleton
|
|
private static AbilityIndexer _instance;
|
|
|
|
// Public reference to the singleton instance
|
|
public static AbilityIndexer Instance
|
|
{
|
|
get
|
|
{
|
|
// If the instance doesn't exist, try to find it in the scene
|
|
if (_instance == null)
|
|
{
|
|
_instance = FindObjectOfType<AbilityIndexer>();
|
|
|
|
// If it's still null, create a new GameObject and add the component
|
|
if (_instance == null)
|
|
{
|
|
GameObject singletonObject = new GameObject(typeof(AbilityIndexer).Name);
|
|
_instance = singletonObject.AddComponent<AbilityIndexer>();
|
|
}
|
|
}
|
|
return _instance;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public List<BaseAbility> Abilities = new List<BaseAbility>();
|
|
|
|
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 (Abilities == null) return;
|
|
|
|
//Abilities.Clear();
|
|
|
|
foreach (BaseAbility ability in Resources.LoadAll<BaseAbility>("Abilities"))
|
|
{
|
|
#if UNITY_EDITOR
|
|
if (!AssetDatabase.Contains(ability))
|
|
continue; // Skip if not a real asset
|
|
#endif
|
|
|
|
if (!Abilities.Contains(ability))
|
|
{
|
|
Abilities.Add(ability);
|
|
}
|
|
}
|
|
}
|
|
|
|
/* private void OnValidate()
|
|
{
|
|
if (Abilities == null) return;
|
|
|
|
foreach (BaseAbility baseAbility in Resources.FindObjectsOfTypeAll<BaseAbility>())
|
|
{
|
|
if (Abilities.Contains(baseAbility)) continue;
|
|
|
|
Abilities.Add(baseAbility);
|
|
}
|
|
}*/
|
|
}
|