using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Video; public class CreateDialog : MonoBehaviour { int idzoeListenrepeat; string route; public static CreateDialog instance; AudioSource source; WriteFile writeFile; public int indexlisten = 0; // public Image imageDialog; List botoes; public Text repeat; public RectTransform trGroup; public GameObject canvas; bool playingAudio; public List clips; public List sprsCharacters; private void Awake() { source = gameObject.AddComponent(); } public IEnumerator createDialogTextCoroutine() { yield return StartCoroutine(MontarResources()); GameObject phrasetoCreate = Resources.Load("Class/DialogStep/DialogsNew"); botoes = new List(); exit tutorial = GetComponentInChildren(); while (!tutorial.closed) { yield return new WaitForEndOfFrame(); } for(int i = 0; i < ApiClass.listen_repeat.response.Length; i++) { GameObject thisObj = Instantiate(phrasetoCreate, trGroup); thisObj.transform.localScale = new Vector2(1, 1); ListenRepeat_Option LR = thisObj.GetComponent(); LR.index = i; LR.SetImgCharacter(sprsCharacters[i]); botoes.Add(false); StartCoroutine(IncreaseSizeLR(thisObj.transform)); yield return new WaitForSecondsRealtime(0.15f); } SetInformations(idzoeListenrepeat); } IEnumerator IncreaseSizeLR(Transform tr) { float value = 0; while (value < 1) { value += Time.deltaTime * 5; tr.localScale = new Vector3(value, value, 1); yield return new WaitForEndOfFrame(); } tr.localScale = new Vector3(1, 1, 1); yield break; } public void SetInformations(int id) { writeFile = new WriteFile(); idzoeListenrepeat = id; StartCoroutine(GetInfoCor()); instance = this; if (!ReadingFile.StudentUsers.Contains(ReadingFile.instance.userType)) { CheckEnd(true); } } IEnumerator GetInfoCor() { ApiClass api = ApiClass.instance; route = api.route; yield return StartCoroutine(MontarResources()); } IEnumerator MontarResources() { ApiClass api = ApiClass.instance; clips = new List(); for (int i = 0; i < ApiClass.listen_repeat.response.Length; i++) { string nomeAudio = "LR_"+ ApiClass.listen_repeat.response[i].idzoelistenrepeat + "_" + i + ".mp3"; //string nomeImagem = "LR_" + ApiClass.listen_repeat.response[i].idzoelistenrepeat + "_" + i + ".png"; yield return StartCoroutine(GetAudioClip("LR/" + nomeAudio)); } sprsCharacters = new List(); for (int i = 0; i < ApiClass.listen_repeat.response.Length; i++) { string nomeImagem = "LR_" + ApiClass.listen_repeat.response[i].idzoelistenrepeat + "_" + i + ".png"; yield return StartCoroutine(DownloadImgCharacter("LR/" + nomeImagem)); } yield break; } IEnumerator DownloadImgCharacter(string path) { string url = "http://" + ReadingFile.iploc + "/zoeGamesResources/" + path; using(WWW www = new WWW(url)) { yield return www; sprsCharacters.Add(Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0))); } yield break; } IEnumerator GetAudioClip(string path) { string url = "http://" + ReadingFile.iploc + "/zoeGamesResources/" + path; Debug.Log(url); using (WWW www = new WWW(url)) { yield return www; clips.Add(www.GetAudioClip()); } } public IEnumerator ReproduzirAudio(ListenRepeat_Option ls) { if (!playingAudio) { playingAudio = true; ls.gameObject.GetComponent().SetBool("listen", true); source.clip = clips[ls.index]; source.Play(); yield return new WaitForSecondsRealtime(clips[ls.index].length); ls.RepeatTxt(); yield return new WaitForSecondsRealtime(clips[ls.index].length + 1); playingAudio = false; ls.EndListen(); botoes[ls.index] = true; CheckEnd(); } } void CheckEnd(bool teacher = false) { bool all = true; foreach (bool item in botoes) { Debug.Log(item); if (!item) { all = false; } } if (all || teacher) { EndStep(); } } void EndStep() { GeneralScript.instance.LiberarAvanco(true); GetComponent().SetTrigger("end"); } IEnumerator ShowRepeat() { yield return new WaitForSeconds(1f); yield return new WaitForSeconds(CreateDialog.instance.source.clip.length - .5f); repeat.gameObject.SetActive(true); StartCoroutine(HideRepeat()); } IEnumerator HideRepeat() { yield return new WaitForSeconds(CreateDialog.instance.source.clip.length - .5f); //repeat.SetActive(false); repeat.gameObject.SetActive(false); botoes = CreateDialog.instance.botoes; bool Finalizou = true; for (int i = 0; i < botoes.Count; i++) { if (!botoes[i]) Finalizou = false; } if (Finalizou) { GeneralScript general = GeneralScript.instance; general.LiberarAvanco(true); GetComponentInParent().CompletedLR(); } } public void ButtonClickShow() { repeat.GetComponent(); StartCoroutine(ShowRepeat()); } }