| 
									
										
										
										
											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; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-15 07:43:03 +00:00
										 |  |  |  |     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
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-15 07:43:03 +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
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-15 07:43:03 +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); | 
					
						
							| 
									
										
										
										
											2022-02-15 07:43:03 +00:00
										 |  |  |  |             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
										 |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2022-04-01 14:07:21 +00:00
										 |  |  |  |                 if (pIndex == PlayerData.Instance.UnlockedLevel) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     tCell.SetUnlock(); | 
					
						
							|  |  |  |  |                     tCell.DelClick = OnClickUnlockLevel; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 else | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     tCell.SetEmpty(); | 
					
						
							|  |  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2022-02-13 09:36:12 +00:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  |             else | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 tCell.SetComingSoon(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnClickLevel(int pLevelIndex) | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-15 07:43:03 +00:00
										 |  |  |  |         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) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         ToukaSDKManager.Instance.PlayRewardAd(Const.AdsEvtValue.UnlockLevel, () => | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             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() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-16 09:00:22 +00:00
										 |  |  |  |         AudioManager.Instance.PlaySound(AudioClipType.TurnPage, 0.7f); | 
					
						
							| 
									
										
										
										
											2022-02-14 09:14:06 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void PlayReachEdge() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-16 09:00:22 +00:00
										 |  |  |  |         AudioManager.Instance.PlaySound(AudioClipType.ReachEdge, 0.7f); | 
					
						
							| 
									
										
										
										
											2022-02-14 09:14:06 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-02-13 09:36:12 +00:00
										 |  |  |  | } |