1378 lines
43 KiB
C#
1378 lines
43 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.Video;
|
|
using System.IO;
|
|
using static ChConversations_Controller;
|
|
|
|
public class ApiClass : MonoBehaviour
|
|
{
|
|
public static ApiClass instance;
|
|
public int homeflames;
|
|
|
|
[System.Serializable]
|
|
public class DownloadLogs
|
|
{
|
|
public string name;
|
|
public bool state;
|
|
}
|
|
|
|
public List<DownloadLogs> downloadLogs;
|
|
|
|
#region stepClass
|
|
[Serializable]
|
|
public class StepClass
|
|
{
|
|
public int status;
|
|
public StepClassResponse[] response;
|
|
}
|
|
[Serializable]
|
|
public class StepClassResponse
|
|
{
|
|
public int idstepclass, qtdeItens, actualExercise, actualItem, completedClass, continueClass;
|
|
public string answersdb;
|
|
}
|
|
#endregion
|
|
|
|
#region Etapas
|
|
[Serializable]
|
|
public class Etapas
|
|
{
|
|
public int status;
|
|
public EtapasResponse[] response;
|
|
}
|
|
[Serializable]
|
|
public class EtapasResponse
|
|
{
|
|
public int ordem, enabled, idexercises, idclassescontent, idclasses;
|
|
public string description, type, acao, obs;
|
|
}
|
|
#endregion
|
|
|
|
#region Question
|
|
[Serializable]
|
|
public class Questions
|
|
{
|
|
public int status;
|
|
public QuestionsResponse[] response;
|
|
}
|
|
[Serializable]
|
|
public class QuestionsResponse
|
|
{
|
|
public int idexercisequestions;
|
|
public string content;
|
|
}
|
|
#endregion
|
|
|
|
#region Insert step
|
|
[Serializable]
|
|
public class InsertStepClass
|
|
{
|
|
public int status;
|
|
}
|
|
#endregion
|
|
|
|
#region Exercise - Descript and Media
|
|
[Serializable]
|
|
public class Exercise
|
|
{
|
|
public int status;
|
|
public ExerciseResponse[] response;
|
|
}
|
|
[Serializable]
|
|
public class ExerciseResponse
|
|
{
|
|
public string description;
|
|
public int idexercises, idexercisetype, hasmedia, enabled;
|
|
}
|
|
#endregion
|
|
|
|
#region Answers
|
|
[Serializable]
|
|
public class Answers
|
|
{
|
|
public int status;
|
|
public AnswersResponse[] response;
|
|
}
|
|
[Serializable]
|
|
public class AnswersResponse
|
|
{
|
|
public string hasmedia, content;
|
|
public int iscorrect, idexerciseanswers;
|
|
}
|
|
#endregion
|
|
|
|
#region Video
|
|
[Serializable]
|
|
public class video
|
|
{
|
|
public int status;
|
|
public videoResponse[] response;
|
|
}
|
|
[Serializable]
|
|
public class videoResponse
|
|
{
|
|
public int idmedia;
|
|
public string description;
|
|
public string publishid;
|
|
public string type;
|
|
}
|
|
#endregion
|
|
|
|
#region Slide
|
|
[Serializable]
|
|
public class slide
|
|
{
|
|
public int status;
|
|
public slideResponse[] response;
|
|
}
|
|
[Serializable]
|
|
public class slideResponse
|
|
{
|
|
public int idslides, itens;
|
|
public string title;
|
|
}
|
|
#endregion
|
|
|
|
#region Animacao
|
|
[Serializable]
|
|
public class Animacao
|
|
{
|
|
public int status;
|
|
public ResponseAnimacao[] response;
|
|
}
|
|
[Serializable]
|
|
public class ResponseAnimacao
|
|
{
|
|
public int idanimations;
|
|
public string description;
|
|
}
|
|
#endregion
|
|
|
|
#region ExerciseAnime
|
|
[Serializable]
|
|
public class ExerciseAnime
|
|
{
|
|
public int status;
|
|
public ResponseExerciseAnime[] response;
|
|
}
|
|
[Serializable]
|
|
public class ResponseExerciseAnime
|
|
{
|
|
public int idanimationexercises;
|
|
public int seconds;
|
|
public int idconversationtree;
|
|
public int idexercises;
|
|
public int idzoechattime;
|
|
public string description;
|
|
public string type;
|
|
}
|
|
#endregion
|
|
|
|
#region StepClass
|
|
[Serializable]
|
|
public class StepClassToUpdate
|
|
{
|
|
public int idstepclass, actualexercise, notegame = 0, finishedclass = 0, continueClass = 0;
|
|
public List<string> answersdb = new List<string>();
|
|
}
|
|
[SerializeField]
|
|
#endregion
|
|
|
|
#region ListenRepeat
|
|
[Serializable]
|
|
public class listenRepeat
|
|
{
|
|
public int status;
|
|
public listenRepeatResponse[] response;
|
|
}
|
|
[Serializable]
|
|
public class listenRepeatResponse
|
|
{
|
|
public int idzoelistenrepeat, ordem, hasmedia, idzoelistenrepeatphrases;
|
|
public string description, phrase;
|
|
}
|
|
#endregion
|
|
|
|
public StepClassToUpdate updateStep = new StepClassToUpdate();
|
|
bool dontlaunchAnswers = false;
|
|
string answersPrevious;
|
|
|
|
public class BypassCertificate : CertificateHandler
|
|
{
|
|
protected override bool ValidateCertificate(byte[] certificateData)
|
|
{
|
|
//Simply return true no matter what
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public string route = "http://18.228.91.135:3337";
|
|
//public string route = "http://localhost:3337";
|
|
public bool gotRoute = false;
|
|
string token; GeneralScript general;
|
|
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
downloadLogs = new List<DownloadLogs>();
|
|
token = PlayerPrefs.GetString("token");
|
|
general = GeneralScript.instance;
|
|
|
|
StartCoroutine(GetRouteCor());
|
|
StartCoroutine(CheckStep());
|
|
}
|
|
|
|
public IEnumerator GetRouteCor()
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
while (!ReadingFile.instance.canGo)
|
|
{
|
|
yield return new WaitForFixedUpdate();
|
|
}
|
|
|
|
if (ReadingFile.instance.userType == ReadingFile.UserType.Teacher)
|
|
{
|
|
ChangeInterfaceToTeacher();
|
|
}
|
|
|
|
route = ReadingFile.route;
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
gotRoute = true;
|
|
}
|
|
|
|
void ChangeInterfaceToTeacher()
|
|
{
|
|
GameObject objCanvas = GameObject.Find("Canvas");
|
|
|
|
GameObject objCreate = new GameObject();
|
|
objCanvas.transform.parent = objCreate.transform;
|
|
|
|
objCreate.transform.localScale = new Vector3(.8f, .8f, .8f);
|
|
|
|
GameObject canvasProf = Instantiate(Resources.Load<GameObject>("Teacher/CanvasTeacher"),
|
|
objCreate.transform);
|
|
|
|
canvasProf.GetComponent<Canvas>().worldCamera = Camera.main;
|
|
|
|
GameObject canvasLogo = Instantiate(Resources.Load<GameObject>("Teacher/Canvas_Marca"),
|
|
objCreate.transform);
|
|
canvasLogo.transform.localScale = new Vector3(1, 1, 1);
|
|
}
|
|
|
|
public IEnumerator CheckStep()
|
|
{
|
|
while (!gotRoute)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
string url = route + "/api/classes/getStepClass/" + ReadingFile.idmatricula + "/" + GeneralScript.idClasses + "/" + ReadingFile.idUnit;
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
general.completed = 1;
|
|
Debug.Log(www.error);
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
|
|
StepClass step = JsonUtility.FromJson<StepClass>(Json);
|
|
|
|
if (step.status == 200)
|
|
{
|
|
general = GetComponent<GeneralScript>();
|
|
if (step.response[0].completedClass == 1)
|
|
{
|
|
general.minExercises = 0;
|
|
updateStep.actualexercise = 0;
|
|
general.completed = 2;
|
|
dontlaunchAnswers = true;
|
|
answersPrevious = step.response[0].answersdb;
|
|
}
|
|
else
|
|
{
|
|
general.completed = 1;
|
|
general.minExercises = step.response[0].actualExercise;
|
|
general.stepstarted = step.response[0].actualExercise;
|
|
if (step.response[0].continueClass == 1)
|
|
{
|
|
string answers = step.response[0].answersdb;
|
|
string[] splitedAnswers = answers.Split(',');
|
|
updateStep.answersdb.Clear();
|
|
for (int i = 0; i < splitedAnswers.Length; i++)
|
|
{
|
|
updateStep.answersdb.Add(splitedAnswers[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
general.SetSlider();
|
|
|
|
updateStep.idstepclass = step.response[0].idstepclass;
|
|
updateStep.finishedclass = step.response[0].completedClass;
|
|
updateStep.actualexercise = step.response[0].actualExercise;
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
else
|
|
{
|
|
general.completed = 1;
|
|
yield return StartCoroutine(insertStepClass());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void changeActualExercises(int i)
|
|
{
|
|
updateStep.actualexercise = i;
|
|
}
|
|
|
|
public IEnumerator insertStepClass()
|
|
{
|
|
if (!ReadingFile.StudentUsers.Contains(ReadingFile.instance.userType))
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
WWWForm form = new WWWForm();
|
|
form.AddField("idusers", ReadingFile.idmatricula);
|
|
form.AddField("idclasses", GeneralScript.idClasses);
|
|
form.AddField("idunits", ReadingFile.idUnit);
|
|
|
|
string url = route + "/api/classes/insertStepClass";
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Post(url, form))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.Log(www.error);
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text; Debug.Log(Json);
|
|
|
|
InsertStepClass insert = JsonUtility.FromJson<InsertStepClass>(Json);
|
|
|
|
if (insert.status == 200)
|
|
{
|
|
yield return CheckStep();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
public IEnumerator getEtapas()
|
|
{
|
|
yield return new WaitForFixedUpdate();
|
|
|
|
string url = route + "/api/classescontent/getClassescontent/" + GeneralScript.idClasses;
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError && www.isHttpError)
|
|
{
|
|
Debug.Log(www.error);
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
|
|
if (Json == "")
|
|
{
|
|
StartCoroutine(getEtapas());
|
|
}
|
|
else
|
|
{
|
|
Etapas etapas = JsonUtility.FromJson<Etapas>(Json);
|
|
if (etapas.status == 200)
|
|
{
|
|
GeneralScript general = GeneralScript.instance;
|
|
general.etapa = etapas.response;
|
|
general.maxExercises = etapas.response.Length;
|
|
|
|
general.api = this;
|
|
general.stepsReady = true;
|
|
|
|
//StartCoroutine(general.startDownloadingVideos());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#region Pegar informações de exercicio
|
|
public List<TypesClass.Questions> createquestion = new List<TypesClass.Questions>();
|
|
public IEnumerator getExercise(int idexercicio, bool inAnime, AnimeControl anime = null)
|
|
{
|
|
string url = route + "/api/exercises/getExercise2/" + idexercicio.ToString();
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
Exercise exercise = JsonUtility.FromJson<Exercise>(Json);
|
|
|
|
yield return StartCoroutine(getQuestion(exercise));
|
|
|
|
if (!inAnime)
|
|
{
|
|
general.questions = createquestion;
|
|
general.actualType = exercise.response[0].idexercisetype;
|
|
general.SpawnNextExercise();
|
|
}
|
|
else
|
|
{
|
|
anime.questions = createquestion;
|
|
anime.actualType = exercise.response[0].idexercisetype;
|
|
anime.SpawnExercise();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public IEnumerator getQuestion(Exercise Exercicio)
|
|
{
|
|
string url = route + "/api/questions/getQuestion/" + Exercicio.response[0].idexercises.ToString();
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
Questions question = JsonUtility.FromJson<Questions>(Json);
|
|
|
|
createquestion = new List<TypesClass.Questions>();
|
|
|
|
if (question.status == 200)
|
|
{
|
|
for (int i = 0; i < question.response.Length; i++)
|
|
{
|
|
createquestion.Add(new TypesClass.Questions());
|
|
createquestion[createquestion.Count - 1].enunciado = question.response[i].content;
|
|
yield return StartCoroutine(getAnswers(question.response[i].idexercisequestions, createquestion.Count - 1));
|
|
createquestion[i].answeredRight = false;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public IEnumerator getAnswers(int idexercicio, int indexCreate)
|
|
{
|
|
string url = route + "/api/answers/getAnswers/" + idexercicio.ToString();
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
Answers answers = JsonUtility.FromJson<Answers>(Json);
|
|
|
|
createquestion[indexCreate].hasmedia = false;
|
|
|
|
createquestion[indexCreate].op1 = answers.response[0].content;
|
|
if (answers.response[0].hasmedia == "1")
|
|
{
|
|
createquestion[indexCreate].photoId1 = answers.response[0].idexerciseanswers.ToString();
|
|
createquestion[indexCreate].hasmedia = true;
|
|
}
|
|
else
|
|
{
|
|
createquestion[indexCreate].answerid1 = answers.response[0].idexerciseanswers;
|
|
}
|
|
if (answers.response.Length > 1)
|
|
{
|
|
createquestion[indexCreate].op2 = answers.response[1].content;
|
|
if (answers.response[1].hasmedia == "1")
|
|
{
|
|
createquestion[indexCreate].photoId2 = answers.response[1].idexerciseanswers.ToString();
|
|
}
|
|
else
|
|
{
|
|
createquestion[indexCreate].answerid2 = answers.response[1].idexerciseanswers;
|
|
}
|
|
}
|
|
|
|
if (answers.response.Length > 2)
|
|
{
|
|
createquestion[indexCreate].op3 = answers.response[2].content;
|
|
if (answers.response[2].hasmedia == "1")
|
|
{
|
|
createquestion[indexCreate].photoId3 =
|
|
answers.response[2].idexerciseanswers.ToString();
|
|
}
|
|
else
|
|
{
|
|
createquestion[indexCreate].answerid3 = answers.response[2].idexerciseanswers;
|
|
}
|
|
}
|
|
if (answers.response.Length > 3)
|
|
{
|
|
createquestion[indexCreate].op4 = answers.response[3].content;
|
|
if (answers.response[3].hasmedia == "1")
|
|
{
|
|
createquestion[indexCreate].photoId4 = answers.response[3].idexerciseanswers.ToString();
|
|
}
|
|
else
|
|
{
|
|
createquestion[indexCreate].answerid4 = answers.response[3].idexerciseanswers;
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < answers.response.Length; i++)
|
|
{
|
|
if (answers.response[i].iscorrect == 1)
|
|
{
|
|
createquestion[indexCreate].rightQuestion = i + 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Pegar informações de vídeo
|
|
public IEnumerator getVideo(int idVideo, bool setLink)
|
|
{
|
|
string url = route + "/api/videos/getMedia/" + idVideo.ToString();
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
video videoInfo = JsonUtility.FromJson<video>(Json);
|
|
|
|
if (videoInfo.status == 200)
|
|
{
|
|
if (setLink)
|
|
{
|
|
//general.links.Add(videoInfo.response[0].publishid);
|
|
general.downloadingVideo = videoInfo.response[0].publishid;
|
|
StartCoroutine(DownloadFile(videoInfo.response[0].publishid, idVideo));
|
|
}
|
|
else
|
|
{
|
|
//StartCoroutine(general.SpawnVideo(videoInfo.response[0].idmedia));
|
|
StartCoroutine(general.SpawnVideo(videoInfo.response[0].idmedia, videoInfo.response[0].publishid));
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
|
|
public IEnumerator getBackVideo(string publishId)
|
|
{
|
|
string url = route + "/api/videos/backVideo/" + publishId;
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
/*string Json = www.downloadHandler.text;
|
|
video videoInfo = JsonUtility.FromJson<video>(Json);
|
|
|
|
if (videoInfo.status == 200)
|
|
{
|
|
|
|
}*/
|
|
}
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
#endregion
|
|
|
|
public IEnumerator getSlide(int id)
|
|
{
|
|
string url = route + "/api/slides/getSlide/" + id.ToString();
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
slide slideres = JsonUtility.FromJson<slide>(Json);
|
|
|
|
if (slideres.status == 200)
|
|
{
|
|
GeneralScript general = GeneralScript.instance;
|
|
general.SpawnSlide(slideres.response[0].itens, slideres.response[0].idslides);
|
|
}
|
|
}
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
|
|
public static listenRepeat listen_repeat;
|
|
|
|
public IEnumerator getListenRepeat(int id)
|
|
{
|
|
string url = route + "/api/listenrepeat/getLRDetails/" + id.ToString();
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
listenRepeat LRList = JsonUtility.FromJson<listenRepeat>(Json);
|
|
|
|
if (LRList.status == 200)
|
|
{
|
|
listen_repeat = LRList;
|
|
GeneralScript general = GeneralScript.instance;
|
|
|
|
general.SpawnLR(LRList.response[0].idzoelistenrepeat);
|
|
}
|
|
}
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
|
|
public IEnumerator lockClass()
|
|
{
|
|
if (!ReadingFile.StudentUsers.Contains(ReadingFile.instance.userType))
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
string url = route + "/api/lockClass/" + ReadingFile.idmatricula + "/" + ReadingFile.idUnit + "/" + GeneralScript.idClasses;
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.method = "GET";
|
|
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.certificateHandler = new BypassCertificate();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("LockClass Successful");
|
|
}
|
|
}
|
|
}
|
|
|
|
public IEnumerator updateStepClass()
|
|
{
|
|
if (!ReadingFile.StudentUsers.Contains(ReadingFile.instance.userType))
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
string url = route + "/api/classes/updateStepClass";
|
|
|
|
WWWForm form = new WWWForm();
|
|
form.AddField("idstepclass", updateStep.idstepclass);
|
|
form.AddField("idusers", ReadingFile.idmatricula);
|
|
form.AddField("idclasses", GeneralScript.idClasses);
|
|
form.AddField("actualClass", 0);
|
|
form.AddField("actualExercise", updateStep.actualexercise);
|
|
form.AddField("actualAnswer", 0);
|
|
form.AddField("actualItem", 0);
|
|
form.AddField("continueClass", updateStep.continueClass);
|
|
form.AddField("completedClass", updateStep.finishedclass);
|
|
form.AddField("note", 0);
|
|
form.AddField("notification", 0);
|
|
form.AddField("idunits", ReadingFile.idUnit);
|
|
form.AddField("notegame", updateStep.notegame);
|
|
form.AddField("homework", 1);
|
|
form.AddField("datefinal", DateTime.Now.AddDays(6).ToString());
|
|
form.AddField("dateinicial", DateTime.Now.ToString());
|
|
|
|
string generatedanswers = "";
|
|
if (dontlaunchAnswers)
|
|
{
|
|
form.AddField("answersdb", answersPrevious);
|
|
}
|
|
else
|
|
{
|
|
|
|
for (int i = 0; i < updateStep.answersdb.Count; i++)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
generatedanswers += updateStep.answersdb[i];
|
|
}
|
|
else
|
|
{
|
|
generatedanswers += ", " + updateStep.answersdb[i];
|
|
}
|
|
}
|
|
|
|
form.AddField("answersdb", generatedanswers);
|
|
}
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Post(url, form))
|
|
{
|
|
www.method = "PATCH";
|
|
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.certificateHandler = new BypassCertificate();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
if (!dontlaunchAnswers && updateStep.finishedclass == 1)
|
|
{
|
|
yield return StartCoroutine(launchAnswer(generatedanswers));
|
|
yield return StartCoroutine(launchNotes());
|
|
if (general.completed == 2)
|
|
{
|
|
yield return StartCoroutine(lockClass());
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
general.doneLaunchingnotes = true;
|
|
|
|
yield break;
|
|
}
|
|
|
|
IEnumerator launchNotes()
|
|
{
|
|
if (!ReadingFile.StudentUsers.Contains(ReadingFile.instance.userType))
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
string url = route + "/api/app/isLastClass/" + ReadingFile.idmatricula + "/" + ReadingFile.idUnit + "/" + GeneralScript.idClasses;
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.certificateHandler = new BypassCertificate();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log(www.downloadHandler.text);
|
|
}
|
|
}
|
|
}
|
|
|
|
public IEnumerator launchGames(int note, int idgames)
|
|
{
|
|
if (!ReadingFile.StudentUsers.Contains(ReadingFile.instance.userType))
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
if (!dontlaunchAnswers)
|
|
{
|
|
string url = route + "/api/classes/insertZoeUserGames";
|
|
|
|
WWWForm form = new WWWForm();
|
|
//form.AddField("idstages", 1);
|
|
form.AddField("idgames", idgames);
|
|
form.AddField("idusers", ReadingFile.idmatricula);
|
|
form.AddField("idunits", ReadingFile.idUnit);
|
|
form.AddField("idclasses", GeneralScript.idClasses);
|
|
form.AddField("note", note);
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Post(url, form))
|
|
{
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.certificateHandler = new BypassCertificate();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log(www.downloadHandler.text);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator launchAnswer(string answersComputed)
|
|
{
|
|
if (!ReadingFile.StudentUsers.Contains(ReadingFile.instance.userType))
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
if (!dontlaunchAnswers)
|
|
{
|
|
string url = route + "/api/answers/insertuseranswer";
|
|
|
|
for (int i = 0; i < updateStep.answersdb.Count; i++)
|
|
{
|
|
WWWForm form = new WWWForm();
|
|
form.AddField("idusers", ReadingFile.idmatricula);
|
|
form.AddField("idexerciseanswers", updateStep.answersdb[i]);
|
|
form.AddField("date_answered", DateTime.Now.ToShortDateString());
|
|
form.AddField("fixed", 1);
|
|
form.AddField("idclasses", GeneralScript.idClasses);
|
|
form.AddField("idunits", ReadingFile.idUnit);
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Post(url, form))
|
|
{
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.certificateHandler = new BypassCertificate();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning(www.downloadHandler.text);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#region Conversation Characters
|
|
|
|
public IEnumerator getBackgroundVideo(int idcharactersBackground, string nameCaller)
|
|
{
|
|
yield return StartCoroutine(DownloadResource("/backgrounds/" + idcharactersBackground + ".m4v", nameCaller));
|
|
string savepath = Application.persistentDataPath + "/videoFile" + nameCaller + ".mp4";
|
|
|
|
ChConversations_Controller.VideoCv video = new ChConversations_Controller.VideoCv();
|
|
video.nameCaller = nameCaller;
|
|
video.path = savepath;
|
|
|
|
ChConversations_Controller.instance.videos.Add(video);
|
|
|
|
yield break;
|
|
}
|
|
|
|
public IEnumerator getVideoConversation(int idmedia)
|
|
{
|
|
string url = route + "/api/videos/getMedia/" + idmedia;
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
video videoInfo = JsonUtility.FromJson<video>(Json);
|
|
|
|
if (videoInfo.status == 200)
|
|
{
|
|
yield return StartCoroutine(DownloadFile(videoInfo.response[0].publishid, idmedia));
|
|
string savepath = Application.persistentDataPath + "/videoFile_" + idmedia + ".mp4";
|
|
|
|
ChConversations_Controller.VideoCv video = new ChConversations_Controller.VideoCv();
|
|
video.nameCaller = idmedia.ToString();
|
|
video.path = savepath;
|
|
|
|
ChConversations_Controller.instance.videos.Add(video);
|
|
}
|
|
}
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
|
|
public IEnumerator DownloadResource(string filepath, string name, bool Replace = true)
|
|
{
|
|
bool Baixar = true;
|
|
string path = "http://" + ReadingFile.iploc + "/zoeGamesResources/" + filepath;
|
|
|
|
string savepath = Application.persistentDataPath + "/" + name;
|
|
if (File.Exists(savepath) && Replace)
|
|
{
|
|
File.Delete(savepath);
|
|
}
|
|
else if (File.Exists(savepath) && !Replace)
|
|
{
|
|
Baixar = false;
|
|
}
|
|
|
|
if (Baixar)
|
|
{
|
|
var www = new WWW(path);
|
|
yield return www;
|
|
|
|
File.WriteAllBytes(savepath, www.bytes);
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
yield break;
|
|
}
|
|
else
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Anime
|
|
public IEnumerator getAnimacao(int idanimations)
|
|
{
|
|
string url = route + "/api/animations/getAnimation/" + idanimations;
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
|
|
Animacao anime = JsonUtility.FromJson<Animacao>(Json);
|
|
|
|
if (anime.status == 200)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
//general.animes = new List<int>();
|
|
general.animes.Add(anime.response[0].idanimations);
|
|
|
|
yield return StartCoroutine(getVideoAnime(anime.response[0].idanimations));
|
|
//yield return StartCoroutine(getExerciseAnime(anime.response[0].idanimations.ToString()));
|
|
}
|
|
}
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
|
|
public IEnumerator getExerciseAnime(int idanimations)
|
|
{
|
|
string url = route + "/api/animations/getAnimationExercises/" + idanimations;
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
ExerciseAnime exerciseAnime = JsonUtility.FromJson<ExerciseAnime>(Json);
|
|
|
|
if (exerciseAnime.status == 200)
|
|
{
|
|
general.exercisesAnime = exerciseAnime.response;
|
|
}
|
|
}
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
|
|
public IEnumerator getVideoAnime(int idanimations)
|
|
{
|
|
string url = route + "/api/animations/backAnimation/" + idanimations;
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(token));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError(www.error);
|
|
}
|
|
else
|
|
{
|
|
|
|
File.WriteAllBytes(Application.persistentDataPath + "/anime_" + idanimations + ".mp4",
|
|
www.downloadHandler.data);
|
|
}
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
#endregion
|
|
|
|
#region CHARACTERS CONVERSATION
|
|
|
|
List<ConversationModel> ListaConversacao;
|
|
List<FeelingsModel> ListaFeelings;
|
|
string AudioExt = ".mp3";
|
|
string CharacterExt = ".png";
|
|
|
|
public IEnumerator GetConversationDetails(int idCharactersConversation)
|
|
{
|
|
string url = route + "/api/characters/getCharConvDetails/" + idCharactersConversation;
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(PlayerPrefs.GetString("token")));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError("Erro de Conexão");
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
ConversationResponse conversation = JsonUtility.FromJson<ConversationResponse>(Json);
|
|
|
|
if (conversation.status == 200)
|
|
{
|
|
ListaConversacao = new List<ConversationModel>();
|
|
ListaConversacao.AddRange(conversation.response);
|
|
}
|
|
}
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
|
|
public IEnumerator GetAllFeelings()
|
|
{
|
|
string url = route + "/api/characters/getAllFeelings";
|
|
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
www.SetRequestHeader("token", Uri.EscapeUriString(PlayerPrefs.GetString("token")));
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.LogError("Erro de Conexão");
|
|
}
|
|
else
|
|
{
|
|
string Json = www.downloadHandler.text;
|
|
FeelingsResponse feelings = JsonUtility.FromJson<FeelingsResponse>(Json);
|
|
|
|
if (feelings.status == 200)
|
|
{
|
|
ListaFeelings = feelings.response;
|
|
}
|
|
}
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
|
|
public IEnumerator DownloadCharConvResources()
|
|
{
|
|
// BACKGROUND
|
|
string NomeFundo = "fundo";
|
|
string ExtFundo = ListaConversacao[0].backgroundExt;
|
|
yield return StartCoroutine(DownloadResource("backgrounds/" + ListaConversacao[0].idcharactersBackground + ExtFundo, NomeFundo + ExtFundo));
|
|
|
|
|
|
|
|
/* CHARACTERS FEELINGS
|
|
for (int i = 0; i < ListaFeelings.Count; i++)
|
|
{
|
|
string src1 = "characters/" + ListaConversacao[0].idcharacters_1 + "_" + ListaFeelings[i].idcharactersFeelings + CharacterExt;
|
|
string name1 = "Ch-" + ListaConversacao[0].idcharacters_1 + "_" + ListaFeelings[i].idcharactersFeelings;
|
|
yield return StartCoroutine(DownloadResource(src1, "VideoFile" + name1 + CharacterExt));
|
|
|
|
string src2 = "characters/" + ListaConversacao[1].idcharacters_2 + "_" + ListaFeelings[i].idcharactersFeelings + CharacterExt;
|
|
string name2 = "Ch-" + ListaConversacao[1].idcharacters_2 + "_" + ListaFeelings[i].idcharactersFeelings;
|
|
yield return StartCoroutine(DownloadResource(src2, "VideoFile" + name2 + CharacterExt));
|
|
}*/
|
|
|
|
// AUDIOS
|
|
for (int i = 0; i < ListaConversacao.Count; i++)
|
|
{
|
|
string Ext = AudioExt;
|
|
string NomeArq = "FileAudio_" + i + Ext;
|
|
yield return StartCoroutine(DownloadResource("audios/" + ListaConversacao[i].idcharactersConversation + "_" + i + Ext, NomeArq));
|
|
}
|
|
|
|
// BALOES
|
|
for (int i = 0; i < ListaConversacao.Count; i++)
|
|
{
|
|
string Ext = ListaConversacao[i].baloonExt;
|
|
string NomeArq = "FileImage_Bl-" + ListaConversacao[i].idcharactersBaloons + Ext;
|
|
yield return StartCoroutine(DownloadResource("baloons/" + ListaConversacao[i].idcharactersBaloons + Ext, NomeArq, false));
|
|
}
|
|
|
|
// TRANSICOES
|
|
for (int i = 0; i < ListaConversacao.Count; i++)
|
|
{
|
|
string Ext = ListaConversacao[i].transitionExt;
|
|
string src = "transitions/" + ListaConversacao[i].idcharactersTransitions + Ext;
|
|
string name = "Ts-" + ListaConversacao[i].idcharactersTransitions;
|
|
yield return StartCoroutine(DownloadResource(src, "VideoFile" + name + Ext));
|
|
}
|
|
|
|
|
|
yield break;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
IEnumerator ActuallyDownloadFile(string publishid, int idmedia, int indexLog)
|
|
{
|
|
publishid = publishid.Replace("/videos/", "");
|
|
publishid = publishid.Replace("/video/", "");
|
|
Debug.Log("DOWNLOAD VIDEO");
|
|
string path = "http://" + ReadingFile.iploc + ":3337/api/videos/backVideo/" + publishid + "/0";
|
|
|
|
/*using (UnityWebRequest www = UnityWebRequest.Get(path))
|
|
{
|
|
www.certificateHandler = new BypassCertificate();
|
|
www.downloadHandler = new DownloadHandlerBuffer();
|
|
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isHttpError || www.isNetworkError)
|
|
{
|
|
Debug.LogError("Erro de conexão : DownloadFile : " + www.error);
|
|
}
|
|
else if (www.downloadHandler.text == "true")
|
|
{
|
|
string videoPath = "http://18.228.91.135/videos/tmp/var/www/html/videos/" + publishid + ".mp4";
|
|
UnityWebRequest wwwVideo = UnityWebRequest.Get(videoPath);
|
|
yield return wwwVideo.SendWebRequest();
|
|
|
|
if (wwwVideo.error != null)
|
|
{
|
|
Debug.LogError("Erro ao baixar o vídeo: " + wwwVideo.error);
|
|
}
|
|
else
|
|
{
|
|
string savepath = Path.Combine(Application.persistentDataPath, "videoFile_" + idmedia + ".mp4");
|
|
|
|
if (File.Exists(savepath))
|
|
{
|
|
File.Delete(savepath);
|
|
}
|
|
|
|
File.WriteAllBytes(savepath, wwwVideo.downloadHandler.data);
|
|
|
|
// Supondo que downloadLogs seja uma lista de algum tipo de estrutura que você está usando
|
|
downloadLogs[indexLog].state = true;
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
}
|
|
}*/
|
|
|
|
downloadLogs[indexLog].state = true;
|
|
|
|
yield break;
|
|
}
|
|
|
|
public bool hasDownloadedVideo(string publishID)
|
|
{
|
|
bool downloaded = false;
|
|
|
|
foreach (DownloadLogs item in downloadLogs)
|
|
{
|
|
if (item.name == publishID)
|
|
{
|
|
downloaded = item.state;
|
|
}
|
|
}
|
|
|
|
return downloaded;
|
|
}
|
|
|
|
public IEnumerator DownloadFile(string publishid, int idmedia)
|
|
{
|
|
//Debug.Log("Downloading " + publishid);
|
|
DownloadLogs downloadLog = new DownloadLogs();
|
|
downloadLog.name = publishid;
|
|
downloadLog.state = false;
|
|
|
|
downloadLogs.Add(downloadLog);
|
|
|
|
int indexThis = downloadLogs.Count - 1;
|
|
|
|
Coroutine corDownloadFile = StartCoroutine(ActuallyDownloadFile(publishid, idmedia, indexThis));
|
|
|
|
float time = 0;
|
|
|
|
while (!hasDownloadedVideo(publishid))
|
|
{
|
|
time += Time.deltaTime;
|
|
|
|
if (time > 10 && !hasDownloadedVideo(publishid))
|
|
{
|
|
general.weakConnection = true;
|
|
general.CheckLoadScreenNConnection();
|
|
}
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
//Debug.Log("Done Download " + publishid);
|
|
yield break;
|
|
}
|
|
}
|