101 lines
2.1 KiB
C#
101 lines
2.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class NPCDialogue : MonoBehaviour
|
|
{
|
|
[Header("UI组件")]
|
|
public Text textLabel;
|
|
public Image faceImage;
|
|
|
|
[Header("文本文件")]
|
|
public TextAsset textFile;
|
|
public int index=0;
|
|
List<string> textList = new List<string>();
|
|
|
|
/// <summary>
|
|
/// NPC警告按钮
|
|
/// </summary>
|
|
public Button ExclamationPointBtn;
|
|
|
|
/// <summary>
|
|
/// 下一句话按钮
|
|
/// </summary>
|
|
public Button NextsentenceBtn;
|
|
|
|
/// <summary>
|
|
/// NPC对话框关闭按钮
|
|
/// </summary>
|
|
public Button ExitBtn;
|
|
|
|
/// <summary>
|
|
/// 是否点击下一句按钮
|
|
/// </summary>
|
|
bool isclick;
|
|
void Awake()
|
|
{
|
|
GetTextFormFile(textFile);
|
|
textLabel.text = textList[index];
|
|
}
|
|
private void OnEnable()
|
|
{
|
|
|
|
}
|
|
void Start()
|
|
{
|
|
//NPC感叹号按钮事件
|
|
ExclamationPointBtn.onClick.AddListener(() =>
|
|
{
|
|
ExclamationPointBtn.gameObject.SetActive(false);
|
|
faceImage.gameObject.SetActive(true);
|
|
index = 0;
|
|
textLabel.text = textList[index];
|
|
//return;
|
|
});
|
|
NextsentenceBtn.onClick.AddListener(() =>
|
|
{
|
|
if (index < textList.Count-1)
|
|
{
|
|
index++;
|
|
}
|
|
textLabel.text = textList[index];
|
|
});
|
|
//ExitBtn.onClick.AddListener(() =>
|
|
//{
|
|
// //index = 0;
|
|
// return;
|
|
//});
|
|
|
|
}
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 玩家碰到NPC感叹号按钮冒出清空index
|
|
/// </summary>
|
|
/// <param name="other"></param>
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.name == "Man_stand")
|
|
{
|
|
ExclamationPointBtn.gameObject.SetActive(true);
|
|
index = 0;
|
|
return;
|
|
}
|
|
}
|
|
public void GetTextFormFile(TextAsset textFile)
|
|
{
|
|
//清空数组
|
|
textList.Clear();
|
|
//
|
|
var LineDate = textFile.text.Split("\n");
|
|
foreach (var line in LineDate)
|
|
{
|
|
textList.Add(line);
|
|
}
|
|
}
|
|
}
|