225 lines
7.7 KiB
C#
225 lines
7.7 KiB
C#
using asap.core;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using game;
|
|
using UniRx;
|
|
using System;
|
|
using GameCore;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Collections;
|
|
|
|
public class EventDrillPanel : MonoBehaviour
|
|
{
|
|
[SerializeField] private TMP_Text textTimer, textTicketCount;
|
|
[SerializeField] private Button btnClose, btnPack, btnInfo;
|
|
[SerializeField] private EventBreakTunnelView[] tunnels;
|
|
[SerializeField] private EventBreakTaskView[] tasks;
|
|
[SerializeField] private float _jiandaBlockSpawnInterval = 0.1f, _jiandaBlockDropTime = 0.5f,_jiandaDrillReadyDuration = 0.5f,
|
|
_jiandaDrillDuration = 0.8f, _jiandaTaskChangeDuration = 0.5f, _jiandaBarFlashDuration = 1f, _jiandaBlockDropHeight = 1680f,
|
|
_jiandaRewardFlyDuration = 2f, _jiandaResetTunnelDelay = 3f, _jiandaButtonPressedDuration = 0.3f, _jiandaDrillDetectionRange = 50f,
|
|
_jiandaBlockDropSfxDelay = 0.3f, _jiandaRewardShowDuration = 2.0f;
|
|
[SerializeField] private GameObject rewardFly, clickMask;
|
|
[SerializeField] private AnimationCurve _jiandaBlockEaseCurve;
|
|
private Coroutine _unblockCoroutine = null;
|
|
private int _blockCounter;
|
|
private EventBreakEntranceData _btnData;
|
|
|
|
private void Awake()
|
|
{
|
|
btnClose.onClick.AddListener(OnClose);
|
|
_btnData = EventBreakAct.Ctx.GetEntranceButtonData();
|
|
UpdateTimer();
|
|
Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this);
|
|
OnTicketCountChange();
|
|
btnPack.onClick.AddListener(OnClickPack);
|
|
btnInfo.onClick.AddListener(OnClickInfo);
|
|
_blockCounter = 0;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
var drillModel = GContext.container.Resolve<DrillModel>();
|
|
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide(gameObject.name);
|
|
if (tunnels.Length != drillModel.DrillJobList.Length || tunnels.Length != tasks.Length)
|
|
{
|
|
Debug.LogError("[EventBreak]Tunnel count not match!");
|
|
return;
|
|
}
|
|
for (int i = 0; i < tunnels.Length; i++)
|
|
{
|
|
var tunnelInfo = new EventBreakTunnelViewInitInfo{
|
|
Job = drillModel.DrillJobList[i],
|
|
SpawnInterval = _jiandaBlockSpawnInterval,
|
|
DropDuration = _jiandaBlockDropTime,
|
|
DrillDuration = _jiandaDrillDuration,
|
|
DropHeight = _jiandaBlockDropHeight,
|
|
Idx = i,
|
|
EaseCurve = _jiandaBlockEaseCurve,
|
|
DrillReadyDuration = _jiandaDrillReadyDuration,
|
|
ResetTunnelDelay = _jiandaResetTunnelDelay,
|
|
ButtonPressedDuration = _jiandaButtonPressedDuration,
|
|
DrillDetectionRange = _jiandaDrillDetectionRange,
|
|
BlockDropSfxDelay = _jiandaBlockDropSfxDelay
|
|
};
|
|
tunnels[i].Init(tunnelInfo);
|
|
var taskInfo = drillModel.TaskInfoList[i];
|
|
tasks[i].Init(taskInfo, _jiandaTaskChangeDuration, _jiandaBarFlashDuration, _jiandaRewardFlyDuration, rewardFly, _jiandaRewardShowDuration);
|
|
}
|
|
EventBreakAct.EventAggregator.GetEvent<EventTicketUpdate>()
|
|
.Subscribe(OnTicketCountChange).AddTo(this);
|
|
EventBreakAct.EventAggregator.GetEvent<EventBreakInsufficientTicket>()
|
|
.Subscribe(_ => OnClickPack()).AddTo(this);
|
|
EventBreakAct.EventAggregator.GetEvent<EventBreakBlockInput>()
|
|
.Subscribe(HandleBlockEvent).AddTo(this);
|
|
EventBreakAct.EventAggregator.GetEvent<EventBreakBlockBreak>()
|
|
.Subscribe(_ => HandleBlockEvent(new EventBreakBlockInput(EEventBreakBlockInputOperation.Block))).AddTo(this);
|
|
var chainPackData = drillModel.ToChainPackData();
|
|
RedPointManager.Instance.SetRedPointState(chainPackData.RedPointKey, chainPackData.DoNeedPackRedPoint);
|
|
}
|
|
|
|
private void OnClose()
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct());
|
|
}
|
|
|
|
private void OnTicketCountChange(EventTicketUpdate _ = null)
|
|
{
|
|
|
|
var n = GContext.container.Resolve<DrillModel>().TicketCount;
|
|
textTicketCount.text = n.ToString();
|
|
var res = EventBreakAct.Ctx.IsTicketEnough(n);
|
|
for (int i = 0; i < tunnels.Length; i++)
|
|
tunnels[i].SetAvailabilityDisplay(res[i]);
|
|
textTicketCount.color = res.All(r => !r)? Color.red : Color.white;
|
|
}
|
|
|
|
private void UpdateTimer(long _ = 0L)
|
|
{
|
|
textTimer.text = ConvertTools.ConvertTime2(_btnData.RemainingTime);
|
|
}
|
|
|
|
private async void OnClickPack()
|
|
{
|
|
try
|
|
{
|
|
PlayBtnPressedAnimation();
|
|
GameObject go;
|
|
var chainPackData = GContext.container.Resolve<DrillModel>().ToChainPackData();
|
|
if (chainPackData.ChainProgress >= chainPackData.ChainListCount)
|
|
{
|
|
go = await UIManager.Instance.ShowUINotLoading(UITypes.EventBreakNormalPackPanel);
|
|
var normalPanel = go.GetComponent<EventBreakNormalPackPanel>();
|
|
normalPanel.Init(EventBreakAct.Ctx.GetNormalPackInfo());
|
|
return;
|
|
}
|
|
go = await UIManager.Instance.ShowUINotLoading(UITypes.EventBreakChainPackPanel);
|
|
var panel = go.GetComponent<ChainPackPanel>();
|
|
panel.Init(chainPackData);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log($"[EventBreak]Pack Error: {e.Message}\n{e.StackTrace}");
|
|
}
|
|
}
|
|
|
|
private async void PlayBtnPressedAnimation()
|
|
{
|
|
btnPack.GetComponent<Animator>().Play("Pressed");
|
|
await Task.Delay(TimeSpan.FromSeconds(_jiandaButtonPressedDuration));
|
|
btnPack.GetComponent<Animator>().Play("Normal");
|
|
}
|
|
|
|
private async void OnClickInfo()
|
|
{
|
|
try
|
|
{
|
|
await UIManager.Instance.ShowUINotLoading(UITypes.EventBreakInfoPanel);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log($"[EventBreak]{e.Message}\n{e.StackTrace}");
|
|
}
|
|
}
|
|
|
|
private void HandleBlockEvent(EventBreakBlockInput e)
|
|
{
|
|
switch (e.BlockOperation)
|
|
{
|
|
case EEventBreakBlockInputOperation.Block:
|
|
BlockInput();
|
|
break;
|
|
case EEventBreakBlockInputOperation.Unblock:
|
|
UnblockInput();
|
|
break;
|
|
case EEventBreakBlockInputOperation.StrongUnblock:
|
|
UnblockInputStrong();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void BlockInput()
|
|
{
|
|
_blockCounter++;
|
|
clickMask.SetActive(true);
|
|
StartUnblockCountDown();
|
|
// Debug.Log($"[EventBreak]Block: {_blockCounter}");
|
|
}
|
|
|
|
private void UnblockInput()
|
|
{
|
|
_blockCounter--;
|
|
// Debug.Log($"[EventBreak]Unblock: {_blockCounter}");
|
|
if (_blockCounter <= 0)
|
|
{
|
|
clickMask.SetActive(false);
|
|
_blockCounter = 0;
|
|
}
|
|
}
|
|
|
|
private void UnblockInputStrong()
|
|
{
|
|
_blockCounter = 0;
|
|
clickMask.SetActive(false);
|
|
// Debug.Log($"[EventBreak]Strong Unblock: {_blockCounter}");
|
|
}
|
|
|
|
private void StartUnblockCountDown()
|
|
{
|
|
if (_unblockCoroutine != null)
|
|
StopAllCoroutines();
|
|
_unblockCoroutine = StartCoroutine(UnBlockCoroutine());
|
|
}
|
|
|
|
private IEnumerator UnBlockCoroutine()
|
|
{
|
|
yield return new WaitForSeconds(5);
|
|
clickMask.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public class EventTicketUpdate
|
|
{
|
|
}
|
|
|
|
public class EventBreakInsufficientTicket
|
|
{
|
|
}
|
|
|
|
public class EventBreakBlockInput
|
|
{
|
|
public EEventBreakBlockInputOperation BlockOperation = EEventBreakBlockInputOperation.Block;
|
|
public EventBreakBlockInput(EEventBreakBlockInputOperation bo)
|
|
{
|
|
BlockOperation = bo;
|
|
}
|
|
}
|
|
public enum EEventBreakBlockInputOperation
|
|
{
|
|
Block,
|
|
Unblock,
|
|
StrongUnblock
|
|
} |