feat(Dialogue): 实现基本的对话系统
This commit is contained in:
51
Assets/Script/Gameplay/UI/PlayerDialogueViewer.cs
Normal file
51
Assets/Script/Gameplay/UI/PlayerDialogueViewer.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
using Script.Gameplay.Input;
|
||||
using Script.Gameplay.Player;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
// 负责显示玩家对话内容的UI组件
|
||||
public class PlayerDialogueViewer : UIBase
|
||||
{
|
||||
[SerializeField] private TMP_Text dialogueText;
|
||||
[SerializeField] private GameObject panel;
|
||||
private bool isShowingPanel = false;
|
||||
private PlayerDialogueController playerDialogueController;
|
||||
private InputManager inputManager;
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
inputManager = InputManager.Instance;
|
||||
ControllerLocator.Instance.TryGetWait<PlayerDialogueController>(OnGetPlayerDialogueController);
|
||||
}
|
||||
|
||||
private void OnGetPlayerDialogueController(PlayerDialogueController controller)
|
||||
{
|
||||
playerDialogueController = controller;
|
||||
playerDialogueController.RegisterDialogueViewer(this);
|
||||
}
|
||||
|
||||
public void ReceiveDialogue(string content)
|
||||
{
|
||||
if(!isShowingPanel) OpenPanel();
|
||||
dialogueText.text = content;
|
||||
}
|
||||
|
||||
private void OpenPanel()
|
||||
{
|
||||
isShowingPanel = true;
|
||||
Show();
|
||||
}
|
||||
|
||||
public void ClosePanel()
|
||||
{
|
||||
isShowingPanel = false;
|
||||
Hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user