152 lines
5.3 KiB
C#
152 lines
5.3 KiB
C#
using System;
|
|
using asap.core;
|
|
using GameCore;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UniRx;
|
|
using asap.core.common;
|
|
|
|
public class DeferredRewardStashButton : MonoBehaviour
|
|
{
|
|
private Button _btn;
|
|
private DeferredRewardStashPanel _panel;
|
|
private Animation _animation;
|
|
public RectTransform Icon;
|
|
private IObjectPoolService _objectPoolService;
|
|
[Tooltip("Empty for old, filled with batched controller for new")]
|
|
[SerializeField] private RewardFlyBatchController _rewardFlyBatchController;
|
|
|
|
protected virtual void Awake()
|
|
{
|
|
_btn = GetComponent<Button>();
|
|
_panel = transform.Find("EventBagRewardPopupPanel").GetComponent<DeferredRewardStashPanel>();
|
|
_panel.gameObject.SetActive(false);
|
|
if (_btn != null)
|
|
_btn.onClick.AddListener(OnClick);
|
|
_animation = GetComponent<Animation>();
|
|
_objectPoolService = GContext.container.Resolve<IObjectPoolService>();
|
|
GContext.OnEvent<EventRewardFlyStashRequest>().Subscribe(OnRewardFlyRequest).AddTo(this);
|
|
}
|
|
|
|
private void OnClick()
|
|
{
|
|
if (GContext.container.Resolve<IDeferredRewardStashService>().IsEmpty)
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_EventWinterShootingPanel_11"));
|
|
else
|
|
_panel.gameObject.SetActive(true);
|
|
}
|
|
|
|
public async void PlayReceiveAnimationWithDelay(float delay)
|
|
{
|
|
try
|
|
{
|
|
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(delay));
|
|
_animation.Play("fx_anim_wintershooting_pack_01");
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log($"{e.Message}\n{e.StackTrace}", this);
|
|
}
|
|
}
|
|
|
|
private async void OnRewardFlyRequest(EventRewardFlyStashRequest e)
|
|
{
|
|
try
|
|
{
|
|
var collectionItemFly = new CollectionItemFly
|
|
{
|
|
itemID = e.Reward.id,
|
|
numStr = $"x{ConvertTools.GetNumberString((int)e.Reward.count)}",
|
|
sourcePos = e.SourceIconRt.position,
|
|
destPos = Icon.position,
|
|
scale = transform.localScale,
|
|
isPlayOpen = e.DoesPlayOpen,
|
|
isPlayClose = true,
|
|
isDestinationRewardStash = true,
|
|
targetIconSize = Icon.rect.width,
|
|
sourceIconSize = e.SourceIconRt.rect.width,
|
|
};
|
|
|
|
var rewardFlyRequest = new BatchedRewardFlyRequest
|
|
{
|
|
itemID = e.Reward.id,
|
|
Quantity = e.Reward.count,
|
|
StartPoint = new BatchedRewardFlyPoint(e.SourceIconRt),
|
|
EndPoint = new BatchedRewardFlyPoint(Icon),
|
|
isDestinationRewardStash = true,
|
|
sourceTextRt = e.SourceTextRt
|
|
};
|
|
|
|
if (_rewardFlyBatchController != null)
|
|
{
|
|
await _rewardFlyBatchController.OnRewardFlyRequestAsync(rewardFlyRequest);
|
|
PlayReceiveAnimationWithDelay(0);
|
|
}
|
|
else
|
|
{
|
|
var pool = _objectPoolService.GetPool(typeof(RewardFly));
|
|
var rewardFly = pool.SpawnObject() as RewardFly;
|
|
rewardFly.gameObject.SetActive(true);
|
|
await rewardFly.ShowAsync(collectionItemFly);
|
|
pool.DespawnObject(rewardFly);
|
|
PlayReceiveAnimationWithDelay(0);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.Log($"[Deferred Reward Stash Button] : Error");
|
|
Debug.LogError(ex);
|
|
}
|
|
}
|
|
|
|
public async System.Threading.Tasks.Task OnRewardFlyRequestAsync(EventRewardFlyStashRequest e)
|
|
{
|
|
try
|
|
{
|
|
var collectionItemFly = new CollectionItemFly
|
|
{
|
|
itemID = e.Reward.id,
|
|
numStr = $"x{ConvertTools.GetNumberString(e.Reward.count)}",
|
|
sourcePos = e.SourceIconRt.position,
|
|
destPos = Icon.position,
|
|
scale = transform.localScale,
|
|
isPlayOpen = e.DoesPlayOpen,
|
|
isPlayClose = true,
|
|
isDestinationRewardStash = true,
|
|
targetIconSize = Icon.rect.width,
|
|
sourceIconSize = e.SourceIconRt.rect.width
|
|
};
|
|
|
|
var rewardFlyRequest = new BatchedRewardFlyRequest
|
|
{
|
|
itemID = e.Reward.id,
|
|
Quantity = e.Reward.count,
|
|
StartPoint = new BatchedRewardFlyPoint(e.SourceIconRt),
|
|
EndPoint = new BatchedRewardFlyPoint(Icon),
|
|
isDestinationRewardStash = true,
|
|
sourceTextRt = e.SourceTextRt
|
|
};
|
|
|
|
if (_rewardFlyBatchController != null)
|
|
{
|
|
await _rewardFlyBatchController.OnRewardFlyRequestAsync(rewardFlyRequest);
|
|
PlayReceiveAnimationWithDelay(0);
|
|
}
|
|
else
|
|
{
|
|
var pool = _objectPoolService.GetPool(typeof(RewardFly));
|
|
var rewardFly = pool.SpawnObject() as RewardFly;
|
|
rewardFly.gameObject.SetActive(true);
|
|
await rewardFly.ShowAsync(collectionItemFly);
|
|
pool.DespawnObject(rewardFly);
|
|
PlayReceiveAnimationWithDelay(0);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Debug.Log($"[Deferred Reward Stash Button] : Error");
|
|
Debug.LogError(ex);
|
|
}
|
|
}
|
|
}
|