Files
ft/Client/Assets/Scripts/UI/JigsawPuzzle/JigsawPuzzlePieceChangedPanel.cs
2026-06-29 21:18:33 +08:00

102 lines
3.8 KiB
C#

using System;
using asap.core;
using GameCore;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.UI.JigsawPuzzle
{
public class JigsawPuzzlePieceChangedPanel : BasePanel
{
#region
[SerializeField, Min(0)]
private float delayCloseTime = 1f;
[Header("rewardFly")]
[SerializeField, Min(0)] private float rewardFlyStartIconSize = 180f;
[SerializeField, Min(0)] private float rewardFlyTargetIconSize = 100f;
[SerializeField, Min(0)] private float rewardFlyEndAwaitTime = 0.2f;
#endregion
private Image icon_piece;
private RewardFlyBatchController RewardFlyBatchCtrl;
private Animation showAni;
private string flyTrailName = "fx_ui_jigsawpuzzlebuilding_piece_flytrail0";
private void Awake()
{
icon_piece = gameObject.FindChildGameObject(nameof(icon_piece)).GetComponent<Image>();
showAni = this.GetComponent<Animation>();
}
public async Task ShowUI(int indexFrom1, RectTransform targetRect, int toggleIndex, RewardFlyBatchController RewardFlyBatchCtrl,int showPieceChangePanelCount)
{
try
{
this.RewardFlyBatchCtrl = RewardFlyBatchCtrl;
var pcitureName = $"{JigsawPuzzleManager.PriceImgName}{indexFrom1}";
_ = GContext.container.Resolve<IUIService>().SetImageSprite(icon_piece, pcitureName);
showAni.Play("piece_change");
await Awaiters.Seconds(delayCloseTime);
await PlayRewardFly(pcitureName, targetRect, toggleIndex);
var uiType = new UIType("EventJigsawPuzzlePieceChangePopupPanel").SetName($"EventJigsawPuzzlePieceChangePopupPanel_{showPieceChangePanelCount}");
UIManager.Instance.DestroyUI(uiType);
}
catch (Exception e)
{
Debug.LogError(e);
}
}
private async Task PlayRewardFly(string pictureName, RectTransform targetRect, int toggleIndex)
{
try
{
this.gameObject?.FindChildGameObject("root")?.SetActive(false);
if (this.RewardFlyBatchCtrl.animationParamList is not { Length: > 0 })
{
Debug.LogError($"{this.GetType().Name} RewardFlyBatchCtrl.animationParamList is null");
return;
}
var aniParam = this.RewardFlyBatchCtrl.animationParamList[0];
if (aniParam.FxSingle == null || aniParam.FxSingle.Length < 2)
{
Debug.LogError(
$"{this.GetType().Name} RewardFlyBatchCtrl.animationParamList aniParam.FxSingle is null");
return;
}
aniParam.FxSingle[1] = $"{flyTrailName}{toggleIndex + 1}";
var request = new BatchedRewardFlyRequest
{
Icon = new BatchedRewardFlyRequestIcon
{
iconName = pictureName
},
StartPoint = new BatchedRewardFlyStartPoint(icon_piece.rectTransform),
EndPoint = new BatchedRewardFlyEndPoint(targetRect.position, rewardFlyTargetIconSize,
UIManager.Instance.transform.lossyScale.x),
IsDestinationRewardStash = true,
AnimationParamIndex = 0,
};
await this.RewardFlyBatchCtrl.OnRewardFlyRequestAsync(request);
await Awaiters.Seconds(rewardFlyEndAwaitTime);
}
catch (Exception e)
{
Debug.LogError(e);
}
}
protected override void OnDestroy()
{
base.OnDestroy();
}
}
}