215 lines
		
	
	
		
			6.4 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			215 lines
		
	
	
		
			6.4 KiB
		
	
	
	
		
			C#
		
	
	
	
| 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 mTxtDiamond;
 | |
|     [SerializeField] Text mTxtCoin;
 | |
| 
 | |
|     [SerializeField] Button mBtnContinueOnly;
 | |
| 
 | |
|     [SerializeField] GameObject mBtnNormalGroup;
 | |
|     [SerializeField] Button mBtnAdCoin;
 | |
|     [SerializeField] Button mBtnContinue;
 | |
| 
 | |
|     [SerializeField] GameObject mGobNative;
 | |
|     [SerializeField] RectTransform mRctNative;
 | |
| 
 | |
|     [SerializeField] GameObject mGobDiamondIcon;
 | |
|     [SerializeField] GameObject mGobRobuxIcon;
 | |
|     [SerializeField] GameObject mGobDiamondBox;
 | |
|     [SerializeField] GameObject mGobRobuxBox;
 | |
| 
 | |
|     [SerializeField] MultipleRoller mRoller;
 | |
| 
 | |
|     private int mBaseDiamond = 0;
 | |
|     private int mBaseCoin = 0;
 | |
|     private float mMultiple = 1;
 | |
| 
 | |
|     private int mCurLevel;
 | |
|     private bool mWin;
 | |
|     private bool mHasClickedAdCoin;
 | |
|     private bool mHasShowedNoAds = false;
 | |
|     private AudioSource mWheelAS;
 | |
| 
 | |
|     private void Awake()
 | |
|     {
 | |
|         UIUtils.BindBtn(mBtnContinueOnly, OnClickContinue);
 | |
| 
 | |
|         UIUtils.BindBtn(mBtnAdCoin, OnClickAdCoin);
 | |
|         UIUtils.BindBtn(mBtnContinue, OnClickContinue);
 | |
| 
 | |
|         mRoller.DelRolling = SetMultiple;
 | |
|     }
 | |
| 
 | |
|     public void InitResult(bool pWin, int pTotalHurt, bool pShowNative)
 | |
|     {
 | |
|         mCurLevel = PlayerData.Instance.CurrentLevel;
 | |
|         mWin = pWin;
 | |
| 
 | |
|         mGobWin.SetActive(mWin);
 | |
|         mGobLose.SetActive(!mWin);
 | |
| 
 | |
|         mBaseDiamond = MMOModule.Instance.GetRewardDiamondOfLevel(PlayerData.Instance.Diamond, mCurLevel);
 | |
|         mBaseDiamond = mWin ? mBaseDiamond : (mCurLevel > 3 ? (mBaseDiamond / 3) : 0);
 | |
| 
 | |
|         if (GameConfig.Instance.IsAutoLevel)
 | |
|         {
 | |
|             mBaseCoin = mWin ? PlayerData.Instance.CurrentWinCoin : PlayerData.Instance.CurrentLoseCoin;
 | |
|             mBaseCoin = Mathf.Max(100, mBaseCoin);
 | |
|         }
 | |
|         else
 | |
|         {
 | |
|             float tLevelFactor = ((mCurLevel - 1) / 20) * 0.5f + 1;
 | |
|             mBaseCoin = (int)(pTotalHurt * 10 * tLevelFactor * (mWin ? 1f : GameConfig.Instance.FailRewardRatio));
 | |
|         }
 | |
| 
 | |
|         PlayerData.Instance.Diamond += mBaseDiamond;
 | |
|         PlayerData.Instance.Coin += mBaseCoin;
 | |
| 
 | |
|         //int tCoin = 0;
 | |
|         //DOTween.To(() => tCoin, (tVal) => tCoin = tVal, mBaseCoin, 1).SetEase(Ease.Linear).onUpdate = () =>
 | |
|         //{
 | |
|         //    mTxtCoin.text = "+" + UIUtils.NumForShort(tCoin);
 | |
|         //};
 | |
| 
 | |
|         mTxtDiamond.text = "+" + UIUtils.NumForShort(mBaseDiamond);
 | |
|         mTxtCoin.text = "+" + UIUtils.NumForShort(mBaseCoin);
 | |
| 
 | |
|         mGobDiamondIcon.SetActive(!MMOModule.Instance.IsAccessible);
 | |
|         mGobRobuxIcon.SetActive(MMOModule.Instance.IsAccessible);
 | |
|         mGobDiamondBox.SetActive(!MMOModule.Instance.IsAccessible);
 | |
|         mGobRobuxBox.SetActive(MMOModule.Instance.IsAccessible);
 | |
| 
 | |
|         Utils.DelayShowGameObject(mBtnContinue.gameObject, 1.5f);
 | |
| 
 | |
|         TKGSDKManager.Instance.LogRewardAdBtnShow(Const.AdsValue.GetCoin);
 | |
| 
 | |
|         //Debug.Log("TKG Native switch:" + TKGSDKManager.Instance.GetConfigBool(TKGParamKey.NativeSwitch));
 | |
|         //Debug.Log("TKG Native ready:" + TKGSDKManager.Instance.IsReadyNativeAd());
 | |
|         if (pShowNative)
 | |
|         {
 | |
|             ShowNative(true);
 | |
|             TKGSDKManager.Instance.HideBanner();
 | |
|         }
 | |
|         else
 | |
|         {
 | |
|             ShowNative(false);
 | |
|             TKGSDKManager.Instance.ShowBanner(Touka.TKGBannerAlign.BannerCenterBottomAlign);
 | |
|         }
 | |
| 
 | |
|         if (mCurLevel > 3)
 | |
|         {
 | |
|             mWheelAS = AudioManager.Instance.PlaySoundLoop(AudioClipType.PrizeWheel, 0.6f);
 | |
|             mRoller.IsRolling = true;
 | |
|         }
 | |
| 
 | |
|         mBtnContinueOnly.gameObject.SetActive(mCurLevel <= 3);
 | |
|         mBtnNormalGroup.gameObject.SetActive(mCurLevel > 3);
 | |
|     }
 | |
