236 lines
8.6 KiB
C#
236 lines
8.6 KiB
C#
using asap.core;
|
|
using DG.Tweening;
|
|
using game;
|
|
using Game;
|
|
using GameCore;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class PinataPack_PonySettlementPanel : MonoBehaviour
|
|
{
|
|
#region UI_ELEMENTS
|
|
private GameObject fingerObj;
|
|
private RectTransform leftRewardTrans;
|
|
private RectTransform rightRewardTrans;
|
|
private EventTrigger eventTrigger;
|
|
|
|
[SerializeField] private float tipsShowTime = 5f;
|
|
[SerializeField] private float clickPonyGapTime = 0.5f;
|
|
|
|
[Header("奖励")]
|
|
[SerializeField] private int leftRewardId = 1002;
|
|
[SerializeField] private Transform leftRewardPos;
|
|
[SerializeField] private Animation leftRewardAni;
|
|
[SerializeField] private int rightRewardId = 1001;
|
|
[SerializeField] private Transform rightRewardPos;
|
|
[SerializeField] private Animation rightRewardAni;
|
|
[SerializeField] private float rewardStartSize = 166f;
|
|
[SerializeField] private float rewardEndSize = 100f;
|
|
|
|
#endregion UI_ELEMENTS
|
|
|
|
private readonly string guideKey = "PinataPack";
|
|
private RewardFlyBatchController _flyBatchController;
|
|
|
|
private void Awake()
|
|
{
|
|
eventTrigger = this.transform.Find("root/btn_scene").GetComponent<EventTrigger>();
|
|
|
|
EventTrigger.Entry entry = new EventTrigger.Entry();
|
|
entry.eventID = EventTriggerType.PointerClick;
|
|
entry.callback.AddListener(OnPointerClick);
|
|
eventTrigger.triggers.Add(entry);
|
|
|
|
fingerObj = this.transform.Find("root/finger").gameObject;
|
|
fingerObj.SetActive(false);
|
|
|
|
Observable.Interval(TimeSpan.FromSeconds(clickPonyGapTime)).Subscribe(ResetClickScene).AddTo(this);
|
|
|
|
leftRewardTrans = this.transform.Find("root/basket1/reward/icon_cash").GetComponent<RectTransform>();
|
|
rightRewardTrans = this.transform.Find("root/basket2/reward/icon_lure").GetComponent<RectTransform>();
|
|
|
|
_flyBatchController = this.gameObject.FindChildGameObject("RewardFlyBatchCtrl").GetComponent<RewardFlyBatchController>();
|
|
}
|
|
|
|
public void OnDestroy()
|
|
{
|
|
playedItemId = null;
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
var eventId = GContext.container.Resolve<EventPinataPackData>().EventID;
|
|
var guideValue = PlayerPrefs.GetInt($"{guideKey}_{eventId}");
|
|
if (guideValue == 0)
|
|
{
|
|
Observable.Interval(TimeSpan.FromSeconds(tipsShowTime)).Subscribe(IsShowTips).AddTo(this);
|
|
fingerObj.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private PointerEventData _pointerEventData;
|
|
|
|
public void OnPointerClick(BaseEventData eventData)
|
|
{
|
|
_pointerEventData = eventData as PointerEventData;
|
|
_ = OnClickScene();
|
|
}
|
|
|
|
private bool _isClicking = false;
|
|
private int _clickCount = 0;
|
|
private float _clickGapTime;
|
|
private List<int> playedItemId;
|
|
|
|
private async Task OnClickScene()
|
|
{
|
|
if (_isClicking) return;
|
|
|
|
_isClicking = true;
|
|
_clickGapTime = 0;
|
|
fingerObj.SetActive(false);
|
|
|
|
EventPinataPackDataManager.GetData(out var packData, out var packMain, out _, out int clickDropId, out _);
|
|
if (packMain == null) return;
|
|
|
|
if (_clickCount > packMain.HitTimes) return;
|
|
|
|
var itemDatas = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropIdAndType(clickDropId);
|
|
if (itemDatas == null) return;
|
|
Debug.Log($"jsd itemDatas {JsonConvert.SerializeObject(itemDatas)}");
|
|
if (playedItemId == null)
|
|
playedItemId = new List<int>();
|
|
else
|
|
playedItemId.Clear();
|
|
|
|
var iAct = GContext.container.ResolveAct(packMain.ActPrefab);
|
|
if (iAct is not PinataPackAct pinataPackAct) return;
|
|
|
|
RectTransformUtility.ScreenPointToWorldPointInRectangle(this.transform as RectTransform,
|
|
_pointerEventData.position,
|
|
Camera.main,
|
|
out var worldPos);
|
|
_ = pinataPackAct.PlayClickEffect(worldPos);
|
|
_ = pinataPackAct.PlayClickPinataEffect();
|
|
_clickCount++;
|
|
if (packMain.HitTimes > _clickCount)
|
|
{
|
|
pinataPackAct.GetRewardOriginPos(out var rewardFlyOriginPos1, out var rewardFlyOriginPos2);
|
|
|
|
var hitSoundName = $"audio_ui_eventpinatapony_hit0{new System.Random().Next(1, 3)}";
|
|
GContext.Publish(new EventUISound(hitSoundName));
|
|
|
|
for (int i = 0; i < itemDatas.Count; i++)
|
|
{
|
|
var itemData = itemDatas[i];
|
|
if (playedItemId.Contains(itemData.id)) continue;
|
|
if (itemData.id != rightRewardId && itemData.id != leftRewardId) continue;
|
|
playedItemId.Add(itemData.id);
|
|
_ = PlayCilckEffect(itemData, packMain.HitTimes, rewardFlyOriginPos1, rewardFlyOriginPos2);
|
|
}
|
|
pinataPackAct.ClickPony(_clickCount);
|
|
}
|
|
else if (packMain.HitTimes == _clickCount)
|
|
{
|
|
var hitSoundName = $"audio_ui_eventpinatapony_hit0{new System.Random().Next(1, 3)}";
|
|
GContext.Publish(new EventUISound(hitSoundName));
|
|
|
|
this.GetComponent<Animation>()?.Play("ponysettlement_end");
|
|
await pinataPackAct.BombPony();
|
|
|
|
var eventId = packData.EventID;
|
|
if (PlayerPrefs.GetInt($"{guideKey}_{eventId}") == 0)
|
|
PlayerPrefs.SetInt($"{guideKey}_{eventId}", 1);
|
|
|
|
GContext.OnEvent<RewardPanelClose>().Subscribe(OnRewardPanelClose).AddTo(this);
|
|
|
|
var service = GContext.container.Resolve<IDeferredRewardStashService>();
|
|
service.Flush();
|
|
|
|
GContext.Publish(new ShowData());
|
|
}
|
|
}
|
|
|
|
private async Task PlayCilckEffect(ItemData itemData, int hitMaxs, Vector3 rewardFlyOriginPos1, Vector3 rewardFlyOriginPos2)
|
|
{
|
|
await PlayRewardFly(itemData, rewardFlyOriginPos1, rewardFlyOriginPos2);
|
|
PlayItemAddEffect(itemData, hitMaxs);
|
|
}
|
|
|
|
private async Task PlayRewardFly(ItemData itemData, Vector3 rewardFlyOriginPos1, Vector3 rewardFlyOriginPos2)
|
|
{
|
|
var isLeftReward = itemData.id == leftRewardId;
|
|
|
|
Vector3 originPosition = isLeftReward ? rewardFlyOriginPos1 : rewardFlyOriginPos2;
|
|
var uiCamera = this.GetComponentInParent<Canvas>().worldCamera;
|
|
var rect = this.transform.parent.GetComponent<RectTransform>();
|
|
var scenePos = RectTransformUtility.WorldToScreenPoint(Camera.main, originPosition);
|
|
RectTransformUtility.ScreenPointToWorldPointInRectangle(
|
|
rect,
|
|
scenePos,
|
|
uiCamera,
|
|
out originPosition);
|
|
var targetPosition = isLeftReward ? leftRewardPos.position : rightRewardPos.position;
|
|
|
|
var request = new BatchedRewardFlyRequest
|
|
{
|
|
Icon = new BatchedRewardFlyRequestIcon { itemID = itemData.id },
|
|
Quantity = itemData.count,
|
|
StartPoint = new BatchedRewardFlyStartPoint(originPosition, rewardStartSize),
|
|
EndPoint = new BatchedRewardFlyEndPoint(targetPosition, rewardEndSize, UIManager.Instance.transform.lossyScale.x),
|
|
IsDestinationRewardStash = true,
|
|
AnimationParamIndex = 0,
|
|
};
|
|
await _flyBatchController.OnRewardFlyRequestAsync(request);
|
|
}
|
|
|
|
private void PlayItemAddEffect(ItemData itemData, int hitMaxs)
|
|
{
|
|
var isLeftReward = itemData.id == leftRewardId;
|
|
if (isLeftReward)
|
|
{
|
|
leftRewardTrans.DOAnchorPosY(-212 + ((212 - 54) / hitMaxs * _clickCount), clickPonyGapTime);
|
|
leftRewardAni.Play();
|
|
}
|
|
else
|
|
{
|
|
rightRewardTrans.DOAnchorPosY(-212 + ((212 - 54) / hitMaxs * _clickCount), clickPonyGapTime);
|
|
rightRewardAni.Play();
|
|
}
|
|
}
|
|
|
|
private void OnRewardPanelClose(RewardPanelClose e)
|
|
{
|
|
_ = CloseActAndUI();
|
|
}
|
|
|
|
private async Task CloseActAndUI()
|
|
{
|
|
EventPinataPackDataManager.GetData(out var packData, out var packMain, out _, out var packConfig_Click, out _);
|
|
if (packMain == null) return;
|
|
var iAct = GContext.container.ResolveAct(packMain.ActPrefab);
|
|
if (iAct is not PinataPackAct pinataPackAct) return;
|
|
await pinataPackAct.MoveRope();
|
|
var uiTypes = UITypes.GetUIType(packMain?.GamePanel ?? nameof(PinataPack_PonySettlementPanel));
|
|
UIManager.Instance.DestroyUI(uiTypes);
|
|
GContext.Publish(new UnloadActToNextAct());
|
|
}
|
|
|
|
private void ResetClickScene(long _ = 0)
|
|
{
|
|
_isClicking = false;
|
|
_clickGapTime += clickPonyGapTime;
|
|
}
|
|
|
|
private void IsShowTips(long _ = 0)
|
|
{
|
|
if (_clickGapTime >= tipsShowTime)
|
|
{
|
|
fingerObj.SetActive(true);
|
|
}
|
|
}
|
|
} |