100 lines
3.3 KiB
C#
100 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using asap.core;
|
|
using game;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace EventMowForTreasure
|
|
{
|
|
public class EventMowForTreasureEntranceButton : EventButtonResource
|
|
{
|
|
[SerializeField] private TMP_Text textTimer;
|
|
[SerializeField] private Button btn;
|
|
[SerializeField] private Image icon;
|
|
private IDisposable _disposable;
|
|
|
|
private EventMowForTreasureManager _eventMowForTreasureManager;
|
|
|
|
private EventMowForTreasureManager EventMowForTreasureManager => _eventMowForTreasureManager ??=
|
|
GContext.container.Resolve<EventMowForTreasureManager>();
|
|
|
|
private EventMowForTreasureData Data => EventMowForTreasureManager?.Data;
|
|
|
|
private void Awake()
|
|
{
|
|
if (!textTimer)
|
|
textTimer = gameObject.FindChildGameObject("text_time").GetComponent<TMP_Text>();
|
|
if (!btn)
|
|
btn = gameObject.GetComponent<Button>();
|
|
if (!icon)
|
|
icon = gameObject.FindChildGameObject("icon_task").GetComponent<Image>();
|
|
gameObject.SetActive(false);
|
|
btn.onClick.AddListener(OnEnterPanel);
|
|
if (Data?.EventMain == null) return;
|
|
var prefabs = new List<string>
|
|
{
|
|
Data.EventMain.UIPanel,
|
|
Data.EventMain.InfoPanel,
|
|
Data.EventMain.Icon,
|
|
EventMowForTreasureManager.GetCurrentStageAct()
|
|
};
|
|
foreach (var item in EventMowForTreasureManager.GetCurrentStageItemDir())
|
|
{
|
|
var config = Data.Tables.TbEventMowForTreasureStageItem.GetOrDefault(item.Value);
|
|
if (config != null && !string.IsNullOrEmpty(config.Prefab))
|
|
prefabs.Add(config.Prefab);
|
|
}
|
|
|
|
foreach (var toolID in Data.EventMain.ToolConfigList)
|
|
{
|
|
var toolConfig = Data.Tables.TbEventMowForTreasureTool.GetOrDefault(toolID);
|
|
if (toolConfig != null) prefabs.Add(toolConfig.Prefab);
|
|
}
|
|
|
|
CheckResource(prefabs);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
UpdateTimer();
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
_disposable?.Dispose();
|
|
}
|
|
|
|
private void UpdateTimer(long _ = 0L)
|
|
{
|
|
gameObject.SetActive(IsShowBtn());
|
|
textTimer.text = ConvertTools.ConvertTime2(EventMowForTreasureManager?.Data.RemainingTime ?? TimeSpan.Zero);
|
|
}
|
|
|
|
private void OnEnterPanel()
|
|
{
|
|
OnEnterActAsync();
|
|
}
|
|
|
|
private bool IsShowBtn()
|
|
{
|
|
return Data?.IsActive ?? false;
|
|
}
|
|
|
|
protected override void OnLoadEventResource()
|
|
{
|
|
_disposable = Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this);
|
|
gameObject.SetActive(IsShowBtn());
|
|
if (Data?.EventMain == null) return;
|
|
_ = GContext.container.Resolve<IUIService>().SetImageSprite(icon, Data.EventMain.Icon);
|
|
}
|
|
|
|
private void OnEnterActAsync()
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct { actId = EventMowForTreasureManager.GetCurrentStageAct() });
|
|
}
|
|
}
|
|
} |