CultivationOfBrewing/Assets/Scripts/UI/UIPanel/UI_StepsPanel.cs

127 lines
3.7 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.IO;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class UI_StepsPanel : BasePanel
{
/// <summary>
/// 步骤预制体父物体
/// </summary>
public RectTransform StepsContent;
/// <summary>
/// 步骤滑动条
/// </summary>
public ScrollRect scrollRect;
public UI_StepsPanelItem StepsItem;
public PptFilesData data = new PptFilesData();
public string jsonFileName = "StepsConfig"; // JSON文件名
protected override void Awake()
{
data = JsonManager.LoadData<PptFilesData>(jsonFileName);
foreach (var pptFile in data.pptFiles)
{
if (StepsItem == null || StepsContent == null)
{
Debug.LogError("按钮预制体或父对象未设置");
return;
}
// 实例化按钮
var item = Instantiate(StepsItem, StepsContent);
item.Init(pptFile.fileName);
var buttonText = item.GetComponentInChildren<TextMeshProUGUI>();
Button button = item.GetComponentInChildren<Button>();
button.name = pptFile.fileName;
if (buttonText != null)
{
buttonText.text = $"{pptFile.fileName}";
}
//if (button == null)
//{
// Debug.LogError("预制体上没有Button组件");
// return;
//}
// 设置按钮文本
}
base.Awake();
}
public override void ShowMe()
{
base.ShowMe();
}
public override void HideMe()
{
base.HideMe();
}
protected override async void OnClick(string btnName)
{
Debug.Log(btnName);
await LoadPPTTest.RefreshScrollView(StepsContent, scrollRect);
switch (btnName)
{
case "retrun_Btn":
Bootstrap.Instance.uiManager.ShowPanel<UI_StepsPanel>(this, E_UI_Layer.System, (panel) =>
{
Debug.Log("UI_StepsPanel已经显示在" + E_UI_Layer.System);
Bootstrap.Instance.uiManager.HidePanel<UI_TipsForPracticePanel>();
Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType., false);
});
break;
case "育苗前种子处理":
Debug.Log("育苗前种子处理");
CameraManager.instance.Camera.transform.SetPositionAndRotation
(CameraManager.instance.StepTrans[0].transform.position, CameraManager.instance.StepTrans[0].transform.rotation);
break;
case "播撒育苗技术流程":
Debug.Log("播撒育苗技术流程");
break;
case "精细整地要求":
Debug.Log("精细整地要求");
CameraManager.instance.Camera.transform.SetPositionAndRotation
(CameraManager.instance.StepTrans[1].transform.position, CameraManager.instance.StepTrans[1].transform.rotation);
Bootstrap.Instance.eventCenter.EventTrigger(Enum_EventType., true);
break;
case "苗龄与叶龄标准":
Debug.Log("育苗前种子处理");
break;
case "移栽时机和方式管理":
Debug.Log("移栽时机和方式管理");
break;
case "移栽后管理":
Debug.Log("移栽后管理");
break;
case "田间管理":
Debug.Log("田间管理");
break;
case "病虫害防治":
Debug.Log("病虫害防治");
break;
case "种子收货与储藏":
Debug.Log("种子收货与储藏");
break;
default:
break;
}
}
}