Files
back_cantanBuilding/Assets/Scripts/UI/BattlePass/BPRewardSlot.cs
2026-05-26 16:15:54 +08:00

99 lines
2.2 KiB
C#

using asap.core;
using System;
using System.Threading.Tasks;
using UniRx;
using UnityEngine;
public class BPRewardSlot : BPItemSlot
{
public enum ESlotState
{
LevelLock,
Normal,
CanGetReward,
HasGotReward
}
#region Field
[SerializeField]
private GameObject
go_light;
#endregion
#region Func
protected override void Start()
{
base.Start();
btn_click?.OnClickAsObservable().Subscribe(_ => OnClickSlotToGetReward()).AddTo(_disposables);
GContext.OnEvent<GetAllBPRewards>().Subscribe(_ => OnGetAllRewards()).AddTo(_disposables);
GContext.OnEvent<BpGetExp>().Subscribe(_ => OnBuyBpLevel()).AddTo(_disposables);
GContext.OnEvent<BpVipUnlock>().Subscribe(_ => OnUnlockBpVip()).AddTo(_disposables);
}
public void OnBuyBpLevel()
{
RefreshSlot();
}
public void OnGetAllRewards()
{
RefreshSlot();
}
public void OnClickSlotToGetReward()
{
if (btn_click)
btn_click.enabled = false;
var eventData = new GetBattlePassRewardEvent();
if (_isNormal)
eventData.NormalLevels.Add(_level);
else
eventData.VipLevels.Add(_level);
GContext.Publish(eventData);
// await RewardItem.ParticleAttractor();
ChangeState(ESlotState.HasGotReward);
}
public override void ChangeState(ESlotState state)
{
base.ChangeState(state);
go_light.SetActive(false);
switch (state)
{
case ESlotState.CanGetReward:
go_light.SetActive(true);
break;
}
}
private async void OnUnlockBpVip()
{
if (!_isNormal)
{
var particle = transform.Find("position/particle");
go_vipLock?.SetActive(!_dataProvider.IsUnlockVip);
particle.gameObject.SetActive(true);
await new WaitForSeconds(2);
if (this != null)
{
particle.gameObject.SetActive(false);
RefreshSlot();
}
}
}
private void OnDestroy()
{
_disposables?.Dispose();
}
#endregion
}