149 lines
4.3 KiB
C#
149 lines
4.3 KiB
C#
using Crosstales.RTVoice.Tool;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
using static Unity.Burst.Intrinsics.X86.Avx;
|
|
using System.Text;
|
|
using UnityEngine.Networking;
|
|
using System;
|
|
|
|
public class UITalk : UIBase
|
|
{
|
|
public TextMeshProUGUI talkTxt;
|
|
public Button nextBtn;
|
|
public Image doc, p;
|
|
|
|
public SpeechText speak;
|
|
|
|
List<DataItem3> talkList;
|
|
static int currentTalkIndex = 0;
|
|
|
|
Animator talkMan;
|
|
|
|
private void Awake()
|
|
{
|
|
speak = GameObject.Find("SpeechText").GetComponent<SpeechText>();
|
|
doc = this.gameObject.transform.Find("doc").GetComponent<Image>();
|
|
p = this.gameObject.transform.Find("people").GetComponent<Image>();
|
|
talkMan = DataManager.Instance.GetGameData().talkMan;
|
|
talkList = new List<DataItem3>();
|
|
currentTalkIndex = 0;
|
|
nextBtn.onClick.AddListener(() =>
|
|
{
|
|
//BeginTalk();
|
|
});
|
|
GetTalkMsg();
|
|
EventCenter.dispatcher.AddListener(MsgType.OnGetTalkMsg, OnGetTalkData);
|
|
|
|
if (!DataManager.Instance.isAddEventRTVoice)
|
|
{
|
|
speak.OnSpeechTextComplete += OnSpeakEnd;
|
|
DataManager.Instance.isAddEventRTVoice = true;
|
|
}
|
|
}
|
|
|
|
private void OnSpeakEnd()
|
|
{
|
|
BeginTalk();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EventCenter.dispatcher.RemoveListener(MsgType.OnGetTalkMsg, OnGetTalkData);
|
|
}
|
|
|
|
private void OnGetTalkData(Message evt)
|
|
{
|
|
this.talkList = DataManager.Instance.currentTalk;
|
|
if (this.talkList != null)
|
|
{
|
|
if (currentTalkIndex >= this.talkList.Count)
|
|
{
|
|
UIManager.Instance.DestoryUI(UIType.UITalk);
|
|
return;
|
|
}
|
|
BeginTalk(this.talkList[currentTalkIndex].msg);
|
|
}
|
|
}
|
|
|
|
void BeginTalk()
|
|
{
|
|
this.talkList = DataManager.Instance.currentTalk;
|
|
if (this.talkList != null)
|
|
{
|
|
if (currentTalkIndex >= this.talkList.Count)
|
|
{
|
|
UIManager.Instance.DestoryUI(UIType.UITalk);
|
|
return;
|
|
}
|
|
BeginTalk(this.talkList[currentTalkIndex].msg);
|
|
}
|
|
}
|
|
|
|
void BeginTalk(string talk)
|
|
{
|
|
speak.Text = talk;
|
|
//talkTxt.DOText
|
|
talkTxt.text = talk;
|
|
speak.Speak();
|
|
string text = talkTxt.text;
|
|
var t = DOTween.To(() => string.Empty, value => talkTxt.text = value, text, talk.Length > 5 ? 2f : 1f).SetEase(Ease.Linear);
|
|
t.SetOptions(true);
|
|
if (null == this)
|
|
{
|
|
this.gameObject.SetActive(false);
|
|
}
|
|
if (this.talkList[currentTalkIndex].senderCode == 2)
|
|
{
|
|
//ResetTalkMan();
|
|
//talkMan.SetBool("totalk", true);
|
|
p?.gameObject.SetActive(true);
|
|
doc?.gameObject.SetActive(false);
|
|
}
|
|
else if (this.talkList[currentTalkIndex].senderCode == 1)
|
|
{
|
|
//ResetTalkMan();
|
|
//talkMan.SetBool("tolisten", true);
|
|
p?.gameObject.SetActive(false);
|
|
doc?.gameObject.SetActive(true);
|
|
}
|
|
currentTalkIndex++;
|
|
}
|
|
|
|
private void ResetTalkMan()
|
|
{
|
|
talkMan.SetBool("totalk", false);
|
|
talkMan.SetBool("tolisten", false);
|
|
}
|
|
|
|
private void GetTalkMsg()
|
|
{
|
|
var people = DataManager.Instance.currentSelectPeople;
|
|
var id = DataManager.Instance.currentData.id;
|
|
//http://122.112.171.137:85/api/diagnosis/message/list/{backgroundType}/{relationId}
|
|
string url = "http://122.112.171.137:85/api/diagnosis/message/list/" + DataManager.Instance.currentBGType + "/" + id;
|
|
StartCoroutine(Get(url));
|
|
}
|
|
|
|
IEnumerator Get(string url)
|
|
{
|
|
UnityWebRequest request = UnityWebRequest.Get(url);
|
|
yield return request.SendWebRequest();
|
|
if (request.isHttpError || request.isNetworkError)
|
|
{
|
|
Debug.LogError(request.error);
|
|
}
|
|
else
|
|
{
|
|
string receiveContent = request.downloadHandler.text;
|
|
byte[] datas = Encoding.UTF8.GetBytes(receiveContent);
|
|
receiveContent = Encoding.UTF8.GetString(datas, 0, datas.Length);
|
|
//JsonInfo jsonInfo = JsonMapper.ToObject<JsonInfo>(receiveContent);
|
|
DataParse.Instance.ParsePeopleTalk(receiveContent);
|
|
}
|
|
}
|
|
}
|