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 textList = new List(); /// /// NPC警告按钮 /// public Button ExclamationPointBtn; /// /// 下一句话按钮 /// public Button NextsentenceBtn; /// /// NPC对话框关闭按钮 /// public Button ExitBtn; /// /// 是否点击下一句按钮 /// bool isclick; void Awake() { GetTextFormFile(textFile); textLabel.text = textList[index]; } private void OnEnable() { } void Start() { //NPC感叹号按钮事件 ExclamationPointBtn.onClick.AddListener(() => { MotionEngine.GetModule().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() { } /// /// 玩家碰到NPC感叹号按钮冒出清空index /// /// 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); } } }