| 
 | |
|     private void OnDestroy()
 | |
|     {
 | |
|         ShowNative(false);
 | |
|         AudioManager.Instance.StopSoundLoop(mWheelAS);
 | |
|     }
 | |
| 
 | |
|     private void ShowNative(bool pShow)
 | |
|     {
 | |
|         //mGobNative.SetActive(pShow);
 | |
|         if (pShow)
 | |
|         {
 | |
|             TKGSDKManager.Instance.ShowNative(mRctNative);
 | |
|         }
 | |
|         else
 | |
|         {
 | |
|             TKGSDKManager.Instance.RemoveNative();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void SetMultiple(float pMultiple)
 | |
|     {
 | |
|         mMultiple = pMultiple;
 | |
| 
 | |
|         mTxtDiamond.text = "+" + ((int)(mBaseDiamond * mMultiple)).ToString();
 | |
|         mTxtCoin.text = "+" + UIUtils.NumForShort((int)(mBaseCoin * mMultiple));
 | |
|     }
 | |
| 
 | |
|     private void OnClickAdCoin()
 | |
|     {
 | |
|         if (mCurLevel > 3)
 | |
|         {
 | |
|             AudioManager.Instance.StopSoundLoop(mWheelAS);
 | |
|             mRoller.IsRolling = false;
 | |
|         }
 | |
| 
 | |
|         AdsUtils.PlayReward(TKGRVPositionName.RV_Get_Coin, () =>
 | |
|         {
 | |
|             ShowNative(false);
 | |
|             PlayerData.Instance.Diamond += (int)(mBaseDiamond * (mMultiple - 1));
 | |
|             UIUtils.FlyDiamond(mRctNative.position, (int)(mBaseDiamond * mMultiple));
 | |
| 
 | |
|             PlayerData.Instance.Coin += (int)(mBaseCoin * (mMultiple - 1));
 | |
|             UIUtils.FlyCoin(mTxtCoin.transform.position, (int)(mBaseCoin * mMultiple));
 | |
| 
 | |
|             AudioManager.Instance.PlaySound(AudioClipType.GetCoin);
 | |
| 
 | |
|             mHasClickedAdCoin = true;
 | |
|             WaitForLoad(1.5f);
 | |
|         });
 | |
|     }
 | |
| 
 | |
|     private void OnClickContinue()
 | |
|     {
 | |
|         if (mCurLevel > 3)
 | |
|         {
 | |
|             AudioManager.Instance.StopSoundLoop(mWheelAS);
 | |
|         }
 | |
| 
 | |
|         ShowNative(false);
 | |
|         UIUtils.FlyDiamond(mRctNative.position, mBaseDiamond);
 | |
|         UIUtils.FlyCoin(mTxtCoin.transform.position, mBaseCoin);
 | |
|         AudioManager.Instance.PlaySound(AudioClipType.GetCoin);
 | |
| 
 | |
|         mHasClickedAdCoin = false;
 | |
|         WaitForLoad(1.5f);
 | |
|     }
 | |
| 
 | |
|     private void WaitForLoad(float pWaitSeconds)
 | |
|     {
 | |
|         mBtnContinueOnly.gameObject.SetActive(false);
 | |
| 
 | |
|         mBtnAdCoin.gameObject.SetActive(false);
 | |
|         mBtnContinue.gameObject.SetActive(false);
 | |
| 
 | |
|         TimerManager.Instance.Schedule(GameManager.Instance.LoadGame, pWaitSeconds);
 | |
|     }
 | |
| 
 | |
|     private void LoadGame()
 | |
|     {
 | |
|         if(mHasClickedAdCoin)
 | |
|         {
 | |
|             GameManager.Instance.LoadGame();
 | |
|         }
 | |
|         else
 | |
|         {
 | |
|             mHasShowedNoAds = AdsUtils.PlayInterstitial(mWin ? TKGIVAdPositionName.IV_Success : TKGIVAdPositionName.IV_Fail, mWin, () =>
 | |
|             {
 | |
|                 if (mHasShowedNoAds)
 | |
|                 {
 | |
|                     GameManager.Instance.LoadGame();
 | |
|                 }
 | |
|             });
 | |
|             if (!mHasShowedNoAds)
 | |
|             {
 | |
|                 GameManager.Instance.LoadGame();
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| } |