Files
ft/Client/Assets/Scripts/UI/JigsawPuzzle/JigsawPuzzleEntranceButton.cs
2026-06-29 21:18:33 +08:00

72 lines
2.5 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.JigsawPuzzle
{
public class JigsawPuzzleEntranceButton : EventButtonResource
{
[SerializeField] private TMP_Text textTimer;
[SerializeField] private Button btn;
[SerializeField] private Image icon;
private JigsawPuzzleManager _jigsawPuzzleManager;
private JigsawPuzzleManager JigsawPuzzleManager => _jigsawPuzzleManager ??= GContext.container.Resolve<JigsawPuzzleManager>();
private IDisposable _disposable;
private void Awake()
{
if (!textTimer)
textTimer = this.gameObject.FindChildGameObject("text_time").GetComponent<TMP_Text>();
if (!btn)
btn = this.gameObject.GetComponent<Button>();
if (!icon)
icon = this.gameObject.FindChildGameObject("icon_task").GetComponent<Image>();
gameObject.SetActive(false);
btn.onClick.AddListener(OnEnterPackPanel);
var data = JigsawPuzzleManager.Data;
if (data == null || data.EventMain == null) return;
UITypes.JigsawPuzzlePanel.SetType(data.EventMain.UIPanel);
CheckResource(new List<string>() { data.EventMain.UIPanel, data.EventMain.InfoPanel,data.EventMain.PictureRewardPanel, data.EventMain.Icon });
}
protected override void OnDestroy()
{
base.OnDestroy();
_disposable?.Dispose();
}
private void UpdateTimer(long _ = 0L)
{
gameObject.SetActive(IsShowBtn());
textTimer.text = ConvertTools.ConvertTime2(JigsawPuzzleManager?.Data.RemainingTime ?? default);
}
private void OnEnterPackPanel()
{
_ = UIManager.Instance.ShowUILoad(UITypes.JigsawPuzzlePanel);
}
private bool IsShowBtn()
{
return JigsawPuzzleManager?.Data?.IsActive ?? false;
}
protected override void OnLoadEventResource()
{
UpdateTimer();
_disposable = Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this);
gameObject.SetActive(IsShowBtn());
var data = JigsawPuzzleManager.Data;
if (data == null || data.EventMain == null) return;
_ = GContext.container.Resolve<IUIService>().SetImageSprite(icon, data.EventMain.Icon);
}
}
}