ISAP/Assets/Scripts/UI/UIClickBody.cs

337 lines
11 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class UIClickBody : UIBase
{
public Button btn;
public Transform currentModel;
public Transform morePanel;
public Button moreBtn;
public Transform morePanel2;
BodyInfoDataItem currentData;
//Dictionary<int,>
List<GameObject> moreBtns;
List<GameObject> moreBtns2;
List<GameObject> posBtns;
public Transform posParent;
private void Awake()
{
var allModel = DataManager.Instance.GetGameData().allModel;
for (int i = 0; i < allModel.Length; i++)
{
if (allModel[i].gameObject.activeSelf)
{
currentModel = allModel[i].transform;
}
}
moreBtns = new List<GameObject>();
moreBtns2 = new List<GameObject>();
posBtns = new List<GameObject>();
moreBtns.Clear();
moreBtns2.Clear();
posBtns.Clear();
EventCenter.dispatcher.AddListener(MsgType.OnGetBodyInfo, OnGetBodyInfo);
EventCenter.dispatcher.AddListener(MsgType.OnGetBodyPosInfo, OnGetBodyPosInfo);
Refrush();
AddCheckQuestionToQuitList();
}
private void AddCheckQuestionToQuitList()
{
int diagnosisID = DataManager.Instance.currentData.id;
string url = "http://122.112.171.137:85/api/problem/answer/getClinicalProblem/" + diagnosisID;
StartCoroutine(GetCheckQuesiton(url));
}
public void Refrush()
{
int checkType = (int)DataManager.Instance.currentCheckTool;
int styleType = (int)DataManager.Instance.currentPeopleStyle;
int diagnosisID = DataManager.Instance.currentData.id;
string url = string.Format("http://122.112.171.137:85/api/diagnosis/clinical/getClinicalCheckResult?checkType={0}&diagnosisId={1}&postureId={2}", checkType, diagnosisID, styleType);
morePanel.gameObject.SetActive(false);
StartCoroutine(GetBodyPos(url));
}
private void OnDestroy()
{
EventCenter.dispatcher.RemoveListener(MsgType.OnGetBodyInfo, OnGetBodyInfo);
EventCenter.dispatcher.RemoveListener(MsgType.OnGetBodyPosInfo, OnGetBodyPosInfo);
}
private void OnGetBodyPosInfo(Message evt)
{
var list = DataManager.Instance.bodyPosInfos;
List<FileInfoData> listData = new List<FileInfoData>();
for (int i = 0; i < list.Count; i++)
{
var item = list[i];
FileInfoData data = new FileInfoData();
data.type = (FileType)item.type;
data.content = item.content;
data.url = item.fileUrl;
data.question = item.problemInfoResp;
listData.Add(data);
}
UIBase ui = UIManager.Instance.OpenUI(UIType.UIFile);
UIFile fileui = (UIFile)ui;
fileui.Init(listData);
//switch (item.type)
//{
// case 1:
// //<2F>ı<EFBFBD>
// //fileui.Init(FileType.text,FileFather.BodyInfo);
// break;
// case 2:
// //ͼƬ
// //fileui.Init(FileType.image, FileFather.BodyInfo);
// break;
// case 3:
// //<2F><>Ƶ
// //fileui.Init(FileType.video, FileFather.BodyInfo);
// break;
// case 4:
// //<2F><><EFBFBD><EFBFBD>
// //fileui.Init(FileType.music, FileFather.BodyInfo);
// break;
// case 5:
// //<2F><><EFBFBD><EFBFBD>
// //fileui.Init(FileType.URL, FileFather.BodyInfo);
// break;
//}
}
//չʾ<D5B9><CABE>λ<EFBFBD><CEBB>ť
private void OnGetBodyInfo(Message evt)
{
for (int i = 0; i < posBtns.Count; i++)
{
GameObject.Destroy(posBtns[i].gameObject);
}
var data = DataManager.Instance.bodyInfoData;
foreach (var item in data)
{
GameObject root = GetCurrentPos(item.positionId);
var newUI = GameObject.Instantiate(btn, posParent);
posBtns.Add(newUI.gameObject);
if (root != null)
{
Vector2 player2DPosition = Camera.main.WorldToScreenPoint(root.transform.position);
newUI.transform.position = player2DPosition;
newUI.gameObject.SetActive(true);
newUI.onClick.AddListener(() =>
{
ClearBtnsList();
morePanel.transform.position = newUI.transform.position + new Vector3(170f, 0f);
morePanel.gameObject.SetActive(true);
//int x = i;
//currentData = data[x];
ShowMorePanel(data.IndexOf(item));
});
}
}
}
void ClearBtnsList()
{
for (int i = 0; i < moreBtns.Count; i++)
{
GameObject.Destroy(moreBtns[i].gameObject);
}
for (int i = 0; i < moreBtns2.Count; i++)
{
GameObject.Destroy(moreBtns2[i].gameObject);
}
}
//һ<><D2BB><EFBFBD>˵<EFBFBD>
void ShowMorePanel(int index)
{
var data = DataManager.Instance.bodyInfoData;
var list = data[index].clinicalProjectPositionRespList;
foreach (var item in list)
{
Button newUI = GameObject.Instantiate(moreBtn, morePanel);
newUI.transform.Find("txt").GetComponent<TextMeshProUGUI>().text = item.toolName;
newUI.gameObject.SetActive(true);
newUI.onClick.AddListener(() =>
{
for (int i = 0; i < moreBtns2.Count; i++)
{
GameObject.Destroy(moreBtns2[i].gameObject);
}
morePanel2.transform.position = newUI.transform.position + new Vector3(320f, -20f);
if (!morePanel2.gameObject.activeSelf)
{
morePanel2.gameObject.SetActive(true);
ShowMorePane2(index, list.IndexOf(item));
}
});
moreBtns.Add(newUI.gameObject);
}
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD>
void ShowMorePane2(int index, int index2)
{
var data = DataManager.Instance.bodyInfoData;
var list = data[index].clinicalProjectPositionRespList[index2].clinicalProjectCheckRespList;
foreach (var item in list)
{
Button newUI = GameObject.Instantiate(moreBtn, morePanel2);
newUI.transform.Find("txt").GetComponent<TextMeshProUGUI>().text = item.checkName;
newUI.gameObject.SetActive(true);
newUI.onClick.AddListener(() =>
{
morePanel2.transform.position = newUI.transform.position + new Vector3(50f, 0f);
morePanel.gameObject.SetActive(false);
morePanel2.gameObject.SetActive(false);
ShowTwiceMenuInfo(item);
//ShowMorePanel(data.IndexOf(item));
});
moreBtns2.Add(newUI.gameObject);
}
}
void ShowTwiceMenuInfo(ClinicalProjectCheckRespListItem data)
{
//http://122.112.171.137:85/api/diagnosis/clinical/getClinicalInfo/{projectId}
string url = "http://122.112.171.137:85/api/diagnosis/clinical/getClinicalInfo/" + data.projectId;
StartCoroutine(ShowPosInfo(url));
}
IEnumerator ShowPosInfo(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.ParseBodyPosInfo(receiveContent);
}
}
GameObject GetCurrentPos(int id)
{
//currentModel
string name = "";
if (id == 1001 || id == 3001)
{
name = "<22><>״<EFBFBD><D7B4>";
}
else if (id == 1002 || id == 2002 || id == 3002 || id == 4001)
{
name = "<22>ز<EFBFBD>";
}
else if (id == 1003 || id == 2003 || id == 3003 || id == 4002)
{
name = "<22><>֫";
}
else if (id == 1004 || id == 2004 || id == 3004 || id == 4003)
{
name = "<22><><EFBFBD><EFBFBD>";
}
else if (id == 1005 || id == 3005 || id == 4004)
{
name = "<22>鷿";
}
else if (id == 1006 || id == 3006)
{
name = "<22><>֫";
}
else if (id == 1007 || id == 3007 || id == 4006)
{
name = "<22><><EFBFBD><EFBFBD>";
}
else if (id == 1008 || id == 2005 || id == 3008 || id == 4007)
{
name = <><CDB7>";
}
else if (id == 2001)
{
name = "<22><><EFBFBD><EFBFBD>";
}
else if (id == 4005)
{
name = "<22>貿";
}
if (currentModel != null)
{
if (currentModel.Find(name).gameObject != null)
{
return currentModel.Find(name).gameObject;
}
return null;
}
else
{
return null;
}
}
IEnumerator GetCheckQuesiton(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.ParseCheckBodyQuestionToQuit(receiveContent);
}
}
IEnumerator GetBodyPos(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.ParseBodyInfo(receiveContent);
}
}
}