备份CatanBuilding瘦身独立工程
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using asap.core;
|
||||
using game;
|
||||
using GameCore;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ShootingRangeEntranceButton : EventButtonResource
|
||||
{
|
||||
[SerializeField] private TMP_Text textTimer;
|
||||
[SerializeField] private Button btn;
|
||||
[SerializeField] private Image icon;
|
||||
private EventShootingRangeData _data;
|
||||
private ILoadResourceService _loadResourceService;
|
||||
private const string ShootingRangeResourceLabel = "EventShooting";
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_data = GContext.container.Resolve<EventShootingRangeData>();
|
||||
_loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
||||
if (_data is not { IsActive: true })
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime);
|
||||
Observable.Interval(TimeSpan.FromSeconds(1.0f)).Subscribe(_ =>
|
||||
{
|
||||
textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime);
|
||||
if (_data.RemainingTime.TotalSeconds <= 0)
|
||||
gameObject.SetActive(false);
|
||||
}).AddTo(this);
|
||||
btn.onClick.AddListener(OnEnterShootingRangeAct);
|
||||
RedPointManager.Instance.SetRedPointState(EventShootingRangeData.EntranceRedPointId, _data.DoNeedEntranceRedPoint || _data.DoNeedPackRedPoint);
|
||||
CheckResource(new List<string>() { _data.ShootingRangeAct, _data.EntranceIcon });
|
||||
}
|
||||
|
||||
private void OnEnterShootingRangeAct()
|
||||
{
|
||||
try
|
||||
{
|
||||
OnEnterShootingRangeActAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log(e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private async void OnEnterShootingRangeActAsync()
|
||||
{
|
||||
//TODO: Will have different bundles in the future.
|
||||
bool isReady = await _loadResourceService.Load(_data.ShootingRangeAct);
|
||||
if (isReady)
|
||||
{
|
||||
Debug.Log($"<color=#22a6f2>[Shooting Range] Download Ready!</color>");
|
||||
GContext.Publish(new UnloadActToNextAct
|
||||
{ actId = _data.ShootingRangeAct, TransitionPanel = UITypes.ShootingRangeTransitionPanel });
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"<color=#22a6f2>[Shooting Range] Download Not Ready!</color>");
|
||||
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
||||
panel.GetComponent<CloudTransitionPanel>().SetBtn(true,
|
||||
() => GContext.Publish(new UnloadActToNextAct(_data.ShootingRangeAct)));
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnLoadEventResource()
|
||||
{
|
||||
if (_data != null && _data.RemainingTime.TotalSeconds > 0)
|
||||
{
|
||||
_ = GContext.container.Resolve<IUIService>().SetImageSprite(icon, _data.EntranceIcon);
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user