+物品展示
todo 玩家背包
This commit is contained in:
@@ -53,14 +53,19 @@ namespace Dialog
|
||||
private IEnumerator Delay()
|
||||
{
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
EventManager.Instance.DialogEventSwitch(_eventToBeExc, _eventArg);
|
||||
EventManager.Instance.EventSwitch(_eventToBeExc, _eventArg);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
private void OnEnable()
|
||||
{
|
||||
EventManager.Instance.DialogPop += StartPrinting;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EventManager.Instance.DialogPop -= StartPrinting;
|
||||
}
|
||||
|
||||
private void Time2Break()
|
||||
{
|
||||
if (!isTime2Break) return;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Assets/Scripts/Dialog/ItemDialog.cs
Normal file
46
Assets/Scripts/Dialog/ItemDialog.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Event;
|
||||
using Event.EventArgs;
|
||||
using Keyboard;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Dialog
|
||||
{
|
||||
public class ItemDialog : MonoBehaviour
|
||||
{
|
||||
public RawImage itemIcon;
|
||||
public TMP_Text itemName;
|
||||
public TMP_Text itemDescription;
|
||||
public GameObject panel;
|
||||
private string _itemName;
|
||||
private void OnEnable()
|
||||
{
|
||||
EventManager.Instance.ItemDialog+=DialogPop;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EventManager.Instance.ItemDialog-=DialogPop;
|
||||
}
|
||||
|
||||
private void DialogPop(ItemDialogArgs itemDialogArgs)
|
||||
{
|
||||
var itemText = DialogManager.Instance.GetItemText(itemDialogArgs.ItemName);
|
||||
if (itemText is null) return;
|
||||
panel.SetActive(true);
|
||||
itemIcon.texture = Resources.Load<Texture2D>("Item" + "/" + itemText.Name);
|
||||
itemName.text = itemText.Name;
|
||||
itemDescription.text = itemText.Description;
|
||||
Time.timeScale = 0;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if ((!panel.activeSelf || !Input.GetKeyDown(KeyCode.Escape)) &&
|
||||
!Input.GetKeyDown(KeySettingManager.Instance.GetKey("InterAct"))) return;
|
||||
Time.timeScale = 1;
|
||||
panel.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Dialog/ItemDialog.cs.meta
Normal file
3
Assets/Scripts/Dialog/ItemDialog.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d01b517b44ab4ca4adc5cec9b2a8ea4d
|
||||
timeCreated: 1727505211
|
||||
@@ -49,14 +49,19 @@ namespace Dialog
|
||||
private IEnumerator Delay()
|
||||
{
|
||||
yield return new WaitForSeconds(1f);
|
||||
EventManager.Instance.DialogEventSwitch(_eventToBeExc, _eventArg);
|
||||
EventManager.Instance.EventSwitch(_eventToBeExc, _eventArg);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
private void OnEnable()
|
||||
{
|
||||
EventManager.Instance.DialogPop += StartPrinting;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EventManager.Instance.DialogPop -= StartPrinting;
|
||||
}
|
||||
|
||||
private IEnumerator BlinkCursor()
|
||||
{
|
||||
while (true)
|
||||
|
||||
Reference in New Issue
Block a user