180 lines
6.3 KiB
C#
180 lines
6.3 KiB
C#
using System;
|
|
using asap.core;
|
|
using Assets.Scripts.UI.AdWheel;
|
|
using cfg;
|
|
using DG.Tweening;
|
|
using game;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
public class AdvertData
|
|
{
|
|
public int ID;
|
|
public int index;
|
|
public int day;
|
|
public string cdTime;
|
|
public bool isOpen;
|
|
}
|
|
public class AdvertPanel : MonoBehaviour
|
|
{
|
|
Button btn_close;
|
|
TMP_Text txt_energy, txt_money, txt_ticket;
|
|
ulong _curGold;
|
|
int _curEnergy;
|
|
int _curTicket;
|
|
protected CompositeDisposable disposables = new CompositeDisposable();
|
|
|
|
|
|
private Transform panel_gift1;
|
|
private Transform panel_gift2;
|
|
private Transform panel_gift3;
|
|
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
txt_ticket = transform.Find("top_area/resource/icon_ticket/text_num").GetComponent<TMP_Text>();
|
|
txt_energy = transform.Find("top_area/resource/icon_energy/text_num").GetComponent<TMP_Text>();
|
|
txt_money = transform.Find("top_area/resource/icon_money/text_num").GetComponent<TMP_Text>();
|
|
btn_close = transform.Find("root/btn_close").GetComponent<Button>();
|
|
|
|
//
|
|
panel_gift1 = transform.Find("root/ScrollView/Viewport/Content/Item/panel_gift1");
|
|
panel_gift2 = transform.Find("root/ScrollView/Viewport/Content/Item/panel_gift2");
|
|
panel_gift3 = transform.Find("root/ScrollView/Viewport/Content/Item/panel_gift3");
|
|
|
|
}
|
|
private void Start()
|
|
{
|
|
var playerData = GContext.container.Resolve<PlayerData>();
|
|
_curGold = playerData.gold;
|
|
_curEnergy = playerData.Energy;
|
|
_curTicket = GContext.container.Resolve<PlayerShopData>().GetAdticketCount();
|
|
txt_money.text = ConvertTools.GetNumberString2(_curGold);
|
|
txt_energy.text = ConvertTools.GetNumberString2(_curEnergy);
|
|
txt_ticket.text = ConvertTools.GetNumberString2(_curTicket);
|
|
btn_close.onClick.AddListener(() =>
|
|
{
|
|
GContext.Publish(new RestartShowHomeUIEvent());
|
|
UIManager.Instance.DestroyUI(UITypes.AdvertPanel);
|
|
});
|
|
GContext.OnEvent<ResAddEvent>().Where(x => x.id == 1002).Subscribe(x =>
|
|
{
|
|
GoldAddAnim();
|
|
}).AddTo(disposables);
|
|
GContext.OnEvent<ResAddEvent>().Where(x => x.id == 1001).Subscribe(x =>
|
|
{
|
|
EnergyAddAnim();
|
|
}).AddTo(disposables);
|
|
GContext.OnEvent<ResAddEvent>().Where(x => x.id == 1006).Subscribe(x =>
|
|
{
|
|
TicketAddAnim();
|
|
}).AddTo(disposables);
|
|
|
|
GContext.OnEvent<ResAddEvent>().Where(x => x.id == 1007).Subscribe(x =>
|
|
{
|
|
TicketAddAnim();
|
|
}).AddTo(disposables);
|
|
|
|
// panel_gift3.gameObject.SetActive(false);
|
|
#if UNITY_IOS || UNITY_IPHONE
|
|
panel_gift2?.gameObject.SetActive(true);
|
|
panel_gift3?.gameObject.SetActive(false);
|
|
#else
|
|
CheckTapJoyOpen();
|
|
#endif
|
|
|
|
}
|
|
|
|
// 7天
|
|
private readonly int _conditionSeconds = 604800; // 7 * 24 * 60 * 60;
|
|
|
|
// 判断是否满足{seconds}没有充值了
|
|
private bool Condition_NoRechargeSeconds(int timeSeconds)
|
|
{
|
|
var lastPaymentStr = PlayFabMgr.Instance.GetLocalData("LastPaymentTime");
|
|
DateTime curTime = ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
DateTime endTime = curTime;
|
|
if (string.IsNullOrEmpty(lastPaymentStr) || !lastPaymentStr.Contains("__"))
|
|
endTime = GContext.container.Resolve<IUserService>().CreateTime.UtcNowOffset();
|
|
|
|
var curTimeSecond = new DateTimeOffset(curTime).ToUnixTimeSeconds();
|
|
var endTimeSecond = new DateTimeOffset(endTime).ToUnixTimeSeconds();
|
|
if (curTimeSecond - endTimeSecond >= timeSeconds)
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
private void CheckTapJoyOpen()
|
|
{
|
|
var tables = GContext.container.Resolve<Tables>();
|
|
var tapjoyWakeParam = tables.TbGlobalConfig.TapjoyWakeParam * 24 * 60 * 60;
|
|
var config = GContext.container.Resolve<IConfig>();
|
|
// bool isTapJoyOpen = !(config != null && string.IsNullOrEmpty(config.Get(GConstant.K_TAPJOY, string.Empty)));
|
|
bool isTapJoyOpen = config == null || string.IsNullOrEmpty(config.Get(GConstant.K_TAPJOY_BAN, string.Empty)) ;
|
|
|
|
#if UNITY_ANDROID
|
|
if (Condition_NoRechargeSeconds(tapjoyWakeParam) && isTapJoyOpen)
|
|
{
|
|
panel_gift2?.gameObject.SetActive(false);
|
|
panel_gift3?.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
panel_gift2?.gameObject.SetActive(true);
|
|
panel_gift3?.gameObject.SetActive(false);
|
|
}
|
|
#endif
|
|
}
|
|
//private async System.Threading.Tasks.Task WaitForRewardPanel()
|
|
//{
|
|
// await new WaitForSeconds(0.5f);
|
|
// var rewardPanelTask = new RewardPopupData();
|
|
// GContext.Publish(rewardPanelTask);
|
|
// if (rewardPanelTask.tcs != null)
|
|
// {
|
|
// await rewardPanelTask.tcs.Task;
|
|
// }
|
|
|
|
//}
|
|
void GoldAddAnim()
|
|
{
|
|
//await WaitForRewardPanel();
|
|
DOTween.Kill("txt_money");
|
|
txt_money.text = ConvertTools.GetNumberString2(_curGold);
|
|
var EndDiamond = GContext.container.Resolve<PlayerData>().gold;
|
|
DOTween.To(() => _curGold, x => _curGold = x, EndDiamond, 1f).OnUpdate(() =>
|
|
{
|
|
txt_money.text = ConvertTools.GetNumberString2(_curGold);
|
|
}).SetId("txt_money");
|
|
}
|
|
void EnergyAddAnim()
|
|
{
|
|
//await WaitForRewardPanel();
|
|
DOTween.Kill("advert_text_energy");
|
|
txt_energy.text = ConvertTools.GetNumberString2(_curEnergy);
|
|
var EndEnergy = GContext.container.Resolve<PlayerData>().Energy;
|
|
DOTween.To(() => _curEnergy, x => _curEnergy = x, EndEnergy, 1f).OnUpdate(() =>
|
|
{
|
|
txt_energy.text = ConvertTools.GetNumberString2(_curEnergy);
|
|
}).SetId("advert_text_energy");
|
|
}
|
|
void TicketAddAnim()
|
|
{
|
|
//await WaitForRewardPanel();
|
|
DOTween.Kill("text_ticket");
|
|
txt_ticket.text = ConvertTools.GetNumberString2(_curTicket);
|
|
var Ticket = GContext.container.Resolve<PlayerShopData>().GetAdticketCount();
|
|
DOTween.To(() => _curTicket, x => _curTicket = x, Ticket, 1f).OnUpdate(() =>
|
|
{
|
|
txt_ticket.text = ConvertTools.GetNumberString2(_curTicket);
|
|
}).SetId("text_ticket");
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
disposables.Dispose();
|
|
}
|
|
}
|