ShanxiKnowledgeBase/SXElectricityInformationAcq.../Assets/taoruiqi/Script/NPC Dialogue.cs

104 lines
2.3 KiB
C#

using DefaultNamespace.ProcessMode;
using MotionFramework;
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(() =>
{
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(GameObject.Find("Man_stand"));
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);
}
}
}