+物品展示
todo 玩家背包
This commit is contained in:
@@ -27,9 +27,21 @@ namespace Dialog
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemText
|
||||
{
|
||||
public readonly string Name;
|
||||
public readonly string Description;
|
||||
|
||||
public ItemText(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
}
|
||||
public class DialogManager : MonoBehaviour
|
||||
{
|
||||
private readonly List<Dialog> _dialog = new();
|
||||
private readonly List<ItemText> _itemTexts = new();
|
||||
private static DialogManager _instance;
|
||||
|
||||
public static DialogManager Instance
|
||||
@@ -53,10 +65,32 @@ namespace Dialog
|
||||
else
|
||||
{
|
||||
LoadCsv("Dialog/DialogData");
|
||||
LoadItemTexts("Dialog/ItemText");
|
||||
_instance = this;
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadItemTexts(string resourcePath)
|
||||
{
|
||||
var texts = Resources.Load<TextAsset>(resourcePath);
|
||||
if (texts == null)
|
||||
{
|
||||
Debug.LogError($"Unable to find CSV file at path: {resourcePath}");
|
||||
return;
|
||||
}
|
||||
var lines = texts.text.Split('\n');
|
||||
for (var i = 1; i < lines.Length; i++)
|
||||
{
|
||||
var values = lines[i].Split(',');
|
||||
if (values.Length < 2) continue;
|
||||
var text = new ItemText(
|
||||
values[0],
|
||||
values[1]
|
||||
);
|
||||
_itemTexts.Add(text);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadCsv(string resourcePath)
|
||||
{
|
||||
var textAsset = Resources.Load<TextAsset>(resourcePath);
|
||||
@@ -95,5 +129,15 @@ namespace Dialog
|
||||
Debug.LogWarning($"Dialog with index {index} not found.");
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemText GetItemText(string nName)
|
||||
{
|
||||
foreach (var text in _itemTexts.Where(text => text.Name == nName))
|
||||
{
|
||||
return text;
|
||||
}
|
||||
Debug.LogWarning($"Dialog with name {nName} not found.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user