+物品展示

todo 玩家背包
This commit is contained in:
2024-09-28 18:06:49 +08:00
parent d4a9b7e0a3
commit 6d3f85829b
24 changed files with 2452 additions and 69 deletions

View File

@@ -14,12 +14,16 @@ namespace Camera
_camera = GetComponent<UnityEngine.Camera>();
_processVolume = GetComponent<PostProcessVolume>();
}
private void Start()
private void OnEnable()
{
EventManager.Instance.PlayerRunning += PostProcess;
EventManager.Instance.PlayerRunStop += ProcessingStop;
}
private void OnDisable()
{
EventManager.Instance.PlayerRunning -= PostProcess;
EventManager.Instance.PlayerRunStop -= ProcessingStop;
}
private void PostProcess()
{

View File

@@ -16,12 +16,23 @@ namespace Camera
private void Start()
{
_originalPos = cameraTransform.localPosition;
}
private void OnEnable()
{
EventManager.Instance.PlayerRunning += OnPlayerRunning;
EventManager.Instance.PlayerRunStop += StopRunning;
EventManager.Instance.PlayerWalking += OnPlayerWalking;
EventManager.Instance.PlayerWalkStop += StopWalking;
}
private void OnDisable()
{
EventManager.Instance.PlayerRunning -= OnPlayerRunning;
EventManager.Instance.PlayerRunStop -= StopRunning;
EventManager.Instance.PlayerWalking -= OnPlayerWalking;
EventManager.Instance.PlayerWalkStop -= StopWalking;
}
private void OnPlayerRunning()
{

View File

@@ -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;

View File

@@ -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;
}
}
}

View 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);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d01b517b44ab4ca4adc5cec9b2a8ea4d
timeCreated: 1727505211

View File

@@ -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)

View File

@@ -0,0 +1,12 @@
namespace Event.EventArgs
{
public class ItemDialogArgs : System.EventArgs
{
public string ItemName { get;private set; }
public ItemDialogArgs(string nItemName)
{
ItemName = nItemName;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d9296ff0a4da4c7094115457f7278e00
timeCreated: 1727505266

View File

@@ -0,0 +1,6 @@
using Event.EventArgs;
namespace Event.EventHandler
{
public delegate void ItemDialogHandler(ItemDialogArgs args);
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: beeb3f2691a14bb291fd94c08e811d6d
timeCreated: 1727505146

View File

@@ -42,8 +42,10 @@ namespace Event
public event PlayerWalkStartHandler PlayerWalkStart;
public event PlayerWalkStopHandler PlayerWalkStop;
public event PlayerWalkingHandler PlayerWalking;
public event ItemDialogHandler ItemDialog;
public void DialogEventSwitch(string eventName, string args)
public void EventSwitch(string eventName, string args)
{
switch (eventName)
{
@@ -85,6 +87,11 @@ namespace Event
PlayerRunStart?.Invoke();
}
public void OnItemDialog(string nName)
{
ItemDialog?.Invoke(new ItemDialogArgs(nName));
}
public void OnPlayerRunning()
{
PlayerRunning?.Invoke();

View File

@@ -8,11 +8,16 @@ namespace Items.Abstract
{
public int index;
private void Start()
private void OnEnable()
{
EventManager.Instance.CameraInterAct += ReceiveEvent;
}
private void OnDisable()
{
EventManager.Instance.CameraInterAct -= ReceiveEvent;
}
protected virtual void ReceiveEvent(CameraInterActArgs item)
{
if (item.Item != gameObject) return;
@@ -21,7 +26,7 @@ namespace Items.Abstract
protected virtual void ActivateItem()
{
Debug.Log("Item is activated");
//Debug.Log("Item is activated");
}
}
}

View File

@@ -10,6 +10,8 @@ namespace Items
{
base.ActivateItem();
EventManager.Instance.OnDialogPop(index);
EventManager.Instance.OnItemDialog(gameObject.name);
Destroy(gameObject);
}
}
}

View File

@@ -1,5 +1,4 @@
using System;
using UnityEngine;
using UnityEngine;
namespace UI
{