181 lines
7.0 KiB
C#
181 lines
7.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using asap.core;
|
|
using cfg;
|
|
using DG.Tweening;
|
|
using game;
|
|
using Game;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace EventMowForTreasure
|
|
{
|
|
public class EventMowForTreasure_CollectionCell : MonoBehaviour
|
|
{
|
|
#region MyRegion
|
|
|
|
[SerializeField] private float progressTime = 0.3f;
|
|
[SerializeField] private float targetIconSize = 115.2f;
|
|
[SerializeField] private float startIconSize = 256f;
|
|
#endregion
|
|
#region UI
|
|
|
|
private Image _collectIcon;
|
|
private RewardItemNew _reward;
|
|
private Image _imageProgress;
|
|
private TMP_Text _textProgress;
|
|
private GameObject _fxReward;
|
|
private GameObject _fxCollect;
|
|
#endregion
|
|
|
|
private RewardFlyBatchController _batchController;
|
|
private EventMowForTreasureCollectionData _collectionData;
|
|
private List<ItemData> _itemDatas;
|
|
private int _index;
|
|
|
|
private void Awake()
|
|
{
|
|
_collectIcon = gameObject.FindChildGameObject("collect_icon").GetComponent<Image>();
|
|
_reward = gameObject.FindChildGameObject("reward").GetComponent<RewardItemNew>();
|
|
_imageProgress = gameObject.FindChildGameObject("image_progress").GetComponent<Image>();
|
|
_textProgress = gameObject.FindChildGameObject("text_progress").GetComponent<TMP_Text>();
|
|
_fxReward = gameObject.FindChildGameObject("fx_ui_mowForTreasure_pumpkin_reward");
|
|
_fxCollect = gameObject.FindChildGameObject("fx_ui_mowForTreasure_pumpkin_collect");
|
|
InitUI();
|
|
}
|
|
|
|
private void InitUI()
|
|
{
|
|
SetActive_FxReward(false);
|
|
SetActive_FxCollect(false);
|
|
_imageProgress.fillAmount = 0;
|
|
_textProgress.text = string.Empty;
|
|
}
|
|
|
|
public void SetData( EventMowForTreasureCollectionData collectionData,List<ItemData> itemDatas,
|
|
RewardFlyBatchController batchController = null,CompositeDisposable disposables = null)
|
|
{
|
|
_collectionData = collectionData;
|
|
_itemDatas = itemDatas;
|
|
_batchController = batchController;
|
|
if (disposables != null)
|
|
{
|
|
GContext.OnEvent<EventMowForTreasureCollectionData>().Subscribe(OnEventCollectionChanged)
|
|
.AddTo(disposables);
|
|
GContext.OnEvent<RewardPanelClose>().Subscribe(OnRewardPanelClose).AddTo(disposables);
|
|
}
|
|
|
|
ShowUI();
|
|
}
|
|
|
|
private void ShowUI(bool isPlayProgressAni=false)
|
|
{
|
|
SetActive_FxReward(false);
|
|
SetActive_FxCollect(false);
|
|
var isNull=_collectionData==null;
|
|
gameObject.SetActive(!isNull);
|
|
if (_collectionData==null) return;
|
|
var collectionConfig = _collectionData.CollectionConfig;
|
|
var currentAmount = _collectionData?.Amount ?? 0;
|
|
var currentFillAmount = (float)currentAmount / collectionConfig.CollectingRequirement;
|
|
if (isPlayProgressAni)
|
|
{
|
|
PlayEffect(currentFillAmount,currentAmount,collectionConfig);
|
|
}
|
|
else
|
|
{
|
|
_imageProgress.fillAmount =currentFillAmount;
|
|
_textProgress.text = $"{currentAmount}/{collectionConfig.CollectingRequirement}";
|
|
}
|
|
_reward.SetData(_itemDatas.FirstOrDefault());
|
|
_ = GContext.container.Resolve<IUIService>().SetImageSprite(_collectIcon, collectionConfig.CollectingIcon);
|
|
}
|
|
|
|
private async void PlayEffect(float currentFillAmount,int currentAmount,EventMowForTreasureCollection collectionConfig)
|
|
{
|
|
try
|
|
{
|
|
if (_collectionData?.IsObtainReward ?? false)
|
|
{
|
|
SetActive_FxReward(true);
|
|
SetActive_FxCollect(true);
|
|
await _imageProgress.DOFillAmount(1, progressTime).AsyncWaitForCompletion();
|
|
_textProgress.text = $"{collectionConfig.CollectingRequirement}/{collectionConfig.CollectingRequirement}";
|
|
GContext.Publish(new ShowData());
|
|
return;
|
|
}
|
|
|
|
SetActive_FxReward(true);
|
|
GContext.Publish(new EventUISound("audio_ui_mowfortreasure_pumpkin_collect"));
|
|
await _imageProgress.DOFillAmount(currentFillAmount, progressTime).AsyncWaitForCompletion();
|
|
_textProgress.text = $"{currentAmount}/{collectionConfig.CollectingRequirement}";
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
private void OnRewardPanelClose(RewardPanelClose e)
|
|
{
|
|
if(_collectionData==null) return;
|
|
if (!_collectionData.IsObtainReward) return;
|
|
var collectionConfig = _collectionData.CollectionConfig;
|
|
var currentAmount = _collectionData?.Amount ?? 0;
|
|
_imageProgress.fillAmount=0;
|
|
_textProgress.text = $"{currentAmount}/{collectionConfig.CollectingRequirement}";
|
|
_collectionData.IsObtainReward = false;
|
|
}
|
|
private void OnEventCollectionChanged(EventMowForTreasureCollectionData data)
|
|
{
|
|
if (data.CollectionID != _collectionData.CollectionID)
|
|
return;
|
|
if (data.IsPlayReward)
|
|
{
|
|
data.PlayRewardFly = PlayCollectionRewardFly(data);
|
|
data.IsPlayReward = false;
|
|
return;
|
|
}
|
|
|
|
if (!data.IsRefresh) return;
|
|
data.IsRefresh = false;
|
|
ShowUI(true);
|
|
}
|
|
|
|
private async Task PlayCollectionRewardFly(EventMowForTreasureCollectionData collectionData)
|
|
{
|
|
if (_batchController == null) return;
|
|
var collectionConfig = collectionData.CollectionConfig;
|
|
if (collectionConfig == null) return;
|
|
var request = new BatchedRewardFlyRequest
|
|
{
|
|
Icon = new BatchedRewardFlyRequestIcon
|
|
{
|
|
iconName = collectionConfig.CollectingIcon
|
|
},
|
|
StartPoint = new BatchedRewardFlyStartPoint(collectionData.Position, startIconSize),
|
|
EndPoint = new BatchedRewardFlyEndPoint(_collectIcon.transform.position, targetIconSize,
|
|
UIManager.Instance.transform.lossyScale.x),
|
|
IsDestinationRewardStash = true,
|
|
AnimationParamIndex = 0
|
|
};
|
|
await _batchController.OnRewardFlyRequestAsync(request);
|
|
collectionData.PlayRewardFly = null;
|
|
}
|
|
|
|
private void SetActive_FxReward(bool isActive)
|
|
{
|
|
if(_fxReward)
|
|
_fxReward?.SetActive(isActive);
|
|
}
|
|
private void SetActive_FxCollect(bool isActive)
|
|
{
|
|
if(_fxCollect)
|
|
_fxCollect?.SetActive(isActive);
|
|
}
|
|
}
|
|
} |