34 lines
823 B
C#
34 lines
823 B
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace DDD
|
|
{
|
|
public class DataSo<T> : ScriptableObject where T : IId
|
|
{
|
|
[SerializeField]
|
|
protected List<T> Datas = new();
|
|
|
|
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<T> newList)
|
|
{
|
|
Datas = newList;
|
|
}
|
|
|
|
public List<T> GetDataList()
|
|
{
|
|
return Datas;
|
|
}
|
|
|
|
public int GetDataCount() => Datas.Count;
|
|
}
|
|
} |