| 
									
										
										
										
											2022-02-10 04:26:52 +00:00
										 |  |  |  | using System.Collections; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using UnityEngine; | 
					
						
							|  |  |  |  | using UnityEngine.UI; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | public class EndingCell : MonoBehaviour | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     [SerializeField] Text mTxtEndingName; | 
					
						
							|  |  |  |  |     [SerializeField] GameObject mGobCheck; | 
					
						
							|  |  |  |  |     [SerializeField] GameObject mGobGood; | 
					
						
							|  |  |  |  |     [SerializeField] Button mBtnTip; | 
					
						
							|  |  |  |  |     [SerializeField] Button mBtnAdTip; | 
					
						
							| 
									
										
										
										
											2022-02-10 10:17:22 +00:00
										 |  |  |  |     [SerializeField] GameObject mGobPlayingTip; | 
					
						
							| 
									
										
										
										
											2022-02-10 04:26:52 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     private int mLevelID; | 
					
						
							|  |  |  |  |     private int mEndingID; | 
					
						
							|  |  |  |  |     private EndingData mEdData; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-10 10:17:22 +00:00
										 |  |  |  |     private List<AudioClip> mTipSoundList; | 
					
						
							|  |  |  |  |     private TimerUnit mTipPlayTimer; | 
					
						
							|  |  |  |  |     private int mTipIndex; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-10 04:26:52 +00:00
										 |  |  |  |     private void Awake() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         UIUtils.BindBtn(mBtnTip, OnClickTip); | 
					
						
							| 
									
										
										
										
											2022-02-15 10:18:44 +00:00
										 |  |  |  |         UIUtils.BindBtn(mBtnAdTip, OnClickAdTip); | 
					
						
							| 
									
										
										
										
											2022-02-10 04:26:52 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-10 10:17:22 +00:00
										 |  |  |  |     private void OnDisable() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if (mTipPlayTimer != null) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mTipPlayTimer.Destroy(); | 
					
						
							|  |  |  |  |             mTipPlayTimer = null; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-10 04:26:52 +00:00
										 |  |  |  |     public void Init(int pLevelID, int pEndingID) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         mLevelID = pLevelID; | 
					
						
							|  |  |  |  |         mEndingID = pEndingID; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mEdData = GameConfig.Instance.GetLevelData(mLevelID).Endings[pEndingID]; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mTxtEndingName.text = mEdData.EndingName; | 
					
						
							|  |  |  |  |         mGobCheck.SetActive(PlayerData.Instance.HasUnlockedEnding(mLevelID, mEndingID)); | 
					
						
							|  |  |  |  |         mGobGood.SetActive(mEdData.IsGoodEnding); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         bool tHasWatchedAdTip = PlayerData.Instance.HasWatchedEndingAdTip(mLevelID, mEndingID); | 
					
						
							|  |  |  |  |         mBtnTip.gameObject.SetActive(tHasWatchedAdTip); | 
					
						
							|  |  |  |  |         mBtnAdTip.gameObject.SetActive(!tHasWatchedAdTip); | 
					
						
							| 
									
										
										
										
											2022-02-10 10:17:22 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         mGobPlayingTip.SetActive(false); | 
					
						
							| 
									
										
										
										
											2022-02-10 04:26:52 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnClickTip() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-02-10 10:17:22 +00:00
										 |  |  |  |         string[] tTemplateEndingStrs = mEdData.EndingCode.Split(';'); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mTipSoundList = new List<AudioClip>(); | 
					
						
							|  |  |  |  |         for (int i = 0; i < tTemplateEndingStrs[0].Length; i++) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             int tSoundIndex = tTemplateEndingStrs[0][i] == 'X' ? 0 : (int.Parse(tTemplateEndingStrs[0][i].ToString()) - 1); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             mTipSoundList.Add(ResourceManager.Instance.LoadRes<AudioClip>(Const.Path.GetSound(mLevelID, tSoundIndex))); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (mTipPlayTimer == null) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mTipPlayTimer = TimerManager.Instance.CreateTimerUnit(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mTipIndex = 0; | 
					
						
							|  |  |  |  |         mTipPlayTimer.CancelTimer(); | 
					
						
							|  |  |  |  |         mTipPlayTimer.StartTimer(PlayOneTip, 0.3f); | 
					
						
							|  |  |  |  |         mGobPlayingTip.SetActive(true); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void PlayOneTip() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         AudioManager.Instance.PlaySound(mTipSoundList[mTipIndex]); | 
					
						
							|  |  |  |  |         mTipIndex++; | 
					
						
							| 
									
										
										
										
											2022-02-10 04:26:52 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-10 10:17:22 +00:00
										 |  |  |  |         if (mTipIndex < mTipSoundList.Count) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mTipPlayTimer.StartTimer(PlayOneTip, 1f); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mGobPlayingTip.SetActive(false); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-02-10 04:26:52 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnClickAdTip() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-07-27 02:30:05 +00:00
										 |  |  |  |         //TKGSDKManager.Instance.PlayRewardAd(Const.AdsEvtValue.UnlockSound, WatchAdSucceed, () => | 
					
						
							|  |  |  |  |         //{ | 
					
						
							|  |  |  |  |         //    UIManager.Instance.OpenUI<PanelNoAdsTip>(); | 
					
						
							|  |  |  |  |         //}); | 
					
						
							|  |  |  |  |         WatchAdSucceed(true); | 
					
						
							| 
									
										
										
										
											2022-02-15 10:59:36 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-02-15 07:43:03 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-31 15:14:44 +00:00
										 |  |  |  |     private void WatchAdSucceed(bool pResult) | 
					
						
							| 
									
										
										
										
											2022-02-15 10:59:36 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-05-31 15:14:44 +00:00
										 |  |  |  |         if (!pResult) | 
					
						
							|  |  |  |  |             return; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-10 04:26:52 +00:00
										 |  |  |  |         PlayerData.Instance.AddEndingAdTip(mLevelID, mEndingID); | 
					
						
							|  |  |  |  |         mBtnTip.gameObject.SetActive(true); | 
					
						
							|  |  |  |  |         mBtnAdTip.gameObject.SetActive(false); | 
					
						
							|  |  |  |  |         OnClickTip(); | 
					
						
							| 
									
										
										
										
											2022-02-16 11:41:50 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-07-27 02:30:05 +00:00
										 |  |  |  |         //TKGSDKManager.Instance.LogEvent(Const.AdsEvent.UnlockTip, Const.AdsEvtID.Level, PlayerData.Instance.CurrentLevel.ToString()); | 
					
						
							| 
									
										
										
										
											2022-02-10 04:26:52 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | } |