85 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			85 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C#
		
	
	
	
| 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<TabButton> mTabs;
 | |
|     private List<CardCell> mHumanCells;
 | |
|     private List<CardCell> mMonsterCells;
 | |
| 
 | |
|     private int mCurIndex = -1;
 | |
| 
 | |
|     private void Awake()
 | |
|     {
 | |
|         UIUtils.BindBtn(mBtnClose, Close);
 | |
| 
 | |
|         mTabs = Utils.GetChildListFirstLayer<TabButton>(mCtnTabs);
 | |
|         mHumanCells = Utils.GetChildListFirstLayer<CardCell>(mCtnHuman);
 | |
|         mMonsterCells = Utils.GetChildListFirstLayer<CardCell>(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);
 | |
|         }
 | |
|     }
 | |
| } |