225 lines
6.0 KiB
C#
225 lines
6.0 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 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;
|
|
|
|
[SerializeField] GameObject mGobNative;
|
|
[SerializeField] RectTransform mRctTopLeft;
|
|
[SerializeField] RectTransform mRctBottomRight;
|
|
|
|
private int mBaseCoin = 200;
|
|
private float mMultiple = 1;
|
|
|
|
private bool mIsRolling = false;
|
|
private int mRollDir = 1;
|
|
private Vector3 mNextPos;
|
|
|
|
private bool mWin;
|
|
private bool mHasClickedAdCoin;
|
|
private bool mHasShowedNoAds = false;
|
|
private AudioSource mWheelAS;
|
|
|
|
private void Awake()
|
|
{
|
|
UIUtils.BindBtn(mBtnAdCoin, OnClickAdCoin);
|
|
UIUtils.BindBtn(mBtnContinue, OnClickContinue);
|
|
}
|
|
|
|
public void InitResult(bool pWin, int pTotalHurt, bool pShowNative)
|
|
{
|
|
mWin = pWin;
|
|
|
|
mGobWin.SetActive(mWin);
|
|
mGobLose.SetActive(!mWin);
|
|
|
|
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;
|
|
mBaseCoin = (int)(pTotalHurt * 10 * tLevelFactor * (mWin ? 1f : 0.3f));
|
|
}
|
|
|
|
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);
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
|
|
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()
|
|
{
|
|
AudioManager.Instance.StopSoundLoop(mWheelAS);
|
|
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);
|
|
|
|
mHasClickedAdCoin = true;
|
|
WaitForLoad(1.5f);
|
|
});
|
|
}
|
|
|
|
private void OnClickContinue()
|
|
{
|
|
AudioManager.Instance.StopSoundLoop(mWheelAS);
|
|
|
|
UIUtils.FlyCoin(mBtnAdCoin.transform.position, mBaseCoin);
|
|
AudioManager.Instance.PlaySound(AudioClipType.GetCoin);
|
|
|
|
mHasClickedAdCoin = false;
|
|
WaitForLoad(1.5f);
|
|
}
|
|
|
|
private void WaitForLoad(float pWaitSeconds)
|
|
{
|
|
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 ? Const.AdsValue.GameSuccess : Const.AdsValue.GameFailure, mWin, () =>
|
|
{
|
|
if (mHasShowedNoAds)
|
|
{
|
|
GameManager.Instance.LoadGame();
|
|
}
|
|
});
|
|
if (!mHasShowedNoAds)
|
|
{
|
|
GameManager.Instance.LoadGame();
|
|
}
|
|
}
|
|
}
|
|
} |