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(); showAni = this.GetComponent(); } 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().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(); } } }