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 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(); ShootingRangeAct.EventAggregator.GetEvent().Subscribe(_ => UpdateAmmoCount()) .AddTo(this); _data = GContext.container.Resolve(); rewardTip.Init(GContext.container.Resolve() .GetItemDataByDropId(_tables.TbEventShootingRangeStage[_data.EventShootingRange.StageList[^1]].DropId[0])); _ammoCountDisplay = _data.AmmoCount; GContext.container.Resolve().InspectTriggerGuide(gameObject.name); InitTaskBubble(); SetRewards(); GContext.container.Resolve().SetImageSprite(iconAmmo, GContext.container.Resolve().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().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().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]); } } /// /// Will decrease ammo display by consumedAmmo if consumedAmmo is not 0, regardless of actual ammo count. Otherwise, will update actual ammo count. /// /// Set to 0 if needing to update actual ammo number, or else. 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(), 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(); var rewardRect = Instantiate(rewardFlyInstance.gameObject, transform).GetComponent(); var rewardFly = rewardRect.gameObject.GetComponent(); 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().Play("reward_common_open"); await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(jiandaRewardCloseAnimationDelay)); rewardFly.GetComponent().Play("reward_common_close"); await System.Threading.Tasks.Task.Delay(24 * 1000 / 60); rewardFly.GetComponent().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().Play("reward_common_open"); await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(jiandaRewardCloseAnimationDelay)); rewardFly.GetComponent().Play("reward_common_close"); await System.Threading.Tasks.Task.Delay(5 * 1000 / 60); Debug.Log($"reward id: {item.id}"); 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); } }