using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.Serialization; namespace DDD { public class DataSo : ScriptableObject where T : IId { [FormerlySerializedAs("Datas")] [SerializeField] protected List _datas = new(); private void OnEnable() { Initialize(); } private void OnValidate() { Initialize(); } protected virtual void Initialize() { } public T GetDataById(string id) => _datas.FirstOrDefault(x => x.Id == id); public bool ContainsData(string id) => _datas.Any(x => x.Id == id); public bool TryGetDataById(string id, out T data) { data = _datas.FirstOrDefault(x => x.Id == id); return data != null; } public void SetDataList(List newList) { _datas = newList; } public List GetDataList() { return _datas; } public int GetDataCount() => _datas.Count; } }