CCCPaste

EffectsRegistry

using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using WallstopStudios.UnityHelpers.Tags;

namespace MB6
{
[CreateAssetMenu(menuName = "Wallstop Studios/Unity Helpers/Attribute Effect Registry")]
public class EffectRegistry : ScriptableObject
{
[SerializeField] private List<AttributeEffect> _effects = new();
private Dictionary<string, AttributeEffect> _effectRegistry = new Dictionary<string, AttributeEffect>();

public void OnEnable()
{
_effectRegistry = _effects.ToDictionary(e=> e.name, e => e);
}

public void AddEffect(AttributeEffect effect) => _effects.Add(effect);

public void RemoveEffect(string lookupName) => _effects.RemoveAll(x => x.name == lookupName);

public AttributeEffect GetEffect(string lookupName) =>
_effectRegistry.TryGetValue(lookupName, out var effect) ? effect : null;

public IEnumerable<AttributeEffect> GetEffects() => _effects;
}
}