Files
YachtDice/Assets/Scripts/Dice/DiceCatalog.cs
T

33 lines
894 B
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Collections.Generic;
using UnityEngine;
namespace YachtDice.Dice
{
[CreateAssetMenu(fileName = "DiceCatalog", menuName = "YachtDice/Dice/Catalog")]
public class DiceCatalog : ScriptableObject
{
[SerializeField] private List<DiсeDefinition> dice = new();
public IReadOnlyList<DiсeDefinition> All => dice;
public DiсeDefinition 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<DiсeDefinition> defs)
{
var catalog = CreateInstance<DiceCatalog>();
catalog.dice = defs ?? new List<DiсeDefinition>();
return catalog;
}
#endif
}
}