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.

143 lines
3.1 KiB

using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.UI;
public class Conversation : MonoBehaviour
{
private string info;
private Text txt;
public float delay = 0.1f;
[Header("题号")]
public int QuesitionIndex = 1;
public void Init()
{
txt = this.transform.Find("Text").GetComponent<Text>();
info = txt.text;
txt.text = "";
int conversationindex = transform.GetSiblingIndex()+1;
EventCenter.AddListener<int>(EventType.ShowQuestion, (index) =>
{
//conversationindex = QuesitionIndex;
try
{
Show(index);
Debug.Log(index);
}
catch
{
Show();
Debug.LogWarning("index丢失");
}
});
EventCenter.AddListener(EventType.HideQuestion, Hide);
if (gameObject.activeSelf)
{
Debug.Log("隐藏");
gameObject.SetActive(false);
}
}
public void Show(int index=1)
{
if (index != this.QuesitionIndex) return;
this.gameObject.SetActive(true);
StartCoroutine(ShowText(index));
}
public void Show()
{
this.gameObject.SetActive(true);
StartCoroutine(ShowText(QuesitionIndex));
}
public void Hide()
{
this.gameObject.SetActive(false);
}
IEnumerator ShowText(int index)
{
for (int i = 0; i < info.Length; i++)//遍历插入字符串的长度
{
txt.text = info.Substring(0, i);
yield return new WaitForSeconds(delay);//每次延迟的时间 数值越小 延迟越少
}
if (QuesitionIndex == 6|| QuesitionIndex == 7||QuesitionIndex==13||QuesitionIndex==16||QuesitionIndex==19)
{
Invoke("yc", 2);
}
else
{
Invoke("Delay", 2);
}
}
/// <summary>
/// 延迟2秒关闭上一段对话 以及打开我们输入框的那个
/// </summary>
public void yc()
{
// EventCenter.Broadcast(EventType.ShowInput);
if (QuesitionIndex > 12)
{
if (QuesitionIndex == 13)
{
GameManager.Instance.obj1.SetActive(true);
}
if (QuesitionIndex == 16)
{
GameManager.Instance.obj2.SetActive(true);
}
if (QuesitionIndex == 19)
{
GameManager.Instance.conversationInputs[QuesitionIndex - 1].gameObject.SetActive(true);
GameManager.Instance.conversations[QuesitionIndex - 1].gameObject.SetActive(false);
}
}
else
{
GameManager.Instance.conversationInputs[QuesitionIndex - 1].gameObject.SetActive(true);
GameManager.Instance.conversations[QuesitionIndex - 1].gameObject.SetActive(false);
}
}
public void Delay()
{
GameManager.Instance.UpdateQuestionIndex();
}
}