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

148 lines
5.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Threading.Tasks;
using asap.core;
using GameCore;
using TMPro;
using UniRx;
using UnityEngine;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;
namespace EventBossFight
{
public class EventBossFightReviewPanel : BasePanel
{
private Button _btnFight;
private Button _btnRest;
private RewardItemNew[] _rewards;
private TMP_Text _textTime;
private GameObject _boss;
private EventBossFightManager _manager;
private EventBossFightManager Manager => _manager ??= GContext.container.Resolve<EventBossFightManager>();
private EventBossFightData Data => Manager.Data;
private Animation _uiAnimation;
private AsyncOperationHandle<GameObject> _reviewBossInstantiateHandle;
private void Awake()
{
_btnFight = gameObject.FindChildGameObject("btn_fight").GetComponentInChildren<Button>();
_btnFight.onClick.AddListener(OnClickFight);
_btnRest = gameObject.FindChildGameObject("btn_rest").GetComponentInChildren<Button>();
_btnRest.onClick.AddListener(OnClickRest);
_rewards = this.gameObject.GetComponentsInChildren<RewardItemNew>(true);
_boss = gameObject.FindChildGameObject("boss");
_textTime = this.gameObject.FindChildGameObject("text_time").GetComponent<TMP_Text>();
Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(disposables);
foreach (var item in _rewards)
{
item?.gameObject.SetActive(false);
}
_uiAnimation = this.GetComponent<Animation>();
}
protected override void OnDestroy()
{
EventBossFightPerStageVideoBossLoader.ReleaseAddressableBoss(ref _reviewBossInstantiateHandle);
_btnFight.onClick.RemoveAllListeners();
_btnRest.onClick.RemoveAllListeners();
base.OnDestroy();
}
protected override void Start()
{
_uiAnimation.Play("popup_common_show");
_textTime.text = string.Empty;
_ = InitReviewFlowAsync();
}
private async Task InitReviewFlowAsync()
{
try
{
Manager.TryStartNewRound();
HideBossHierarchyChildren();
_reviewBossInstantiateHandle = await EventBossFightPerStageVideoBossLoader.LoadAddressableBossIfNeededAsync(
_boss.transform, Data.InitConfig, Data.StageCountFrom1, _reviewBossInstantiateHandle);
ShowBossVideoIdle();
ShowUI();
}
catch (Exception e)
{
Debug.LogError(e);
}
}
private void HideBossHierarchyChildren()
{
for (var i = 0; i < _boss.transform.childCount; i++)
_boss.transform.GetChild(i).gameObject.SetActive(false);
}
private void ShowBossVideoIdle()
{
Transform stageRoot = null;
if (EventBossFightPerStageVideoBossLoader.TryGetBossRootFromHandle(_reviewBossInstantiateHandle,
out var fromHandle))
stageRoot = fromHandle;
else if (EventBossFightPerStageVideoBossLoader.TryFindEmbeddedBossSlotRoot(_boss.transform,
Data.InitConfig, Data.StageCountFrom1, out var embedded))
stageRoot = embedded;
if (stageRoot == null)
{
Debug.LogError(
$"复盘 Boss 未就绪(无 Addressables 实例且 boss 下无与 key 同名的嵌入式槽位StageCountFrom1={Data.StageCountFrom1},期望:{EventBossFightBossBundleKeys.GetAddressableKey(Data.InitConfig, Data.StageCountFrom1)}",
_boss);
return;
}
// InitReviewFlowAsync 里 HideBossHierarchyChildren 已关闭 boss 下所有子节点;嵌入式须激活本关槽位
stageRoot.gameObject.SetActive(true);
EventBossFightPerStageVideoBossLoader.PlayVideoBossIdle(stageRoot.gameObject,
"[EventBossFightReviewPanel]");
}
private void UpdateTimer(long obj)
{
if (Data == null)
return;
_textTime.text = ConvertTools.ConvertTime2(Data.RemainingTime);
}
public async Task ClosePanel()
{
_uiAnimation.Play("popup_common_out");
await Awaiters.Seconds(0.25f);
UIManager.Instance.DestroyUI(UITypes.EventBossFightReviewPopupPanel);
}
private void ShowUI()
{
UpdateTimer(0);
var itemDatas = GContext.container.Resolve<PlayerItemData>()
.GetItemDataByDropIdLureInflation(Data.InflationRate, Data.StageConfig.DropId);
if (itemDatas == null) return;
for (var i = 0; i < itemDatas.Count && i < _rewards.Length; i++)
{
if (itemDatas[i] == null) continue;
_rewards[i].SetData(itemDatas[i]);
_rewards[i].gameObject.SetActive(true);
}
}
private void OnClickRest()
{
Manager.RestFight();
}
private void OnClickFight()
{
Manager.StartNewStageFight();
}
}
}