using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class LevelPage : PageView { public Action DelClickLevel; [SerializeField] GameObject mGobLeftArrow; [SerializeField] GameObject mGobRightArrow; private int mCurrentIndex = -1; protected override void AwakeInit() { OnScrollPage = PlayScrollPage; OnReachEdge = PlayReachEdge; OnPageChanged = PageChanged; } protected override void BeforeLoad() { mCurrentIndex = PlayerData.Instance.CurrentLevel - 1; } public LevelCell GetCell(int pIndex) { return mCellList[pIndex].GetComponent(); } public override int Count { get { int tTotalCount = GameConfig.Instance.LevelSort.Count + 1;//add coming soon int tUnlockedCount = PlayerData.Instance.UnlockedLevel; int tEnoughCount = (tUnlockedCount / CountPerPage + 1) * CountPerPage;//add next to unlock return Mathf.Min(tTotalCount, tEnoughCount); } } protected override void ConfigCell(GameObject pCellGob, int pIndex) { LevelCell tCell = pCellGob.GetComponent(); if (pIndex < PlayerData.Instance.UnlockedLevel) { tCell.Init(pIndex); tCell.ShowCurrent(pIndex == mCurrentIndex); tCell.DelClick = OnClickLevel; } else { if (pIndex < GameConfig.Instance.LevelSort.Count) { if (pIndex == PlayerData.Instance.UnlockedLevel) { tCell.SetUnlock(); tCell.DelClick = OnClickUnlockLevel; TKGSDKManager.Instance.LogRewardAdBtnShow(Const.AdsEvtValue.UnlockLevel); } else { tCell.SetEmpty(); } } else { tCell.SetComingSoon(); } } } private void OnClickLevel(int pLevelIndex) { if (mCurrentIndex >= 0) { mCellList[mCurrentIndex].GetComponent().ShowCurrent(false); } mCurrentIndex = pLevelIndex; mCellList[mCurrentIndex].GetComponent().ShowCurrent(true); DelClickLevel?.Invoke(pLevelIndex); } private void OnClickUnlockLevel(int pLevelIndex) { TKGSDKManager.Instance.PlayRewardAd(Const.AdsEvtValue.UnlockLevel, (pResult) => { if (pResult) { PlayerData.Instance.UnlockNewLevel(false); LoadData(true); } }); } private void PageChanged(int pPageIndex) { mGobLeftArrow.SetActive(pPageIndex > 0); mGobRightArrow.SetActive(pPageIndex < PageCount - 1); } private void PlayScrollPage() { AudioManager.Instance.PlaySound(AudioClipType.TurnPage, 0.7f); } private void PlayReachEdge() { AudioManager.Instance.PlaySound(AudioClipType.ReachEdge, 0.7f); } }