YiHe_AllVersion/YHWeb/Assets/YHElectric/Scripts/UIPanel/DevInfoPanel.cs

110 lines
3.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XFrame.Core.UI;
using XFrame.Core.Tool;
using UnityEngine.UI;
using DG.Tweening;
namespace YHElectric
{
public class DevInfoPanel : XUIPanel
{
Transform bg;
Transform basicInfo;
Transform chartInfo;
public DevInfoPanel():base(UIType.PopUp,UIMode.None,UICollider.None)
{
uiPath = "UI/UIPanelPrefab/DevInfoPanel";
}
public override void Awake(GameObject go)
{
bg = transform.Find("BG");
basicInfo = transform.Find("BG/BasicInfo");
chartInfo= transform.Find("BG/ChartInfo");
transform.Find("BG/closeBtn").GetComponent<Button>().onClick.AddListener(Hide);
}
public override void Active()
{
base.Active();
OnEnter();
}
void OnEnter()
{
bg.transform.localScale = Vector3.zero;
this.gameObject.SetActive(true);
bg.DOScale(Vector3.one, 0.4f).SetEase(Ease.InOutQuad);
//GameManager.jsonDataName = "Workshop";
//LoadJsonData(GameManager.jsonDataName);
}
public override void Hide()
{
ClearPanel();
ClosePanel<MaskPanel>();
ClosePanel<ModelPanel>();
bg.DOScale(Vector3.zero, 0.3f).SetEase(Ease.InOutQuad).OnComplete(() => base.Hide());
}
void LoadJsonData(string fileName)
{
TextAsset ta = Resources.Load("Data/"+fileName) as TextAsset;
LitJson.JsonData jd = JsonParser.GetJson(ta.text);
IDictionary dictJD = jd as IDictionary;
foreach (string key in dictJD.Keys)
{
Debug.Log(key + " : " + dictJD[key].ToString() + "\n");
}
for (int i=0;i<jd.Count;i++)
{
IDictionary dict = jd[i] as IDictionary;
foreach (string key in dict.Keys)
{
if (i == 0) {
CreatElement("FieldPrefab",key, basicInfo);
CreatElement("FieldPrefab",dict[key].ToString(), basicInfo);
}
if (i == 1)
{
CreatElement("DevicePrefab",key,chartInfo.GetChild(0));
}
if (i == 2)
{
CreatElement("TabPrefab", key, chartInfo.GetChild(1));
}
Debug.Log(key + " : " + dict[key].ToString() + "\n");
}
}
}
/// <summary>
/// 创建UI元素
/// </summary>
/// <param name="path"></param>
/// <param name="value"></param>
/// <param name="parent"></param>
void CreatElement(string path,string value,Transform parent)
{
GameObject go = GameObject.Instantiate(Resources.Load("UI/UIElement/"+ path),Vector3.zero,Quaternion.identity)as GameObject;
go.transform.SetParent(parent);
go.transform.GetChild(0).GetComponent<Text>().text = value;
go.transform.localScale = Vector3.one;
}
/// <summary>
/// 清空面板
/// </summary>
public void ClearPanel()
{
for (int i=0;i< basicInfo.childCount;i++)
{
GameObject.Destroy(basicInfo.GetChild(i).gameObject);
}
for (int i = 0; i < chartInfo.GetChild(0).childCount; i++)
{
GameObject.Destroy(chartInfo.GetChild(0).GetChild(i).gameObject);
}
for (int i = 0; i < chartInfo.GetChild(1).childCount; i++)
{
GameObject.Destroy(chartInfo.GetChild(1).GetChild(i).gameObject);
}
}
}
}