ISAP/Assets/Scripts/UI/UIPeopleInfoItem.cs

131 lines
3.9 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class UIPeopleInfoItem : MonoBehaviour
{
public Image head;
public Image headBG;
public TextMeshProUGUI infoTxt;
public TextMeshProUGUI lauguage;
public Button beginBtn;
string imgurl;
string headurl;
private RowsItem data;
private StudentTestDataItem studentData;
private void Awake()
{
if (head == null)
{
Debug.LogError(this.gameObject.name + "Head is Null");
return;
}
if (infoTxt == null)
{
Debug.LogError(this.gameObject.name + "infoTxt is Null");
return;
}
if (beginBtn == null)
{
Debug.LogError(this.gameObject.name + "beginBtn is Null");
return;
}
}
public void Init(RowsItem item)
{
this.data = item;
head.sprite = Resources.Load<Sprite>("");
if (DataManager.Instance.showMode == ShowMode.PeopleTest)
{
infoTxt.text = data.name + "-" + data.specialty;
}
else if (DataManager.Instance.showMode == ShowMode.StudentTest)
{
infoTxt.text = data.name + "-" + data.specialty + "--" + "¿¼ÊÔѧÉúÐÕÃû";
}
lauguage.text = data.languageType;
imgurl = data.image;
StartCoroutine(DownSprite());
beginBtn.onClick.AddListener(OnClickBegin);
}
public void Init(StudentTestDataItem item)
{
this.studentData = item;
head.sprite = Resources.Load<Sprite>("");
infoTxt.text = studentData.projectName + "-" + studentData.roomCode + "-" + studentData.specialty + "-" + studentData.casesName;
lauguage.text = studentData.languageType;
imgurl = studentData.image;
StartCoroutine(DownSprite());
beginBtn.onClick.AddListener(OnClickBegin);
}
IEnumerator DownSprite()
{
UnityWebRequest wr = new UnityWebRequest(imgurl);
DownloadHandlerTexture texD1 = new DownloadHandlerTexture(true);
wr.downloadHandler = texD1;
yield return wr.SendWebRequest();
int width = 280;
int high = 100;
if (!wr.isNetworkError)
{
Texture2D tex = new Texture2D(width, high);
tex = texD1.texture;
//±£´æ±¾µØ
//Byte[] bytes = tex.EncodeToPNG();
//File.WriteAllBytes(Application.dataPath + "/" + data.name + ".png", bytes);
if (tex != null)
{
Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
headBG.sprite = sprite;
head.sprite = sprite;
}
//transform.GetComponent<Image>().sprite = sprite;
}
}
private void OnClickBegin()
{
//½øÈëÏÂÒ»¸ö½çÃæ
if (DataManager.Instance.showMode == ShowMode.PeopleTest)
{
DataManager.Instance.currentSelectPeople = data;
UIManager.Instance.OpenUI(UIType.UIPeopleProgress);
}
else if (DataManager.Instance.showMode == ShowMode.StudentTest)
{
var studentTestData = DataManager.Instance.currentSelectTest;
RowsItem temp = null;
if (studentTestData != null)
{
var allpeople = DataManager.Instance.peoples;
foreach (var people in allpeople)
{
if (people.id == studentTestData.casesId)
{
temp = people;
}
}
}
DataManager.Instance.currentSelectTest = studentData;
if (temp != null)
DataManager.Instance.currentSelectPeople = temp;
UIManager.Instance.OpenUI(UIType.UIChooseStudent);
}
}
}