Files
ft/Client/Assets/Scripts/EventBossFight/EventBossFightEntranceButton.cs
2026-06-29 21:18:33 +08:00

92 lines
2.9 KiB
C#

using asap.core;
using GameCore;
using System;
using System.Collections.Generic;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
namespace EventBossFight
{
public class EventBossFightEntranceButton : EventButtonResource
{
[SerializeField] private TMP_Text textTimer;
[SerializeField] private Button btn;
[SerializeField] private Image icon;
private EventBossFightManager _manager;
private EventBossFightManager Manager => _manager ??= GContext.container.Resolve<EventBossFightManager>();
private EventBossFightData Data=>Manager?.Data;
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);
if (Data?.InitConfig == null) return;
var resList = new List<string>
{
Data.InitConfig.UIPanel,
Data.InitConfig.InfoPanel,
Data.InitConfig.Icon,
Data.InitConfig.EndingPanel,
Data.InitConfig.ReviewPanel,
Data.InitConfig.RewardPanel,
Data.InitConfig.LoadingPanel
};
var bossKey = EventBossFightBossBundleKeys.GetAddressableKey(Data.InitConfig, Data.StageCountFrom1);
if (!string.IsNullOrEmpty(bossKey))
resList.Add(bossKey);
CheckResource(resList);
}
protected override void OnDestroy()
{
base.OnDestroy();
_disposable?.Dispose();
}
private void UpdateTimer(long _ = 0L)
{
gameObject.SetActive(IsShowBtn());
textTimer.text = ConvertTools.ConvertTime2(Data?.RemainingTime ?? TimeSpan.Zero);
}
private void OnEnterPackPanel()
{
try
{
if (Data?.InitConfig == null)
return;
EventBossFightActTransition.PublishSwitchToBossFightAct(Data.InitConfig);
}
catch (Exception e)
{
Debug.LogError(e);
}
}
private bool IsShowBtn()
{
return Data?.IsActive ?? false;
}
protected override void OnLoadEventResource()
{
UpdateTimer();
_disposable = Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this);
gameObject.SetActive(IsShowBtn());
if (Data?.InitConfig == null) return;
_ = GContext.container.Resolve<IUIService>().SetImageSprite(icon, Data?.InitConfig.Icon);
}
}
}