using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using UnityEngineInternal;
using static InterfaceManager;
///
/// 案例中心面板
///
public class CaseCenterPanel : PanelBasic
{
public static CaseCenterPanel instance;
///
/// 实例root
///
Transform case_item_content;
///
/// 案例预制体
///
CaseItem case_item_prefab;
///
/// 案例中心返回按钮
///
Button case_center_back_button;
///
/// 案例列表
///
public List case_items = new List();
///
/// 案例详情面板
///
public CaseDetailPanel detailPanel;
///
/// 无人机_选中
///
public Sprite 无人机_选中;
///
/// 无人机_显示
///
public Sprite 无人机_显示;
///
/// 机器人_显示
///
public Sprite 机器人_显示;
///
/// 机器人_选中
///
public Sprite 机器人_选中;
///
/// 数字人_选中
///
public Sprite 数字人_选中;
///
/// 数字人_显示
///
public Sprite 数字人_显示;
protected override void Awake()
{
base.Awake();
instance = this;
}
protected override void OnEnable()
{
base.OnEnable();
Init();
}
void Init()
{
detailPanel.gameObject.SetActive(false);
case_center_back_button.onClick.AddListener(OnCaseCenterBack);
if (case_item_prefab == null) case_item_prefab = Resources.Load("Prefabs/UIItem/CaseItem");
//死的加载配置能文件
//StartCoroutine(Get(Path.Combine(Application.streamingAssetsPath, "LocalConfig/Cases.txt"), (_data) =>
//{
// var _case_item_datas = JsonConvert.DeserializeObject(_data);
// for (int i = 0; i < _case_item_datas.Length; i++)
// {
// var _case_item = Instantiate(case_item_prefab, case_item_content);
// _case_item.Init(_case_item_datas[i]);
// case_items.Add(_case_item);
// }
//}));
//清除item
case_items.ForEach(a =>
{
Destroy(a.gameObject);
});
case_items.Clear();
string url = InterfaceManager.IdAddress + ":8080/component/task/case/list?taskType=1";
StartCoroutine(InterfaceManager.Get(url, (isok, result) =>
{
if (isok)
{
JObject jo = JObject.Parse(result);
Debug.Log(jo);
CaseData[] _case_item_datas = jo["data"].ToObject();
for (int i = 0; i < _case_item_datas.Length; i++)
{
Debug.Log("加载了" + _case_item_datas[i].sceneName + "模块");
var _case_item = Instantiate(case_item_prefab, case_item_content);
//自己添加的修改显示图片的方法
switch (_case_item_datas[i].sceneName)
{
case "机器人舞台":
_case_item.GetComponent().Picture_显示 = 机器人_显示;
_case_item.GetComponent().Picture_选中 = 机器人_选中;
break;
case "深圳市民中心":
_case_item.GetComponent().Picture_显示 = 无人机_显示;
_case_item.GetComponent().Picture_选中 = 无人机_选中;
break;
case "数字人舞台":
_case_item.GetComponent().Picture_显示 = 数字人_显示;
_case_item.GetComponent().Picture_选中 = 数字人_选中;
break;
}
_case_item.Init(_case_item_datas[i]);
case_items.Add(_case_item);
}
}
else
{
Debug.LogError(result);
}
}));
}
///
/// 案例中心返回
///
public void OnCaseCenterBack()
{
OnNagetive(true);
}
}