From fea27cdfd4abc3b3c2b267eafb2edcd3e7387546 Mon Sep 17 00:00:00 2001 From: yangjing Date: Mon, 14 Feb 2022 12:44:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=BB=E8=BE=91bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/CustomControl/LevelList/LevelPage.cs | 2 +- Assets/Scripts/UI/CustomControl/PageSpot.cs | 43 +++++++++++++++++-- Assets/Scripts/UI/PanelMain.cs | 2 +- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/UI/CustomControl/LevelList/LevelPage.cs b/Assets/Scripts/UI/CustomControl/LevelList/LevelPage.cs index 2bb7b88f..e2e8d66d 100644 --- a/Assets/Scripts/UI/CustomControl/LevelList/LevelPage.cs +++ b/Assets/Scripts/UI/CustomControl/LevelList/LevelPage.cs @@ -12,7 +12,7 @@ public class LevelPage : PageView get { int tTotalCount = GameConfig.Instance.LevelSort.Count + 1;//add coming soon - int tUnlockedCount = 23;// PlayerData.Instance.UnlockedLevel; + int tUnlockedCount = PlayerData.Instance.UnlockedLevel; int tEnoughCount = (tUnlockedCount / CountPerPage + 1) + (tUnlockedCount % CountPerPage == 0 ? -1 : 0); return Mathf.Min(tTotalCount, tEnoughCount * CountPerPage); diff --git a/Assets/Scripts/UI/CustomControl/PageSpot.cs b/Assets/Scripts/UI/CustomControl/PageSpot.cs index 7cdb1b74..47fd0fa1 100644 --- a/Assets/Scripts/UI/CustomControl/PageSpot.cs +++ b/Assets/Scripts/UI/CustomControl/PageSpot.cs @@ -8,6 +8,9 @@ public class PageSpot : MonoBehaviour private Transform mCtn; private List mLightSpots; + private List mSpotList; + + private int mSpotCount; private void Awake() { @@ -16,16 +19,16 @@ public class PageSpot : MonoBehaviour public void Init(int pTotalCount) { + mSpotCount = pTotalCount; mLightSpots = new List(); for (int i = 0; i < pTotalCount; i++) { - GameObject tSpot = Instantiate(mTplSpot, mCtn); - tSpot.SetActive(true); - tSpot.transform.localScale = Vector3.one; - + GameObject tSpot = GetSpot(i); mLightSpots.Add(tSpot.transform.GetChild(0).gameObject); } + + HideUnused(); } public void SetPageIndex(int pCurrentIndex) @@ -35,4 +38,36 @@ public class PageSpot : MonoBehaviour mLightSpots[i].SetActive(pCurrentIndex == i); } } + + private GameObject GetSpot(int pSpotIndex) + { + if (mSpotList == null) + { + mSpotList = new List(); + } + + GameObject tCell = null; + if (pSpotIndex < mSpotList.Count) + { + tCell = mSpotList[pSpotIndex]; + } + else + { + tCell = Instantiate(mTplSpot, mCtn); + tCell.transform.localScale = Vector3.one; + mSpotList.Add(tCell); + } + + tCell.SetActive(true); + + return tCell; + } + + private void HideUnused() + { + for (int i = mSpotCount; i < mSpotList.Count; i++) + { + mSpotList[i].SetActive(false); + } + } } \ No newline at end of file diff --git a/Assets/Scripts/UI/PanelMain.cs b/Assets/Scripts/UI/PanelMain.cs index cf2e587c..09ec53ef 100644 --- a/Assets/Scripts/UI/PanelMain.cs +++ b/Assets/Scripts/UI/PanelMain.cs @@ -145,7 +145,7 @@ public class PanelMain : BasePanel private void InitLevelIcons() { - mTotalLevel = GameConfig.Instance.LevelSort.Count; + mTotalLevel = PlayerData.Instance.UnlockedLevel; int tLevel = 0; for (int i = 0; i < mImgLevelIcons.Length; i++)