153 lines
4.0 KiB
C#
153 lines
4.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;
|
|
|
|
private int mBaseCoin = 200;
|
|
private float mMultiple = 1;
|
|
|
|
private bool mIsRolling = false;
|
|
private int mRollDir = 1;
|
|
private Vector3 mNextPos;
|
|
|
|
private AudioSource mWheelAS;
|
|
|
|
private void Awake()
|
|
{
|
|
UIUtils.BindBtn(mBtnAdCoin, OnClickAdCoin);
|
|
UIUtils.BindBtn(mBtnContinue, OnClickContinue);
|
|
}
|
|
|
|
public void InitResult(bool pWin, int pTotalHurt)
|
|
{
|
|
mGobWin.SetActive(pWin);
|
|
mGobLose.SetActive(!pWin);
|
|
|
|
float tLevelFactor = ((PlayerData.Instance.CurrentLevel - 1) / 20) * 0.5f + 1;
|
|
mBaseCoin = (int)(pTotalHurt * 10 * tLevelFactor * (pWin ? 1 : 0.5f));
|
|
|
|
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);
|
|
}
|
|
|
|
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 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()
|
|
{
|
|
mWheelAS.Stop();
|
|
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);
|
|
|
|
WaitForLoad(1.5f);
|
|
});
|
|
}
|
|
|
|
private void OnClickContinue()
|
|
{
|
|
mWheelAS.Stop();
|
|
|
|
UIUtils.FlyCoin(mBtnAdCoin.transform.position, mBaseCoin);
|
|
AudioManager.Instance.PlaySound(AudioClipType.GetCoin);
|
|
|
|
WaitForLoad(1.5f);
|
|
}
|
|
|
|
private void WaitForLoad(float pWaitSeconds)
|
|
{
|
|
mBtnAdCoin.gameObject.SetActive(false);
|
|
mBtnContinue.gameObject.SetActive(false);
|
|
|
|
TimerManager.Instance.Schedule(GameManager.Instance.LoadGame, pWaitSeconds);
|
|
}
|
|
} |