// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-09-24
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace G.UI
{
///
/// 复活面板
///
public class RevivePanel : KUIWidget
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
Button _btnAdsChance;
[KUIFlag]
TextMeshProUGUI _tmpCountdown;
[KUIFlag]
Image _imgAdsChance;
[KUIFlag]
Image _imgFreeChance;
[KUIFlag]
Button _btnQuit;
[KUIFlag]
Button _btnBg;
[KUIFlag]
KUIImage _imgPrivilege;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private float _countdown;
#endregion
#region Method
private bool CheckAd()
{
return GameLevel.Instance.curLevelId > 1 && VipProxy.Instance.curVip < 2;
}
private void OnBtnAdsChance()
{
if (CheckAd())
{
AdProxy.Instance.PlayAd("battle", "revive", GameLevel.Instance.curStageId.ToString(), (error, message) =>
{
if (error == 0)
{
UI_Ingame.Instance.Resurrection();
this.gameObject.SetActive(false);
}
});
}
else
{
UI_Ingame.Instance.Resurrection();
this.gameObject.SetActive(false);
}
}
private void OnBgClick()
{
//if (_countdown > 0.5f)
// _countdown -= 0.5f;
}
private void OnQuitBtnClick()
{
this.gameObject.SetActive(false);
UI_Ingame.Instance.OnRefuseRevive();
}
#endregion
#region Unity
///
///
///
private void Awake()
{
SetViewData();
_btnAdsChance.onClick.AddListener(this.OnBtnAdsChance);
_btnQuit.onClick.AddListener(this.OnQuitBtnClick);
_btnBg.onClick.AddListener(this.OnBgClick);
}
private void OnEnable()
{
//_countdown = 9f;
if (CheckAd())
{
_imgAdsChance.gameObject.SetActive(true);
_imgFreeChance.gameObject.SetActive(false);
}
else
{
_imgAdsChance.gameObject.SetActive(false);
_imgFreeChance.gameObject.SetActive(true);
var card = RmbShopProxy.Instance.IsActivitionCard();
if (card == 3)
{
_imgPrivilege.gameObject.SetActive(true);
_imgPrivilege.ShowSprite(0);
}
else if (card == 4)
{
_imgPrivilege.gameObject.SetActive(true);
_imgPrivilege.ShowSprite(1);
}
else
{
_imgPrivilege.gameObject.SetActive(false);
}
}
#if !UNITY_WEBGL && UNITY_EDITOR
System.Collections.IEnumerator AutoGame()
{
yield return new WaitForSeconds(1f);
if (KGMOptions.Instance.自动复活)
{
OnBtnAdsChance();
}
else
{
OnQuitBtnClick();
}
};
if (KGMOptions.Instance.自动挂机)
{
StartCoroutine(AutoGame());
}
#endif
}
private void Update()
{
//if (_countdown > 0)
//{
// _countdown -= Time.unscaledDeltaTime;
// //if (_countdown < 1f)
// // _tmpCountdown.text = ((int)_countdown).ToString();
// //else
// _tmpCountdown.text = Mathf.Ceil(_countdown).ToString();
// if (_countdown <= 0)
// {
// this.gameObject.SetActive(false);
// UI_Ingame.Instance.OnRefuseRevive();
// }
//}
}
#endregion
}
}