You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

140 lines
4.7 KiB

using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Dialogs
{
public class AfterDeathDialog : BaseDialog
{
[SerializeField] GameObject m_adsObj;
[SerializeField] TextMeshProUGUI m_headerText;
[SerializeField] TextMeshProUGUI m_labelText;
[SerializeField] TextMeshProUGUI m_timerText;
[SerializeField] TextMeshProUGUI m_adsText;
[SerializeField] Button m_respawnButton;
[SerializeField] Button m_respawnButton2;
[SerializeField] Button m_watchAdsButton;
float m_startTime = 6f;
bool m_needCloseDialogByTime = true;
//-----------------------------------------------------------------------------------------
void Start ()
{
m_type = DialogType.AFTER_DEATH_DIALOG;
}
//-----------------------------------------------------------------------------------------
public void Init()
{
InitTexts();
InitButtons();
InitAdsObj();
StartCoroutine(UpdateTimer());
}
//-----------------------------------------------------------------------------------------
void InitAdsObj()
{
if (!CommonFunctions.IsRewardedAdCanBeShown())
m_adsObj.SetActive(false);
else
m_respawnButton.gameObject.SetActive(false);
}
//-----------------------------------------------------------------------------------------
void InitButtons()
{
if (m_respawnButton)
m_respawnButton.onClick.AddListener(ButtonPress);
if (m_respawnButton2)
m_respawnButton2.onClick.AddListener(ButtonPress);
if (m_watchAdsButton)
m_watchAdsButton.onClick.AddListener(ButtonPress);
}
//-----------------------------------------------------------------------------------------
void ButtonPress()
{
GameObject currentClickedObj = EventSystem.current.currentSelectedGameObject;
if (currentClickedObj == m_respawnButton.gameObject)
{
if (GlobalsVar.gUser.Crystals > GlobalsVar.gRespawnPrice)
{
GlobalsVar.gUser.IncCurrency(Shop.ShopType.Gems, -GlobalsVar.gRespawnPrice);
StopAllCoroutines();
HideDialog();
GameBoard.Instance.MainCharacter.Reload();
}
}
else if (currentClickedObj == m_respawnButton2.gameObject)
{
if (GlobalsVar.gUser.Crystals > GlobalsVar.gRespawnPrice)
{
GlobalsVar.gUser.IncCurrency(Shop.ShopType.Gems, -GlobalsVar.gRespawnPrice);
StopAllCoroutines();
HideDialog();
GameBoard.Instance.MainCharacter.Reload();
}
}
else if (currentClickedObj == m_watchAdsButton.gameObject)
{
if (CommonFunctions.IsRewardedAdCanBeShown())
{
StopAllCoroutines();
CommonFunctions.StartShowAd();
}
}
}
//-----------------------------------------------------------------------------------------
void InitTexts()
{
if (m_headerText)
m_headerText.text = GlobalsVar.gGameTextMng.GetGameText(20).ToUpper();
if (m_labelText)
m_labelText.text = GlobalsVar.gGameTextMng.GetGameText(21);
if (m_timerText)
m_timerText.text = m_startTime.ToString().ToUpper();
if (m_adsText)
m_adsText.text = GlobalsVar.gGameTextMng.GetGameText(53).ToUpper();
}
//-----------------------------------------------------------------------------------------
private IEnumerator UpdateTimer()
{
while (m_startTime > 0)
{
m_startTime -= Time.unscaledDeltaTime;
m_timerText.text = ((int)m_startTime).ToString();
if (m_startTime <= 0f)
{
m_startTime = 0f;
m_timerText.text = ((int)m_startTime).ToString();
Time.timeScale = 1f;
if (GlobalsVar.gBoard)
{
GameObject dlg = GlobalsVar.gBoard.StartDialog("EndRunDialog");
dlg.GetComponent<EndRunDialog>().Init();
}
}
yield return null;
}
}
}
}