66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using asap.core;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
namespace Assets.Scripts.UI.AdWheel
|
|
{
|
|
public class AdWheelEntranceButton : EventButtonResource
|
|
{
|
|
[SerializeField] private TMP_Text textTimer;
|
|
[SerializeField] private Button btn;
|
|
[SerializeField] private Image icon;
|
|
|
|
private AdWheelManager _adWheelManager;
|
|
private AdWheelManager _AdWheelManager => _adWheelManager ??= GContext.container.Resolve<AdWheelManager>();
|
|
|
|
private IDisposable _disposable;
|
|
private void Awake()
|
|
{
|
|
gameObject.SetActive(false);
|
|
btn = this.GetComponent<Button>();
|
|
btn.onClick.AddListener(OnEnterPackPanel);
|
|
if (_AdWheelManager == null) return;
|
|
|
|
var adWheelMain = _AdWheelManager.Data.AdWheelMain;
|
|
if (adWheelMain == null) return ;
|
|
CheckResource(new List<string>() { adWheelMain.UIPanel, adWheelMain.Icon });
|
|
}
|
|
protected override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
_disposable?.Dispose();
|
|
}
|
|
private void UpdateTimer(long _ = 0L)
|
|
{
|
|
gameObject.SetActive(IsShowBtn());
|
|
|
|
var adWheelData = _AdWheelManager?.Data;
|
|
if (adWheelData == null) return;
|
|
textTimer.text = ConvertTools.ConvertTime2(adWheelData.RemainingTime);
|
|
}
|
|
private void OnEnterPackPanel()
|
|
{
|
|
_ = UIManager.Instance.ShowUILoad(UITypes.EventBonusWheelPopupPanel);
|
|
}
|
|
private bool IsShowBtn()
|
|
{
|
|
return _AdWheelManager?.Data?.IsActive??false;
|
|
}
|
|
|
|
protected override void OnLoadEventResource()
|
|
{
|
|
UpdateTimer();
|
|
gameObject.SetActive(IsShowBtn());
|
|
if (_AdWheelManager == null) return;
|
|
|
|
var adWheelMain = _AdWheelManager.Data.AdWheelMain;
|
|
if (adWheelMain == null) return;
|
|
_ = GContext.container.Resolve<IUIService>().SetImageSprite(icon, adWheelMain.Icon);
|
|
_disposable = Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this);
|
|
}
|
|
}
|
|
} |