69 lines
2.6 KiB
C#

/// <summary>
///********************************************************
/// 脚本功能:选择项目界面(StartState)
/// 创建人: GD
/// 创建时间: 2023/09/20 11:31
///********************************************************
/// </summary>
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using ZXKFramework;
namespace YiLiao.Main
{
public class ProjectPanel : UIBase
{
public override string GroupName => "ProjectPanel";
public override string Name => "ProjectPanel";
GameModel gameModel;
Transform container;
GameObject projectBtn;
Button loBtn;
List<Button> btns = new();
public override void Init(IUIManager uictrl)
{
base.Init(uictrl);
gameModel = MVC.GetModel<GameModel>();
container = transform.FindFirst<Transform>("Container");
projectBtn = transform.FindFirst<Transform>("ProjectBtn").gameObject;
foreach (MainData mainData in gameModel.excelData.allMainData)
{
if (!string.IsNullOrEmpty(mainData.name) && mainData.scene != "Main")
{
GameObject m = Instantiate(projectBtn, container);
m.SetActive(true);
m.transform.localScale = Vector3.one;
m.FindFirst<Text>("Text").text = mainData.name;
loBtn = m.GetComponent<Button>();
btns.Add(loBtn);
loBtn.onClick.RemoveAllListeners();
loBtn.onClick.AddListener(() =>
{
for (int i = 0; i < btns.Count; i++)
{
btns[i].transform.FindFirst<Image>("Select").gameObject.SetActive(false);
}
loBtn.transform.FindFirst<Image>("Select").gameObject.SetActive(true);
gameModel.mainData = mainData;
uiManager.GetUI<TitlePanel>().SetTitle(mainData.name);
Game.Instance.fsm.ChangeState<GamePatternState>();
});
Game.Instance.res.Load<Texture2D>(mainData.texture, t =>
{
loBtn.transform.FindFirst<Image>("Icon").sprite = UnityTools.ToSprite(t);
});
}
}
}
public override void Show()
{
base.Show();
for (int i = 0; i < btns.Count; i++)
{
btns[i].transform.FindFirst<Image>("Select").gameObject.SetActive(false);
}
}
}
}