69 lines
1.8 KiB
C#
69 lines
1.8 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UI;
|
|
|
|
public class StudentDataUI : MonoBehaviour
|
|
{
|
|
public Text studentName;
|
|
public Text examChapter;
|
|
public Text timeLeft;
|
|
public Image headImage;
|
|
|
|
public Sprite headSpriteDefault;
|
|
public Sprite headSpriteTemp;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
public IEnumerator UpdateStudentData(string name, string examChapter, string timeLeft, string spriteUrl)
|
|
{
|
|
this.studentName.text = name;
|
|
this.examChapter.text = examChapter;
|
|
this.timeLeft.text = timeLeft;
|
|
this.headImage.sprite = headSpriteDefault;
|
|
if (spriteUrl != null && spriteUrl != "null" && spriteUrl != "")
|
|
{
|
|
yield return GetSpriteFromUrl(spriteUrl);
|
|
headImage.sprite = headSpriteTemp;
|
|
}
|
|
|
|
}
|
|
|
|
public void UpdateLeftTime(string timeLeft)
|
|
{
|
|
this.timeLeft.text = timeLeft;
|
|
}
|
|
|
|
|
|
public IEnumerator GetSpriteFromUrl(string url)
|
|
{
|
|
headSpriteTemp = null;
|
|
UnityWebRequest request = UnityWebRequestTexture.GetTexture(url);
|
|
|
|
yield return request.SendWebRequest();
|
|
|
|
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError || request.responseCode == 0)
|
|
{
|
|
Debug.Log(request.error);
|
|
}
|
|
else
|
|
{
|
|
Texture2D webTexture = ((DownloadHandlerTexture)request.downloadHandler).texture as Texture2D;
|
|
headSpriteTemp = Sprite.Create(webTexture, new Rect(0.0f, 0.0f, webTexture.width, webTexture.height), new Vector2(0.5f, 0.5f), 100.0f);
|
|
}
|
|
}
|
|
|
|
}
|