using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; 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; 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); CaseData[] _case_item_datas = jo["data"].ToObject(); 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); } } else { Debug.LogError(result); } })); } /// /// 案例中心返回 /// public void OnCaseCenterBack() { OnNagetive(true); } }