ZoeAppClass/Assets/Scripts/Class/QuestionGlobals/Enunciado.cs

98 lines
2.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Enunciado : MonoBehaviour
{
public void ChangeText(string txtstr)
{
string newtxt = GlobalClasses.TratarTexto(txtstr);
TextMeshPro txt = GetComponent<TextMeshPro>();
txt.text = newtxt;
}
public void NoImage(string txtEnunciado, Color setColor, bool teacher, bool anime) {
string newtxt = GlobalClasses.TratarTexto(txtEnunciado);
TextMeshPro txt = GetComponent<TextMeshPro>();
txt.text = newtxt;
if (teacher)
{
txt.color = new Color(0, 0, 0, 1);
}
else
{
txt.color = setColor;
}
if (!anime)
{
GameObject objToDestroy = transform.parent.transform.Find("ImgSentence").gameObject;
Destroy(objToDestroy);
Destroy(transform.parent.transform.Find("AllignWhenTheresImage").gameObject);
}
}
public void WithImage(string txtEnunciado, Color setColor, string ip, bool teacher)
{
string newtxt = GlobalClasses.TratarTexto(txtEnunciado);
TextMeshPro txt = GetComponent<TextMeshPro>();
txt.text = newtxt;
if (teacher)
{
txt.color = new Color(0, 0, 0, 1);
}
else
{
txt.color = setColor;
}
List<RectTransform> rectsToChange = new List<RectTransform>()
{
transform.parent.transform.Find("AllignOptionsImg").GetComponent<RectTransform>(),
transform.parent.transform.Find("AllignOptions").GetComponent<RectTransform>()
};
RectTransform rectBase = transform.parent.transform.Find("AllignWhenTheresImage").GetComponent<RectTransform>();
foreach (RectTransform item in rectsToChange)
{
item.anchoredPosition = rectBase.anchoredPosition;
item.anchorMax = rectBase.anchorMax;
item.anchorMin = rectBase.anchorMin;
}
Destroy(rectBase.gameObject);
StartCoroutine(downloadImagee(ip));
}
IEnumerator downloadImagee(string ip) {
yield return new WaitForFixedUpdate();
yield return StartCoroutine(DownloadImage(ip));
}
IEnumerator DownloadImage(string id)
{
string url = id;
Image image = transform.parent.transform.Find("ImgSentence").GetComponent<Image>();
using (WWW www = new WWW(url))
{
yield return www;
image.sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height),
new Vector2(0, 0));
}
}
}