26 lines
882 B
C#
26 lines
882 B
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
// 게임에 존재하는 모든 아이템의 목록 (StoryDatabase와 같은 "단일 원본" 역할).
|
|
// 저장 파일에는 Id 문자열만 남으므로, Id → ItemData 복원은 이 에셋이 담당한다.
|
|
// 게임에 하나만 만들어 ItemHud에 꽂아 쓴다.
|
|
[CreateAssetMenu(menuName = "Item/Item Database")]
|
|
public class ItemDatabase : ScriptableObject
|
|
{
|
|
[SerializeField] private List<ItemData> _items = new();
|
|
|
|
public IReadOnlyList<ItemData> Items => _items;
|
|
|
|
public ItemData FindById(string id)
|
|
{
|
|
if (string.IsNullOrEmpty(id)) return null;
|
|
foreach (var item in _items)
|
|
{
|
|
if (item == null) continue;
|
|
string itemId = string.IsNullOrEmpty(item.Id) ? item.name : item.Id;
|
|
if (itemId == id) return item;
|
|
}
|
|
return null;
|
|
}
|
|
}
|