备份CatanBuilding瘦身独立工程
This commit is contained in:
78
Assets/Scripts/EventGatherCore/EventGatherCoreEntranceBtn.cs
Normal file
78
Assets/Scripts/EventGatherCore/EventGatherCoreEntranceBtn.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using UnityEngine.UI;
|
||||
using UniRx;
|
||||
using asap.core;
|
||||
using game;
|
||||
using GameCore;
|
||||
|
||||
public class EventGatherCoreEntranceBtn : EventButtonResource
|
||||
{
|
||||
[SerializeField] private TMP_Text textTimer;
|
||||
[SerializeField] private Button button;
|
||||
[SerializeField] private Image icon;
|
||||
private ILoadResourceService _loadResourceService;
|
||||
private EventBingoEntranceData _data;
|
||||
private TimeSpan RemainingTime => _data.ExpiryTime - ZZTimeHelper.UtcNow();
|
||||
private bool IsActive => _data.ExpiryTime > ZZTimeHelper.UtcNow() && ZZTimeHelper.UtcNow() > _data.StartTime;
|
||||
private const string RedPointKey = "event_gather_core.entrance";
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
var model = GContext.container.Resolve<EventGatherCoreData>();
|
||||
if (model == null)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
_data = model.ToEntranceData();
|
||||
UpdateTimer();
|
||||
Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this);
|
||||
_loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
||||
button.onClick.AddListener(EnterActAsync);
|
||||
RedPointManager.Instance.SetRedPointState(RedPointKey, _data.NeedRedPoint);
|
||||
CheckResource(new List<string>() { UITypes.EventGatherCorePanel.Path, EventBingoAct.ActAddressable, _data.Icon });
|
||||
}
|
||||
|
||||
private void UpdateTimer(long _ = 0L)
|
||||
{
|
||||
textTimer.text = ConvertTools.ConvertTime2(RemainingTime);
|
||||
if (!IsActive)
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private async void EnterActAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isReady = await _loadResourceService.Loads(
|
||||
new List<string>() { UITypes.EventGatherCorePanel.Path, EventBingoAct.ActAddressable });
|
||||
if (isReady)
|
||||
{
|
||||
GContext.Publish(new UnloadActToNextAct { actId = EventGatherCoreAct.ActAddressable, TransitionPanel = UITypes.CloudTransitionPanel });
|
||||
}
|
||||
else
|
||||
{
|
||||
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
||||
panel.GetComponent<CloudTransitionPanel>()
|
||||
.SetBtn(true, () => GContext.Publish(new UnloadActToNextAct(EventBingoAct.ActAddressable)));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log($"<color=#22a6f2>[EventGatherCore] EnterActError: {e.Message}\n{e.StackTrace}</color>");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoadEventResource()
|
||||
{
|
||||
if (IsActive)
|
||||
{
|
||||
GContext.container.Resolve<IUIService>().SetImageSprite(icon, _data.Icon);
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user