using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class PanelBook : BasePanel { [SerializeField] Button mBtnClose; [SerializeField] Transform mCtnTabs; [SerializeField] GameObject[] mGobLists; [SerializeField] Transform mCtnHuman; [SerializeField] Transform mCtnMonster; private List mTabs; private List mHumanCells; private List mMonsterCells; private int mCurIndex = -1; private void Awake() { UIUtils.BindBtn(mBtnClose, Close); mTabs = Utils.GetChildListFirstLayer(mCtnTabs); mHumanCells = Utils.GetChildListFirstLayer(mCtnHuman); mMonsterCells = Utils.GetChildListFirstLayer(mCtnMonster); for (int i = 0; i < mTabs.Count; i++) { mTabs[i].DelClick = OnClickTab; } } public override void OnOpen() { base.OnOpen(); int tHumanIndex = 0, tMonsterIndex = 0; CardData tCard = null; for (int i = 0; i < GameConfig.Instance.CardList.Count; i++) { tCard = GameConfig.Instance.CardList[i]; if (Utils.IsHuman(tCard.CardID)) { if (tHumanIndex >= GameConfig.Instance.BlockMaxLevel) { mHumanCells[tHumanIndex].gameObject.SetActive(false); tHumanIndex++; continue; } mHumanCells[tHumanIndex].InitCell(tCard.CardID, !PlayerData.Instance.HasCard(tCard.CardID)); tHumanIndex++; } else if(Utils.IsMonster(tCard.CardID)) { if (tMonsterIndex >= GameConfig.Instance.BlockMaxLevel) { mMonsterCells[tMonsterIndex].gameObject.SetActive(false); tMonsterIndex++; continue; } mMonsterCells[tMonsterIndex].InitCell(tCard.CardID, !PlayerData.Instance.HasCard(tCard.CardID)); tMonsterIndex++; } } if (mCurIndex < 0) { OnClickTab(0); } } private void OnClickTab(int pIndex) { mCurIndex = pIndex; for (int i = 0; i < mTabs.Count; i++) { mTabs[i].SetOn(i == mCurIndex); mGobLists[i].SetActive(i == mCurIndex); } } }