RiftMayhem/Assets/Scripts/AbilitySystem/StatusEffectIndexer.cs
2025-02-12 22:43:02 +00:00

82 lines
2.2 KiB
C#

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