126 lines
4.2 KiB
C#
126 lines
4.2 KiB
C#
using EnhancedUI.EnhancedScroller;
|
|
using UnityEngine;
|
|
using game;
|
|
using asap.core;
|
|
using System.Threading.Tasks;
|
|
using UniRx;
|
|
|
|
public class EventOfferJourneyWheelCellRightBottom : EventOfferJourneyBlockView
|
|
{
|
|
[SerializeField] private GameObject fxLock, fxReward, fxFirework;
|
|
private EventOfferJourneyWheelAnimationParams _param;
|
|
|
|
public override void Start()
|
|
{
|
|
base.Start();
|
|
GContext.OnEvent<RewardPanelClose>().Subscribe(OnRewardPanelClose).AddTo(this);
|
|
}
|
|
|
|
public void Init(EventOfferJourneyBlockData data, EState state, EnhancedScroller scroller,
|
|
EventOfferJourneyWheelAnimationParams param, bool isGrandPrize = false, float cellOffset = 0, int bgIdx = 0)
|
|
{
|
|
base.Init(data, state, scroller, isGrandPrize);
|
|
var c = transform.Find("OfferJourneyWheel_Reward");
|
|
var pos = c.transform.localPosition;
|
|
c.transform.localPosition = new Vector3(pos.x, +cellOffset, pos.z);
|
|
fxLock.SetActive(false);
|
|
fxReward.SetActive(true);
|
|
fxFirework.SetActive(false);
|
|
reward.transform.localScale = Vector3.one * param.rewardScale;
|
|
_param = param;
|
|
SetBg(bgIdx);
|
|
}
|
|
|
|
public async Task SetBought()
|
|
{
|
|
_state = EState.Bought;
|
|
if (btnIap.gameObject.activeSelf)
|
|
{
|
|
btnIap.gameObject.SetActive(false);
|
|
btnIapGray.gameObject.SetActive(false);
|
|
}
|
|
if (btnTicket.gameObject.activeSelf)
|
|
{
|
|
btnTicket.gameObject.SetActive(false);
|
|
btnTicketGray.gameObject.SetActive(false);
|
|
}
|
|
fxReward.SetActive(false);
|
|
_ = PlayRewardDisappear(0.2f);
|
|
if (goGrandReward != null)
|
|
goGrandReward.SetActive(false);
|
|
aniTick.gameObject.SetActive(true);
|
|
GContext.Publish(new Game.EventUISound("audio_ui_offerjourneywheel_completed"));
|
|
aniTick.Play("OfferJourneyWheelGet");
|
|
|
|
await PlayFx(fxFirework, _param.fireworkDelay);
|
|
// _ = Task.Delay(TimeSpan.FromSeconds(aniTick.GetClip("OfferJourneyShellGet").length));
|
|
if (dataIndex > 0)
|
|
{
|
|
var nextViewRaw = _scroller.GetCellViewAtDataIndex(dataIndex - 1);
|
|
if (nextViewRaw is EventOfferJourneyWheelCellLeftTop leftTop)
|
|
{
|
|
await leftTop.Unlock();
|
|
}
|
|
else if (nextViewRaw is EventOfferJourneyWheelCellLeftBottom leftBottom)
|
|
{
|
|
await leftBottom.Unlock();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GContext.Publish(new EventOfferJourneyClosePanel());
|
|
var rawData = GContext.container.Resolve<IEventOfferJourneyData>();
|
|
if (rawData is EventOfferJourneyLvlTriggerData lvlTriggerData && !lvlTriggerData.IsActive)
|
|
{
|
|
GContext.Publish(new EventOfferJourneyHideEntrance());
|
|
}
|
|
}
|
|
// UnityEngine.Debug.Log($"Set Bought here @ {dataIndex}", this);
|
|
}
|
|
|
|
public async Task Unlock()
|
|
{
|
|
_state = EState.Active;
|
|
goLock.SetActive(false);
|
|
fxLock.SetActive(false);
|
|
fxLock.SetActive(true);
|
|
await Task.Delay(System.TimeSpan.FromSeconds(0.3f));
|
|
GContext.Publish(new Game.EventUISound("audio_ui_offerjourneyshell_break"));
|
|
if (btnIapGray.gameObject.activeSelf)
|
|
{
|
|
btnIapGray.gameObject.SetActive(false);
|
|
btnIap.gameObject.SetActive(true);
|
|
}
|
|
if (btnTicketGray.gameObject.activeSelf)
|
|
{
|
|
btnTicketGray.gameObject.SetActive(false);
|
|
btnTicket.gameObject.SetActive(true);
|
|
}
|
|
GContext.Publish(new EventOfferJourneyDisplayEnd());
|
|
}
|
|
|
|
public async void OnRewardPanelClose(RewardPanelClose _)
|
|
{
|
|
try
|
|
{
|
|
if (_state != EState.Active)
|
|
return;
|
|
await SetBought();
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
[SerializeField] private GameObject[] goBgList;
|
|
private void SetBg(int index)
|
|
{
|
|
if (goBgList is not { Length: > 0 })
|
|
return;
|
|
index %= goBgList.Length;
|
|
for(int i = 0; i < goBgList.Length; i++)
|
|
goBgList[i].SetActive(i == index);
|
|
}
|
|
}
|