chicken_dy/Assets/Scripts/UI/CustomControl/LevelPage/LevelPage.cs

136 lines
3.6 KiB
C#
Raw Normal View History

2022-02-13 09:36:12 +00:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LevelPage : PageView
{
public Action<int> DelClickLevel;
2022-02-15 05:23:07 +00:00
[SerializeField] GameObject mGobLeftArrow;
[SerializeField] GameObject mGobRightArrow;
private int mCurrentIndex = -1;
2022-02-15 05:23:07 +00:00
protected override void AwakeInit()
2022-02-14 09:14:06 +00:00
{
OnScrollPage = PlayScrollPage;
OnReachEdge = PlayReachEdge;
2022-02-15 05:23:07 +00:00
OnPageChanged = PageChanged;
2022-02-14 09:14:06 +00:00
}
protected override void BeforeLoad()
{
mCurrentIndex = PlayerData.Instance.CurrentLevel - 1;
}
2022-02-16 04:11:28 +00:00
public LevelCell GetCell(int pIndex)
{
return mCellList[pIndex].GetComponent<LevelCell>();
}
2022-02-13 09:36:12 +00:00
public override int Count
{
get
{
2022-02-13 09:50:39 +00:00
int tTotalCount = GameConfig.Instance.LevelSort.Count + 1;//add coming soon
2022-02-14 04:44:49 +00:00
int tUnlockedCount = PlayerData.Instance.UnlockedLevel;
2022-04-01 14:07:21 +00:00
int tEnoughCount = (tUnlockedCount / CountPerPage + 1) * CountPerPage;//add next to unlock
2022-02-13 09:50:39 +00:00
return Mathf.Min(tTotalCount, tEnoughCount);
2022-02-13 09:36:12 +00:00
}
}
protected override void ConfigCell(GameObject pCellGob, int pIndex)
{
LevelCell tCell = pCellGob.GetComponent<LevelCell>();
if (pIndex < PlayerData.Instance.UnlockedLevel)
{
tCell.Init(pIndex);
tCell.ShowCurrent(pIndex == mCurrentIndex);
2022-02-13 09:36:12 +00:00
tCell.DelClick = OnClickLevel;
2022-08-03 08:14:00 +00:00
tCell.DelShareClick = OnClickLevel;
2022-02-13 09:36:12 +00:00
}
else
{
2022-02-13 09:50:39 +00:00
if (pIndex < GameConfig.Instance.LevelSort.Count)
2022-02-13 09:36:12 +00:00
{
2022-04-01 14:07:21 +00:00
if (pIndex == PlayerData.Instance.UnlockedLevel)
{
tCell.SetUnlock();
tCell.DelClick = OnClickUnlockLevel;
2022-08-03 08:14:00 +00:00
tCell.DelShareClick = OnClickShareUnlockLevel;
2022-05-31 15:14:44 +00:00
2022-07-27 02:30:05 +00:00
//TKGSDKManager.Instance.LogRewardAdBtnShow(Const.AdsEvtValue.UnlockLevel);
2022-04-01 14:07:21 +00:00
}
else
{
tCell.SetEmpty();
}
2022-02-13 09:36:12 +00:00
}
else
{
tCell.SetComingSoon();
}
}
}
private void OnClickLevel(int pLevelIndex)
{
if (mCurrentIndex >= 0)
{
mCellList[mCurrentIndex].GetComponent<LevelCell>().ShowCurrent(false);
}
mCurrentIndex = pLevelIndex;
mCellList[mCurrentIndex].GetComponent<LevelCell>().ShowCurrent(true);
2022-02-13 09:36:12 +00:00
DelClickLevel?.Invoke(pLevelIndex);
}
2022-02-14 09:14:06 +00:00
2022-04-01 14:07:21 +00:00
private void OnClickUnlockLevel(int pLevelIndex)
{
TKGSDKManager.Instance.ShowRewardAd(TKGRVPositionName.RV_level_unlock, (pResult) =>
{
if (pResult)
{
PlayerData.Instance.UnlockNewLevel(false);
LoadData(true);
}
});
2022-07-27 02:30:05 +00:00
PlayerData.Instance.UnlockNewLevel(false);
LoadData(true);
2022-04-01 14:07:21 +00:00
}
2022-08-03 08:14:00 +00:00
private void OnClickShareUnlockLevel(int pLevelIndex)
{
TKGSDKManager.Instance.ShareShareAppMessageByType(TKGSDKManager.ShareType.ShareAppFixedImg);
Invoke("RewardSucc", 0.5f);
}
private void RewardSucc()
{
PlayerData.Instance.UnlockNewLevel(false);
LoadData(true);
}
2022-02-15 05:23:07 +00:00
private void PageChanged(int pPageIndex)
{
mGobLeftArrow.SetActive(pPageIndex > 0);
mGobRightArrow.SetActive(pPageIndex < PageCount - 1);
}
2022-02-14 09:14:06 +00:00
private void PlayScrollPage()
{
AudioManager.Instance.PlaySound(AudioClipType.TurnPage, 0.7f);
2022-02-14 09:14:06 +00:00
}
private void PlayReachEdge()
{
AudioManager.Instance.PlaySound(AudioClipType.ReachEdge, 0.7f);
2022-02-14 09:14:06 +00:00
}
2022-02-13 09:36:12 +00:00
}