备份CatanBuilding瘦身独立工程
This commit is contained in:
242
Assets/Scripts/UI/ShootingRange/WinterShootingRangePanel.cs
Normal file
242
Assets/Scripts/UI/ShootingRange/WinterShootingRangePanel.cs
Normal file
@@ -0,0 +1,242 @@
|
||||
using asap.core;
|
||||
using game;
|
||||
using GameCore;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using cfg;
|
||||
using DG.Tweening;
|
||||
using Game;
|
||||
using RectTransform = UnityEngine.RectTransform;
|
||||
|
||||
public class WinterShootingRangePanel : MonoBehaviour
|
||||
{
|
||||
#region UI_ELEMENTS
|
||||
|
||||
[SerializeField] private Image barStageProgress, iconAmmo, iconPack;
|
||||
[SerializeField] private TMP_Text textStageProgress, textTimer, textAmmoCount;
|
||||
[SerializeField] private Button btnClose, btnSupply, btnInfo, btnTopPrize, btnAmmoTip;
|
||||
[SerializeField] private List<RewardItemNew> rewards;
|
||||
[SerializeField] private RectTransform scopeRect, stashRect, snowManRect, snowManTargetIcon;
|
||||
[SerializeField] private RewardItemNew rewardFlyInstance;
|
||||
[SerializeField] private ShootingRangeRewardTip rewardTip;
|
||||
[SerializeField] private GameObject ticketTip;
|
||||
[SerializeField] private DeferredRewardStashButton rewardStashButton;
|
||||
|
||||
#endregion
|
||||
|
||||
private EventShootingRangeData _data;
|
||||
|
||||
private const float ProgressIncGap = 0.8f;
|
||||
|
||||
[Tooltip("奖励飞入背包后背包响应延迟,从奖励粒子特效出现开始计算,不是从奖励出现、消失动画开始计算")] [SerializeField]
|
||||
private float jiandaBagPackResponseDelay = 1.0f;
|
||||
[Tooltip("从奖励出现动画开始播放到奖励消失动画开始播放的时间差")] [SerializeField]
|
||||
private float jiandaRewardCloseAnimationDelay = 0.8f;
|
||||
|
||||
private int _ammoCountDisplay;
|
||||
|
||||
// private int _stageIdx;
|
||||
private Tables _tables;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
btnClose.onClick.AddListener(OnClickClose);
|
||||
btnInfo.onClick.AddListener(OnClickInfo);
|
||||
btnSupply.onClick.AddListener(OnClickSupply);
|
||||
btnTopPrize.onClick.AddListener(() => rewardTip.gameObject.SetActive(true));
|
||||
btnAmmoTip.onClick.AddListener(ShowAmmoTip);
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
ShootingRangeAct.EventAggregator.GetEvent<ShootingRangeAct.EventAmmoBought>().Subscribe(_ => UpdateAmmoCount())
|
||||
.AddTo(this);
|
||||
_data = GContext.container.Resolve<EventShootingRangeData>();
|
||||
rewardTip.Init(GContext.container.Resolve<PlayerItemData>()
|
||||
.GetItemDataByDropId(_tables.TbEventShootingRangeStage[_data.EventShootingRange.StageList[^1]].DropId[0]));
|
||||
_ammoCountDisplay = _data.AmmoCount;
|
||||
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide(gameObject.name);
|
||||
InitTaskBubble();
|
||||
SetRewards();
|
||||
GContext.container.Resolve<IUIService>().SetImageSprite(iconAmmo,
|
||||
GContext.container.Resolve<Tables>().GetItemIconName(_data.CycleItem.ItemId));
|
||||
UpdateAmmoCount();
|
||||
textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime);
|
||||
Observable.Interval(TimeSpan.FromSeconds(1.0f)).Subscribe(_ =>
|
||||
{
|
||||
textTimer.text =
|
||||
ConvertTools.ConvertTime2(_data.RemainingTime.TotalSeconds <= 0
|
||||
? TimeSpan.Zero
|
||||
: _data.RemainingTime);
|
||||
}).AddTo(this);
|
||||
rewardFlyInstance.gameObject.SetActive(false);
|
||||
snowManRect.gameObject.SetActive(false);
|
||||
GContext.container.Resolve<IUIService>().SetImageSprite(iconPack, _data.PackIcon);
|
||||
RedPointManager.Instance.SetRedPointState(EventShootingRangeData.PackRedPointId, _data.DoNeedPackRedPoint);
|
||||
}
|
||||
|
||||
public void OnClickSupply()
|
||||
{
|
||||
_ = UIManager.Instance.ShowUI(_data.IsChainPackDepleted
|
||||
? UITypes.ShootingNormalPackPanel
|
||||
: UITypes.ShootingChainPackPanel);
|
||||
}
|
||||
|
||||
private void OnClickInfo()
|
||||
{
|
||||
_ = UIManager.Instance.ShowUILoad(UITypes.ShootingRangeInfoPanel);
|
||||
}
|
||||
|
||||
public void OnClickClose()
|
||||
{
|
||||
UIManager.Instance.DestroyUI(UITypes.EventWinterShootingPanel);
|
||||
GContext.Publish(new UnloadActToNextAct { TransitionPanel = UITypes.ShootingRangeTransitionPanel });
|
||||
}
|
||||
|
||||
private void InitTaskBubble()
|
||||
{
|
||||
// _stageIdx = _data.CurrentStageIdx;
|
||||
barStageProgress.fillAmount = (float)_data.CurrentStageIdx / _data.EventShootingRange.StageList.Count;
|
||||
textStageProgress.text = $"{_data.CurrentStageIdx}/{_data.EventShootingRange.StageList.Count}";
|
||||
}
|
||||
|
||||
public void UpdateTaskBubble()
|
||||
{
|
||||
// _stageIdx = _data.CurrentStageIdx;
|
||||
barStageProgress.DOFillAmount((float)_data.CurrentStageIdx / _data.EventShootingRange.StageList.Count,
|
||||
ProgressIncGap);
|
||||
textStageProgress.text = $"{_data.CurrentStageIdx}/{_data.EventShootingRange.StageList.Count}";
|
||||
}
|
||||
|
||||
public void SetRewards()
|
||||
{
|
||||
var items = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(_data.CurrentStage.DropId[0]);
|
||||
for (int i = 0; i < rewards.Count; i++)
|
||||
{
|
||||
if (i >= items.Count)
|
||||
rewards[i].gameObject.SetActive(false);
|
||||
else
|
||||
rewards[i].SetData(items[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Will decrease ammo display by consumedAmmo if consumedAmmo is not 0, regardless of actual ammo count. Otherwise, will update actual ammo count.
|
||||
/// </summary>
|
||||
/// <param name="consumedAmmo">Set to 0 if needing to update actual ammo number, or else.</param>
|
||||
public void UpdateAmmoCount(int consumedAmmo = 0)
|
||||
{
|
||||
if (consumedAmmo == 0)
|
||||
_ammoCountDisplay = _data.AmmoCount;
|
||||
else
|
||||
_ammoCountDisplay -= consumedAmmo;
|
||||
textAmmoCount.text = _ammoCountDisplay.ToString();
|
||||
textAmmoCount.color = _data.AmmoCount < ShootingRangeAct.AmmoCost ? Color.red : Color.white;
|
||||
}
|
||||
|
||||
// private Vector2 _localHitPosition;
|
||||
public Vector2 GetUiHitPosition(GameObject target)
|
||||
{
|
||||
// Vector2 localHitPosition = ConvertTools.WorldToScreenPoint(target.transform.position);
|
||||
// Debug.Log($"localHitPosition leyuan: {localHitPosition}");
|
||||
var screenPoint = RectTransformUtility.WorldToScreenPoint(Camera.main, target.transform.position);
|
||||
// Debug.Log($"ScreenPoint: {screenPoint}");
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(GetComponent<RectTransform>(), screenPoint,
|
||||
Camera.main, out var localHitPosition);
|
||||
// Debug.Log($"localHitPosition: {localHitPosition}");
|
||||
return localHitPosition;
|
||||
}
|
||||
|
||||
public async System.Threading.Tasks.Task ShowCrosshairAfterDelay(Vector3 pos, float delay)
|
||||
{
|
||||
scopeRect.gameObject.SetActive(false);
|
||||
scopeRect.position = pos;
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(delay));
|
||||
scopeRect.gameObject.SetActive(true);
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(1f));
|
||||
scopeRect.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
[SerializeField] private float jiandaRewardFlyDuration = 0.5f;
|
||||
|
||||
public async System.Threading.Tasks.Task PlayRewardFlyWithDelay(ItemData item, Vector2 pos, float delay)
|
||||
{
|
||||
// var rewardRect = rewardFly.gameObject.GetComponent<RectTransform>();
|
||||
var rewardRect = Instantiate(rewardFlyInstance.gameObject, transform).GetComponent<RectTransform>();
|
||||
var rewardFly = rewardRect.gameObject.GetComponent<RewardItemNew>();
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(delay));
|
||||
rewardFly.SetRewardPopupData(item);
|
||||
rewardRect.position = pos;
|
||||
rewardFly.gameObject.SetActive(true);
|
||||
if (_tables.TbItem[item.id].Type == 5)
|
||||
{
|
||||
rewardFly.GetComponent<Animation>().Play("reward_common_open");
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(jiandaRewardCloseAnimationDelay));
|
||||
rewardFly.GetComponent<Animation>().Play("reward_common_close");
|
||||
await System.Threading.Tasks.Task.Delay(24 * 1000 / 60);
|
||||
rewardFly.GetComponent<CanvasGroup>().alpha = 1;
|
||||
await Awaiters.NextFrame;
|
||||
_ = PlayFishCardBundleAudio();
|
||||
await DOTween
|
||||
.To(() => rewardRect.localPosition, value => rewardRect.localPosition = value, stashRect.localPosition,
|
||||
jiandaRewardFlyDuration).AsyncWaitForCompletion();
|
||||
rewardStashButton.PlayReceiveAnimationWithDelay(0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
rewardFly.GetComponent<Animation>().Play("reward_common_open");
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(jiandaRewardCloseAnimationDelay));
|
||||
rewardFly.GetComponent<Animation>().Play("reward_common_close");
|
||||
await System.Threading.Tasks.Task.Delay(5 * 1000 / 60);
|
||||
Debug.Log($"<color=#f18c0a>reward id: {item.id}</color>");
|
||||
if (item.id != _data.AmmoId)
|
||||
rewardStashButton.PlayReceiveAnimationWithDelay(jiandaBagPackResponseDelay);
|
||||
if (item.id == _data.AmmoId)
|
||||
{
|
||||
_ = UpdateAmmoCountAfterDelay(1.0f);
|
||||
}
|
||||
await rewardFly.ParticleAttractor();
|
||||
}
|
||||
|
||||
Destroy(rewardFly.gameObject);
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task PlayFishCardBundleAudio()
|
||||
{
|
||||
GContext.Publish(new EventUISound("audio_ui_shooting_winter_rewardfly"));
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(0.25f));
|
||||
GContext.Publish(new EventUISound("audio_ui_shooting_winter_rewardget"));
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task UpdateAmmoCountAfterDelay(float delay)
|
||||
{
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(delay));
|
||||
UpdateAmmoCount();
|
||||
}
|
||||
|
||||
public async System.Threading.Tasks.Task ShowSnowmanAfterDelay(Vector3 pos, float delay)
|
||||
{
|
||||
snowManRect.position = pos;
|
||||
snowManRect.localScale = Vector3.one;
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(delay));
|
||||
snowManRect.gameObject.SetActive(true);
|
||||
// GContext.Publish(new EventUISound("audio_ui_reward_icon_1"));
|
||||
}
|
||||
|
||||
public async System.Threading.Tasks.Task MoveSnowmanAfterDelayAndUpdateTarget(float delay)
|
||||
{
|
||||
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(delay));
|
||||
snowManRect.DOScale(0.5f, jiandaRewardFlyDuration);
|
||||
await DOTween
|
||||
.To(() => snowManRect.position, value => snowManRect.position = value,
|
||||
snowManTargetIcon.position, jiandaRewardFlyDuration).AsyncWaitForCompletion();
|
||||
snowManRect.gameObject.SetActive(false);
|
||||
UpdateTaskBubble();
|
||||
}
|
||||
|
||||
public void ShowAmmoTip()
|
||||
{
|
||||
ticketTip.SetActive(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user