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

91 lines
2.3 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-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;
int tEnoughCount = ((tUnlockedCount - 1) / CountPerPage + 1) * CountPerPage;
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;
}
else
{
2022-02-13 09:50:39 +00:00
if (pIndex < GameConfig.Instance.LevelSort.Count)
2022-02-13 09:36:12 +00:00
{
tCell.SetEmpty();
}
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-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()
{
2022-02-15 07:54:40 +00:00
AudioManager.Instance.PlaySound(AudioType.TurnPage, 0.7f);
2022-02-14 09:14:06 +00:00
}
private void PlayReachEdge()
{
2022-02-15 07:54:40 +00:00
AudioManager.Instance.PlaySound(AudioType.ReachEdge, 0.7f);
2022-02-14 09:14:06 +00:00
}
2022-02-13 09:36:12 +00:00
}