| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  | using System; | 
					
						
							|  |  |  |  | using System.Collections; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using UnityEngine; | 
					
						
							|  |  |  |  | using UnityEngine.UI; | 
					
						
							| 
									
										
										
										
											2022-02-09 11:36:47 +00:00
										 |  |  |  | using DG.Tweening; | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | public class PanelGame : BasePanel | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     public Action<int[]> DelPlay; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-11 11:58:24 +00:00
										 |  |  |  |     [SerializeField] LevelOpening mLvOpening; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     [SerializeField] Text mTxtTitle; | 
					
						
							| 
									
										
										
										
											2022-02-16 10:43:49 +00:00
										 |  |  |  |     [SerializeField] Button mBtnMoreGame; | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     [SerializeField] Button mBtnLevel; | 
					
						
							|  |  |  |  |     [SerializeField] Button mBtnMenu; | 
					
						
							|  |  |  |  |     [SerializeField] ButtonEndings mBtnEndings; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     [SerializeField] ButtonSlot[] mBtnSlots; | 
					
						
							|  |  |  |  |     [SerializeField] GameObject[] mGobArrows; | 
					
						
							|  |  |  |  |     [SerializeField] ButtonSound[] mBtnSounds; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-11 11:58:24 +00:00
										 |  |  |  |     [SerializeField] GameObject mGobChooseTip; | 
					
						
							|  |  |  |  |     [SerializeField] GameObject mGobTapTip; | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     [SerializeField] GameObject mGobPlay; | 
					
						
							|  |  |  |  |     [SerializeField] Button mBtnPlay; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     [SerializeField] GameObject mGobPlayProgress; | 
					
						
							|  |  |  |  |     [SerializeField] Image mImgPlayProgress; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 11:36:47 +00:00
										 |  |  |  |     [SerializeField] Animator mAtrAction; | 
					
						
							|  |  |  |  |     [SerializeField] GameObject mGobOpMask; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     private int mTotalSlot; | 
					
						
							|  |  |  |  |     private int mCurSlotIndex; | 
					
						
							|  |  |  |  |     private int[] mSoundOrder; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 11:36:47 +00:00
										 |  |  |  |     private PanelGameAni mAni; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     private void Awake() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-16 10:43:49 +00:00
										 |  |  |  |         UIUtils.BindBtn(mBtnMoreGame, OnClickMoreGame); | 
					
						
							| 
									
										
										
										
											2022-02-16 09:00:22 +00:00
										 |  |  |  |         UIUtils.BindBtn(mBtnLevel, OnClickLevel, AudioClipType.Click_Normal); | 
					
						
							|  |  |  |  |         UIUtils.BindBtn(mBtnMenu, OnClickMenu, AudioClipType.Click_Tip); | 
					
						
							|  |  |  |  |         UIUtils.BindBtn(mBtnPlay, OnClickPlay, AudioClipType.Click_Play); | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         mBtnEndings.DelClick = OnClickEndings; | 
					
						
							| 
									
										
										
										
											2022-02-09 11:36:47 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         mAni = GetComponent<PanelGameAni>(); | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-11 11:58:24 +00:00
										 |  |  |  |     public void Init(bool pWithOpening = false) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if (pWithOpening) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mLvOpening.Enter(PlayerData.Instance.CurrentLevel, ShowStage); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mLvOpening.gameObject.SetActive(false); | 
					
						
							|  |  |  |  |             ShowStage(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-14 11:17:52 +00:00
										 |  |  |  |     public void RiseSlot(int pIndex) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         mBtnSlots[pIndex].RiseUp(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-11 11:58:24 +00:00
										 |  |  |  |     private void ShowStage() | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         LevelData tLvData = GameConfig.Instance.GetLevelData(PlayerData.Instance.CurrentLevelID); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mTxtTitle.text = tLvData.LevelName; | 
					
						
							| 
									
										
										
										
											2022-02-09 12:07:40 +00:00
										 |  |  |  |         mBtnEndings.Init(PlayerData.Instance.CurrentLevelID, PlayerData.Instance.EndingCountOfLevel(PlayerData.Instance.CurrentLevelID), tLvData.Endings.Count); | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         mTotalSlot = tLvData.SlotCount; | 
					
						
							|  |  |  |  |         mCurSlotIndex = 0; | 
					
						
							|  |  |  |  |         mSoundOrder = new int[mTotalSlot]; | 
					
						
							|  |  |  |  |         for (int i = 0; i < mSoundOrder.Length; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mSoundOrder[i] = -1; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         for (int i = 0; i < mBtnSlots.Length; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mBtnSlots[i].gameObject.SetActive(i < mTotalSlot); | 
					
						
							|  |  |  |  |             mBtnSlots[i].Init(i); | 
					
						
							|  |  |  |  |             mBtnSlots[i].ShowCurrent(i == mCurSlotIndex); | 
					
						
							|  |  |  |  |             mBtnSlots[i].DelClick = OnClickSlot; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         for (int i = 0; i < mGobArrows.Length; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mGobArrows[i].SetActive(i < mTotalSlot - 1); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         for (int i = 0; i < mBtnSounds.Length; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mBtnSounds[i].Init(i); | 
					
						
							|  |  |  |  |             mBtnSounds[i].SetSoundPic(ResourceManager.Instance.LoadRes<Sprite>(Const.Path.GetSoundPic(PlayerData.Instance.CurrentLevelID, i))); | 
					
						
							|  |  |  |  |             mBtnSounds[i].DelClick = OnClickSound; | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-02-09 11:36:47 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-11 11:58:24 +00:00
										 |  |  |  |         mGobChooseTip.SetActive(false); | 
					
						
							| 
									
										
										
										
											2022-02-11 09:21:44 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-11 11:58:24 +00:00
										 |  |  |  |         mGobTapTip.SetActive(false); | 
					
						
							| 
									
										
										
										
											2022-02-09 11:36:47 +00:00
										 |  |  |  |         mGobPlay.SetActive(false); | 
					
						
							|  |  |  |  |         mGobPlayProgress.SetActive(false); | 
					
						
							|  |  |  |  |         mAtrAction.gameObject.SetActive(false); | 
					
						
							|  |  |  |  |         mGobOpMask.SetActive(false); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mAni.Init(); | 
					
						
							| 
									
										
										
										
											2022-02-11 11:58:24 +00:00
										 |  |  |  |         TimerManager.Instance.Schedule(() => mGobChooseTip.SetActive(true), 0.5f); | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-16 10:43:49 +00:00
										 |  |  |  |     private void OnClickMoreGame() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-16 11:41:50 +00:00
										 |  |  |  |         ToukaSDKManager.Instance.LogEventByUmeng(Const.AdsEvent.ClickMoreGame, Const.AdsEvtID.Level, PlayerData.Instance.CurrentLevel.ToString()); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-16 10:43:49 +00:00
										 |  |  |  |         ToukaUtils.OpenMoreGames(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     private void OnClickLevel() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-16 11:41:50 +00:00
										 |  |  |  |         ToukaSDKManager.Instance.LogEventByUmeng(Const.AdsEvent.ClickLevel, Const.AdsEvtID.Level, PlayerData.Instance.CurrentLevel.ToString()); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-10 09:21:59 +00:00
										 |  |  |  |         PanelLevel tUILevel = UIManager.Instance.OpenUI<PanelLevel>(); | 
					
						
							|  |  |  |  |         tUILevel.Init(true); | 
					
						
							| 
									
										
										
										
											2022-02-15 10:59:36 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-16 11:41:50 +00:00
										 |  |  |  |         ToukaSDKManager.Instance.PlayInterstitialAd(Const.AdsEvtValue.GamingSelect); | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnClickMenu() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-10 07:31:53 +00:00
										 |  |  |  |         UIManager.Instance.OpenUI<PanelSettings>(); | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnClickEndings() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-10 04:26:52 +00:00
										 |  |  |  |         PanelEndings tUIEndings = UIManager.Instance.OpenUI<PanelEndings>(); | 
					
						
							|  |  |  |  |         tUIEndings.Init(PlayerData.Instance.CurrentLevelID); | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnClickPlay() | 
					
						
							| 
									
										
										
										
											2022-02-09 11:36:47 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-11 11:58:24 +00:00
										 |  |  |  |         mGobTapTip.SetActive(false); | 
					
						
							| 
									
										
										
										
											2022-02-09 11:36:47 +00:00
										 |  |  |  |         mGobPlay.SetActive(false); | 
					
						
							|  |  |  |  |         mGobOpMask.SetActive(true); | 
					
						
							| 
									
										
										
										
											2022-02-09 12:28:20 +00:00
										 |  |  |  |         for (int i = 0; i < mBtnSlots.Length; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mBtnSlots[i].ShowCurrent(false); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-02-09 11:36:47 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         mAni.ReadyPlay(0.5f); | 
					
						
							|  |  |  |  |         TimerManager.Instance.Schedule(Action, 0.5f); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void Action() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         mAtrAction.gameObject.SetActive(true); | 
					
						
							|  |  |  |  |         mAtrAction.Play("Action"); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-16 09:00:22 +00:00
										 |  |  |  |         AudioManager.Instance.PlaySound(AudioClipType.Click_Play); | 
					
						
							| 
									
										
										
										
											2022-02-14 09:14:06 +00:00
										 |  |  |  |         TimerManager.Instance.Schedule(PlayActionSound, 1f); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void PlayActionSound() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-16 09:00:22 +00:00
										 |  |  |  |         AudioManager.Instance.PlaySound(AudioClipType.Action); | 
					
						
							| 
									
										
										
										
											2022-02-14 09:14:06 +00:00
										 |  |  |  |         TimerManager.Instance.Schedule(StartPlay, 1f); | 
					
						
							| 
									
										
										
										
											2022-02-09 11:36:47 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void StartPlay() | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     { | 
					
						
							|  |  |  |  |         DelPlay?.Invoke(mSoundOrder); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-09 11:36:47 +00:00
										 |  |  |  |         mGobPlayProgress.SetActive(true); | 
					
						
							|  |  |  |  |         mImgPlayProgress.fillAmount = 0; | 
					
						
							|  |  |  |  |         mImgPlayProgress.DOFillAmount(1, mSoundOrder.Length * 1.5f).SetEase(Ease.Linear); | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnClickSlot(int pIndex) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         mCurSlotIndex = pIndex; | 
					
						
							|  |  |  |  |         for (int i = 0; i < mBtnSlots.Length; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mBtnSlots[i].ShowCurrent(i == mCurSlotIndex); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnClickSound(int pIndex) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         mSoundOrder[mCurSlotIndex] = pIndex; | 
					
						
							|  |  |  |  |         mBtnSlots[mCurSlotIndex].SetSoundPic(ResourceManager.Instance.LoadRes<Sprite>(Const.Path.GetSoundPic(PlayerData.Instance.CurrentLevelID, pIndex))); | 
					
						
							|  |  |  |  |         if (mCurSlotIndex < mTotalSlot - 1) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             OnClickSlot(mCurSlotIndex + 1); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         AudioManager.Instance.PlaySound(ResourceManager.Instance.LoadRes<AudioClip>(Const.Path.GetSound(PlayerData.Instance.CurrentLevelID, pIndex))); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         CheckOrder(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void CheckOrder() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         bool tAllSet = true; | 
					
						
							|  |  |  |  |         for (int i = 0; i < mSoundOrder.Length; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (mSoundOrder[i] < 0) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 tAllSet = false; | 
					
						
							|  |  |  |  |                 break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-14 09:19:31 +00:00
										 |  |  |  |         mGobChooseTip.SetActive(!tAllSet); | 
					
						
							| 
									
										
										
										
											2022-02-11 11:58:24 +00:00
										 |  |  |  |         mGobTapTip.SetActive(tAllSet); | 
					
						
							| 
									
										
										
										
											2022-02-09 08:35:01 +00:00
										 |  |  |  |         mGobPlay.SetActive(tAllSet); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | } |