| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | using System.Collections; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using UnityEngine; | 
					
						
							|  |  |  |  | using UnityEngine.UI; | 
					
						
							|  |  |  |  | using DG.Tweening; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | public class PanelResult : BasePanel | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     [SerializeField] GameObject mGobWin; | 
					
						
							|  |  |  |  |     [SerializeField] GameObject mGobLose; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     [SerializeField] Text mTxtCoin; | 
					
						
							|  |  |  |  |     [SerializeField] Text mTxtAdCoin; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     [SerializeField] RectTransform mRctNeedle; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     [SerializeField] Button mBtnAdCoin; | 
					
						
							|  |  |  |  |     [SerializeField] Button mBtnContinue; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     [SerializeField] Vector2 mRollArea; | 
					
						
							|  |  |  |  |     [SerializeField] Vector2 m3XArea; | 
					
						
							|  |  |  |  |     [SerializeField] Vector2 m2XArea; | 
					
						
							|  |  |  |  |     [SerializeField] Vector2 m1_5XArea; | 
					
						
							|  |  |  |  |     [SerializeField] float mRollSpeed = 50; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |     [SerializeField] GameObject mGobNative; | 
					
						
							|  |  |  |  |     [SerializeField] RectTransform mRctTopLeft; | 
					
						
							|  |  |  |  |     [SerializeField] RectTransform mRctBottomRight; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     private int mBaseCoin = 200; | 
					
						
							|  |  |  |  |     private float mMultiple = 1; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private bool mIsRolling = false; | 
					
						
							|  |  |  |  |     private int mRollDir = 1; | 
					
						
							|  |  |  |  |     private Vector3 mNextPos; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |     private bool mWin; | 
					
						
							|  |  |  |  |     private bool mHasClickedAdCoin; | 
					
						
							|  |  |  |  |     private bool mHasShowedNoAds = false; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     private AudioSource mWheelAS; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void Awake() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         UIUtils.BindBtn(mBtnAdCoin, OnClickAdCoin); | 
					
						
							|  |  |  |  |         UIUtils.BindBtn(mBtnContinue, OnClickContinue); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |     public void InitResult(bool pWin, int pTotalHurt, bool pShowNative) | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |         mWin = pWin; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |         mGobWin.SetActive(mWin); | 
					
						
							|  |  |  |  |         mGobLose.SetActive(!mWin); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |         if (GameConfig.Instance.IsAutoLevel) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mBaseCoin = mWin ? PlayerData.Instance.CurrentWinCoin : PlayerData.Instance.CurrentLoseCoin; | 
					
						
							|  |  |  |  |             mBaseCoin = Mathf.Max(100, mBaseCoin); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             float tLevelFactor = ((PlayerData.Instance.CurrentLevel - 1) / 20) * 0.5f + 1; | 
					
						
							| 
									
										
										
										
											2022-06-08 13:56:34 +00:00
										 |  |  |  |             mBaseCoin = (int)(pTotalHurt * 10 * tLevelFactor * (mWin ? 1f : 0.3f)); | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  |          | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         mIsRolling = true; | 
					
						
							|  |  |  |  |         mTxtAdCoin.text = UIUtils.NumForShort(mBaseCoin); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         PlayerData.Instance.Coin += mBaseCoin; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         int tCoin = 0; | 
					
						
							|  |  |  |  |         DOTween.To(() => tCoin, (tVal) => tCoin = tVal, mBaseCoin, 1).SetEase(Ease.Linear).onUpdate = () => | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mTxtCoin.text = "+" + UIUtils.NumForShort(tCoin); | 
					
						
							|  |  |  |  |         }; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         Utils.DelayShowGameObject(mBtnContinue.gameObject, 1.5f); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mWheelAS = AudioManager.Instance.PlaySoundLoop(AudioClipType.PrizeWheel, 0.6f); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         TKGSDKManager.Instance.LogRewardAdBtnShow(Const.AdsValue.GetCoin); | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         Debug.Log("TKG Native switch:" + TKGSDKManager.Instance.GetConfigBool(TKGParamKey.NativeSwitch.ToString())); | 
					
						
							|  |  |  |  |         Debug.Log("TKG Native ready:" + TKGUtils.IsNativeReady()); | 
					
						
							|  |  |  |  |         if (pShowNative) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             ShowNative(true); | 
					
						
							|  |  |  |  |             TKGSDKManager.Instance.HideBanner(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             ShowNative(false); | 
					
						
							|  |  |  |  |             TKGSDKManager.Instance.ShowBanner(2); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void Update() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if (mIsRolling) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mNextPos = mRctNeedle.localPosition + (Vector3.right * mRollDir * mRollSpeed * Time.deltaTime); | 
					
						
							|  |  |  |  |             if (mNextPos.x >= mRollArea.y) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 mNextPos.x = mRollArea.y; | 
					
						
							|  |  |  |  |                 mRollDir = -1; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             else if (mNextPos.x <= mRollArea.x) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 mNextPos.x = mRollArea.x; | 
					
						
							|  |  |  |  |                 mRollDir = 1; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             mRctNeedle.localPosition = mNextPos; | 
					
						
							|  |  |  |  |             SetMultiple(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |     private void OnDestroy() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         ShowNative(false); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void ShowNative(bool pShow) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         mGobNative.SetActive(pShow); | 
					
						
							|  |  |  |  |         if (pShow) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             TKGUtils.ShowNative(mRctTopLeft.position, mRctBottomRight.position, mWin ? Const.AdsValue.GameSuccess : Const.AdsValue.GameFailure); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             TKGUtils.RemoveNative(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     private void SetMultiple() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         float tX = Mathf.Abs(mRctNeedle.localPosition.x); | 
					
						
							|  |  |  |  |         if (IsInArea(tX, m3XArea)) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mMultiple = 3; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else if (IsInArea(tX, m2XArea)) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mMultiple = 2; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else if (IsInArea(tX, m1_5XArea)) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mMultiple = 1.5f; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mMultiple = 1; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         mTxtAdCoin.text = UIUtils.NumForShort((int)(mBaseCoin * mMultiple)); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private bool IsInArea(float pVal, Vector2 pArea)//val and area is positive | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if (pVal >= pArea.x && pVal < pArea.y) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             return true; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         return false; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnClickAdCoin() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-06-13 10:42:49 +00:00
										 |  |  |  |         AudioManager.Instance.StopSoundLoop(mWheelAS); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         mIsRolling = false; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         AdsUtils.PlayReward(Const.AdsValue.GetCoin, () => | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             PlayerData.Instance.Coin += (int)(mBaseCoin * (mMultiple - 1)); | 
					
						
							|  |  |  |  |             UIUtils.FlyCoin(mBtnAdCoin.transform.position, (int)(mBaseCoin * mMultiple)); | 
					
						
							|  |  |  |  |             AudioManager.Instance.PlaySound(AudioClipType.GetCoin); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |             mHasClickedAdCoin = true; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |             WaitForLoad(1.5f); | 
					
						
							|  |  |  |  |         }); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void OnClickContinue() | 
					
						
							|  |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-06-13 10:42:49 +00:00
										 |  |  |  |         AudioManager.Instance.StopSoundLoop(mWheelAS); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         UIUtils.FlyCoin(mBtnAdCoin.transform.position, mBaseCoin); | 
					
						
							|  |  |  |  |         AudioManager.Instance.PlaySound(AudioClipType.GetCoin); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |         mHasClickedAdCoin = false; | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |         WaitForLoad(1.5f); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void WaitForLoad(float pWaitSeconds) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         mBtnAdCoin.gameObject.SetActive(false); | 
					
						
							|  |  |  |  |         mBtnContinue.gameObject.SetActive(false); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 13:56:34 +00:00
										 |  |  |  |         TimerManager.Instance.Schedule(GameManager.Instance.LoadGame, pWaitSeconds); | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     private void LoadGame() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if(mHasClickedAdCoin) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             GameManager.Instance.LoadGame(); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             mHasShowedNoAds = AdsUtils.PlayInterstitial(mWin ? Const.AdsValue.GameSuccess : Const.AdsValue.GameFailure, mWin, () => | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 if (mHasShowedNoAds) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     GameManager.Instance.LoadGame(); | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             }); | 
					
						
							|  |  |  |  |             if (!mHasShowedNoAds) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 GameManager.Instance.LoadGame(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | } |