先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
151 lines
4.9 KiB
C#
151 lines
4.9 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UniRx;
|
|
|
|
public class AdvertGiftPanel : MonoBehaviour
|
|
{
|
|
Tables _tables;
|
|
PlayerShopData shopData;
|
|
TMP_Text text_time;
|
|
AdvertGiftItem[] advertGiftItems;
|
|
Timer timer;
|
|
private IDisposable ads;
|
|
AdConfig curAdConfig;
|
|
AdvertGiftItem advertGiftItem;
|
|
private AdvertPopupType _curOpenAdType = AdvertPopupType.None;
|
|
private void Awake()
|
|
{
|
|
_tables = GContext.container.Resolve<Tables>();
|
|
shopData = GContext.container.Resolve<PlayerShopData>();
|
|
text_time = transform.Find("title2/bg_time/text_info").GetComponent<TMP_Text>();
|
|
advertGiftItems = transform.GetComponentsInChildren<AdvertGiftItem>();
|
|
}
|
|
protected void Start()
|
|
{
|
|
Init();
|
|
StartTimer();
|
|
}
|
|
|
|
void Init()
|
|
{
|
|
var DataList = _tables.TbAdConfig.DataList;
|
|
int viplv = GContext.container.Resolve<PlayerData>().vip;
|
|
for (int i = 0; i < advertGiftItems.Length; i++)
|
|
{
|
|
AdConfig adConfig = DataList[i];
|
|
var itemDropPackage = _tables.TbItemDropPackage.GetOrDefault(adConfig.Reward);
|
|
advertGiftItems[i].adConfig = adConfig;
|
|
advertGiftItems[i].vipFree = viplv >= adConfig.VipFree;
|
|
advertGiftItems[i].btn_watch.SetData(() =>
|
|
{
|
|
shopData.AddAdvertCount(curAdConfig.Reward);
|
|
//广告成功
|
|
OnBuySuccess();
|
|
}, AdvertPopupType.Shop);
|
|
advertGiftItems[i].btn_free.onClick.AddListener(OnBuySuccess);
|
|
|
|
if (itemDropPackage.ItemDisplay.Count > 0)
|
|
{
|
|
List<string> CountDisplay = GContext.container.Resolve<PlayerItemData>().ShowItemDropPackage(itemDropPackage);
|
|
advertGiftItems[i].rewardItem1.SetData(itemDropPackage.ItemDisplay[0], CountDisplay[0], true);
|
|
advertGiftItems[i].rewardItem2.SetData(itemDropPackage.ItemDisplay[1], CountDisplay[1], true);
|
|
}
|
|
}
|
|
}
|
|
async void ReStart()
|
|
{
|
|
await Awaiters.Seconds(0.5f);
|
|
StartTimer();
|
|
}
|
|
void SetState()
|
|
{
|
|
shopData.ClearAdvertCount();
|
|
// TODO: restore when VIPAdPackData is available
|
|
// int adCount = shopData.VIPAdPackData.index;
|
|
int adCount = 0; // fallback
|
|
for (int i = 0; i < advertGiftItems.Length; i++)
|
|
{
|
|
advertGiftItems[i].current.SetActive(i == adCount);
|
|
advertGiftItems[i].done.SetActive(i < adCount);
|
|
advertGiftItems[i].unlock.SetActive(i > adCount);
|
|
advertGiftItems[i].unlock2.SetActive(i > adCount);
|
|
|
|
if (i == adCount)
|
|
{
|
|
advertGiftItem = advertGiftItems[i];
|
|
advertGiftItem.btn_free.gameObject.SetActive(advertGiftItem.vipFree);
|
|
advertGiftItem.btn_watch.gameObject.SetActive(!advertGiftItem.vipFree);
|
|
curAdConfig = advertGiftItems[i].adConfig;
|
|
}
|
|
}
|
|
}
|
|
void StartTimer()
|
|
{
|
|
if (timer != null)
|
|
{
|
|
timer.Cancel();
|
|
timer = null;
|
|
}
|
|
var newTime = ZZTimeHelper.UtcNow().UtcNowOffset().Date.AddDays(1);
|
|
TimeSpan timeSpan = newTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
SetState();
|
|
timer = this.AttachTimer((float)timeSpan.TotalSeconds, ReStart, (elapsed) =>
|
|
{
|
|
TimeSpan now = newTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
text_time.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_refresh", $"<size=40>{ConvertTools.ConvertTime2(now)}</size>");
|
|
}, useRealTime: true);
|
|
}
|
|
void OnClickGet()
|
|
{
|
|
advertGiftItem.btn_watch.enabled = false;
|
|
//拉起广告
|
|
AdsDispose();
|
|
ads = GContext.OnEvent<AdsResult>().Subscribe(SetResult);
|
|
_curOpenAdType = AdvertPopupType.Shop;
|
|
GContext.container.Resolve<IAdsService>().ShowRewarded(_curOpenAdType);
|
|
}
|
|
void SetResult(AdsResult adsResult)
|
|
{
|
|
AdsDispose();
|
|
advertGiftItem.btn_watch.enabled = true;
|
|
if (adsResult.Result == 0 && adsResult.Type == AdvertPopupType.Shop)
|
|
{
|
|
shopData.AddAdvertCount(curAdConfig.Reward);
|
|
//广告成功
|
|
OnBuySuccess();
|
|
}
|
|
}
|
|
void AdsDispose()
|
|
{
|
|
if (ads != null)
|
|
{
|
|
_curOpenAdType = AdvertPopupType.None;
|
|
ads.Dispose();
|
|
ads = null;
|
|
}
|
|
}
|
|
private void OnBuySuccess()
|
|
{
|
|
//体力膨胀 不膨胀
|
|
GContext.container.Resolve<PlayerItemData>().AddItemByDrop(curAdConfig.Reward,null);
|
|
// TODO: restore when SetVIPPackNext is available
|
|
// shopData.SetVIPPackNext();
|
|
GContext.Publish(new ShowData());
|
|
SetState();
|
|
shopData.SetAdvRedPoint();
|
|
}
|
|
protected void OnDestroy()
|
|
{
|
|
if (timer != null)
|
|
{
|
|
timer.Cancel();
|
|
}
|
|
}
|
|
}
|