备份CatanBuilding瘦身独立工程
This commit is contained in:
64
Assets/Scripts/EventGatherCore/EventGatherCoreTriggerView.cs
Normal file
64
Assets/Scripts/EventGatherCore/EventGatherCoreTriggerView.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using asap.core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class EventGatherCoreTriggerView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Button btn;
|
||||
[SerializeField] private Animation ani;
|
||||
private IEventAggregator _eventAggregator;
|
||||
private int _idx;
|
||||
private float _showDuration;
|
||||
private readonly string AnimationShow = "football_show";
|
||||
|
||||
private void Start()
|
||||
{
|
||||
btn.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
public void Init(int index, bool isUsed, float showDuration, IEventAggregator eventAggregator)
|
||||
{
|
||||
// Debug.Log($"[EventGatherCore] Init: {isUsed}]", this);
|
||||
Set(isUsed);
|
||||
_eventAggregator = eventAggregator;
|
||||
_idx = index;
|
||||
_showDuration = showDuration;
|
||||
}
|
||||
|
||||
public void Set(bool isUsed)
|
||||
{
|
||||
if (!isUsed && !gameObject.activeSelf)
|
||||
{
|
||||
ani.Play(AnimationShow);
|
||||
}
|
||||
gameObject.SetActive(!isUsed);
|
||||
}
|
||||
|
||||
private async void OnClick()
|
||||
{
|
||||
try
|
||||
{
|
||||
var res = EventGatherCoreSystem.Draw(_idx, out int rewardIdx, out int rewardId);
|
||||
_eventAggregator.Publish(
|
||||
new EventGatherCoreTriggerTaken()
|
||||
{
|
||||
Succeeded = res,
|
||||
RewardIdx = rewardIdx,
|
||||
Position = btn.transform.position,
|
||||
RewardId = rewardId,
|
||||
});
|
||||
// Debug.Log($"[EventGatherCore] Trigger Click: {_showDuration}", this);
|
||||
if (!res)
|
||||
{
|
||||
return;
|
||||
}
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(_showDuration));
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log($"[EventGatherCore] Trigger Click Error:{e.Message}\n{e.StackTrace}", this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user