You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
AED/Assets/Tools/DialogueController.cs

47 lines
1.4 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using System;
public class DialogueController : MonoSingleton<DialogueController>
{
public Text showText;//对话显示位置
public int curDialogue = 0;//当前对话索引
[TextArea]
public string[] dialogues;
protected override void Awake()
{
base.Awake();
}
public void StartDialogue(int index,Action action = null, Text showPos = null, string str = "", bool waitPlayEndExecuteAction = true) {
if (curDialogue != index) return;
if (str == "") str = dialogues[index];
if (showPos == null) showPos = showText;
showPos.GetComponent<DialoguePlay>().PlayText(str);
curDialogue++;
if (action == null) return;
if (waitPlayEndExecuteAction)
{
StartCoroutine(WaitExecute(showPos.GetComponent<DialoguePlay>().IsPlay, action));
}
else {
action.Invoke();
}
}
public void StartDialogue(int index)
{
if (curDialogue != index) return;
showText.GetComponent<DialoguePlay>().PlayText(dialogues[index]);
curDialogue++;
}
IEnumerator WaitExecute(Func<bool> fun,Action action) {
yield return new WaitWhile(fun);
yield return new WaitForSeconds(1);
action.Invoke();
}
}