144 lines
4.1 KiB
C#
144 lines
4.1 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using UnityEngine.Networking;
|
||
using TMPro;
|
||
using System;
|
||
using Unity.VisualScripting;
|
||
|
||
public class UIPeopleProgress : UIBase
|
||
{
|
||
private RowsItem currentItem;
|
||
|
||
public Image bg;
|
||
public Image head;
|
||
public TextMeshProUGUI nameTxt;
|
||
public TextMeshProUGUI descriptionTxt;
|
||
public Button close;
|
||
public TextMeshProUGUI hintTxt;
|
||
|
||
public Image progressImg;
|
||
public TextMeshProUGUI progressTxt;
|
||
public Button resetBtn;
|
||
public TextMeshProUGUI progressHintTxt;
|
||
|
||
string imgurl;
|
||
|
||
public Transform content;
|
||
|
||
public List<UIProgressItem> listP;
|
||
|
||
|
||
public List<DataItem> currentData;
|
||
|
||
private void Awake()
|
||
{
|
||
currentItem = DataManager.Instance.currentSelectPeople;
|
||
|
||
close.onClick.AddListener(DestroyThisUI);
|
||
|
||
EventCenter.dispatcher.AddListener(MsgType.OnGetCurrentPeopleProgress, OnGetCurrentData);
|
||
|
||
GetPeopleInfo();
|
||
}
|
||
|
||
private void DestroyThisUI()
|
||
{
|
||
UIManager.Instance.DestoryUI(UIType.UIPeopleProgress);
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
EventCenter.dispatcher.RemoveListener(MsgType.OnGetCurrentPeopleProgress, OnGetCurrentData);
|
||
}
|
||
|
||
public void SetProgress()
|
||
{
|
||
float p = 1;
|
||
progressImg.fillAmount = p;
|
||
progressTxt.text = p * 100 + "%";
|
||
}
|
||
|
||
private void OnGetCurrentData(Message evt)
|
||
{
|
||
imgurl = currentItem.image;
|
||
nameTxt.text = currentItem.name + "-" + currentItem.specialty;
|
||
descriptionTxt.text = currentItem.languageType;
|
||
currentData = DataManager.Instance.currentPeoplesProgress;
|
||
SetProgress();
|
||
StartCoroutine(DownSprite());
|
||
|
||
if (currentData != null)
|
||
{
|
||
listP = new List<UIProgressItem>();
|
||
GameObject Prefab = (GameObject)Resources.Load("UIPrefabs/UIProgressItem");
|
||
for (int i = 0; i < currentData.Count; i++)
|
||
{
|
||
UIProgressItem item = Instantiate(Prefab, content).GetComponent<UIProgressItem>();
|
||
listP.Add(item);
|
||
if (i == 0)
|
||
{
|
||
item.CloseBG();
|
||
}
|
||
}
|
||
for (int i = 0; i < currentData.Count; i++)
|
||
{
|
||
listP[i].SetTitle(currentData[i].title);
|
||
listP[i].SetData(currentData[i]);
|
||
}
|
||
}
|
||
}
|
||
|
||
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;
|
||
//<2F><><EFBFBD>汾<EFBFBD><E6B1BE>
|
||
//Byte[] bytes = tex.EncodeToPNG();
|
||
//File.WriteAllBytes(Application.dataPath + "/" + data.name + ".png", bytes);
|
||
|
||
Sprite sprite = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
|
||
bg.sprite = sprite;
|
||
head.sprite = sprite;
|
||
//transform.GetComponent<Image>().sprite = sprite;
|
||
}
|
||
}
|
||
|
||
public void GetPeopleInfo()
|
||
{
|
||
string url = "http://122.112.171.137:85/api/diagnosis/info/list?casesId=" + currentItem.id;
|
||
StartCoroutine(Get(url));
|
||
}
|
||
|
||
IEnumerator Get(string url)
|
||
{
|
||
UnityWebRequest request = UnityWebRequest.Get(url);
|
||
yield return request.SendWebRequest();
|
||
if (request.isHttpError || request.isNetworkError)
|
||
{
|
||
Debug.LogError(request.error);
|
||
}
|
||
else
|
||
{
|
||
string receiveContent = request.downloadHandler.text;
|
||
byte[] datas = Encoding.UTF8.GetBytes(receiveContent);
|
||
receiveContent = Encoding.UTF8.GetString(datas, 0, datas.Length);
|
||
//JsonInfo jsonInfo = JsonMapper.ToObject<JsonInfo>(receiveContent);
|
||
DataParse.Instance.ParsePeopleList(receiveContent);
|
||
|
||
}
|
||
}
|
||
|
||
|
||
}
|