Initial commit
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
using Febucci.UI;
|
||||
using Febucci.UI.Core;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class DialogUiViewer : Singleton<DialogUiViewer>
|
||||
{
|
||||
#region 对话框UI
|
||||
private GameObject dialogBox;
|
||||
private TypewriterByCharacter dialogText;
|
||||
private TextMeshProUGUI actorName;
|
||||
private Button nextButton;
|
||||
#endregion
|
||||
|
||||
private Action nextStepAction;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 获取子物体
|
||||
dialogBox = transform.GetChild(0).gameObject;
|
||||
GetDialogComponentInBox(dialogBox);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 显示文字
|
||||
/// </summary>
|
||||
/// <param name="dialogLine">对话内容</param>
|
||||
/// <param name="actor">名称</param>
|
||||
/// <param name="nextStep">下一步</param>
|
||||
public void ShowLine(string dialogLine, string actor, Action nextStep)
|
||||
{
|
||||
dialogBox.SetActive(true);
|
||||
actorName.text = actor;
|
||||
dialogText.ShowText(dialogLine);
|
||||
nextStepAction = nextStep;
|
||||
}
|
||||
|
||||
public void ShowNextButton()
|
||||
{
|
||||
nextButton.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void ClickNextStep()
|
||||
{
|
||||
Action temp = nextStepAction;
|
||||
nextStepAction = null;
|
||||
temp?.Invoke();
|
||||
|
||||
|
||||
nextButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void GetDialogComponentInBox(GameObject box)
|
||||
{
|
||||
actorName = box.transform.GetChild(0).gameObject.GetComponent<TextMeshProUGUI>();
|
||||
dialogText = box.transform.GetChild(1).gameObject.GetComponent<TypewriterByCharacter>();
|
||||
nextButton = box.transform.GetChild(2).GetComponent<Button>();
|
||||
|
||||
dialogText.onTextShowed.AddListener(ShowNextButton);
|
||||
nextButton.onClick.AddListener(ClickNextStep);
|
||||
}
|
||||
|
||||
public void HideDialog()
|
||||
{
|
||||
dialogBox?.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user