33 lines
889 B
C#
33 lines
889 B
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace YachtDice.Dice
|
|
{
|
|
[CreateAssetMenu(fileName = "DiceCatalog", menuName = "YachtDice/Dice/Catalog")]
|
|
public class DiceCatalog : ScriptableObject
|
|
{
|
|
[SerializeField] private List<DiceDefinition> dice = new();
|
|
|
|
public IReadOnlyList<DiceDefinition> All => dice;
|
|
|
|
public DiceDefinition FindById(string id)
|
|
{
|
|
for (int i = 0; i < dice.Count; i++)
|
|
{
|
|
if (dice[i] != null && dice[i].Id == id)
|
|
return dice[i];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
public static DiceCatalog CreateForTest(List<DiceDefinition> defs)
|
|
{
|
|
var catalog = CreateInstance<DiceCatalog>();
|
|
catalog.dice = defs ?? new List<DiceDefinition>();
|
|
return catalog;
|
|
}
|
|
#endif
|
|
}
|
|
}
|