993 lines
34 KiB
C#
993 lines
34 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using GameCore;
|
||
using TMPro;
|
||
using System;
|
||
using cfg;
|
||
using DG.Tweening;
|
||
using asap.core;
|
||
using UniRx;
|
||
using Game;
|
||
using UnityEngine.EventSystems;
|
||
using game;
|
||
using tysdk;
|
||
using System.Threading.Tasks;
|
||
|
||
public class FishingTurntablePanel : BasePanel
|
||
{
|
||
Tables _tables;
|
||
FishingEventData _fishingEventData;
|
||
CanvasGroup canvasGroup;
|
||
public Button btn_close;
|
||
public Button btn_nextLevelInfo;
|
||
public Button btn_Info;
|
||
public UIButton btn_draw;
|
||
private PointerEventData _eventButtonDraw;
|
||
|
||
Button stopClick;
|
||
|
||
//private Button btn_beilv;
|
||
//private Button btn_beilv_max;
|
||
Button btn_levelUp;
|
||
TMP_Text text_ticket;
|
||
TMP_Text text_title;
|
||
TMP_Text text_time;
|
||
TMP_Text text_level;
|
||
TMP_Text text_progress;
|
||
Image bar;
|
||
|
||
Image Bg;
|
||
|
||
//TMP_Text text_multi;
|
||
//TMP_Text text_multi_max;
|
||
TMP_Text text_draw;
|
||
Timer timer;
|
||
List<TurntableRewardItem> rewards;
|
||
GameObject selected;
|
||
List<WheelDrop> wheelDrops;
|
||
public WheelLevel wheelLevel;
|
||
TurntableRewardItem selectedReward = null;
|
||
public bool isFree;
|
||
int multiplier = 1;
|
||
GameObject ticket;
|
||
GameObject levelUp;
|
||
GameObject wheelBg;
|
||
GameObject wheelBg_free;
|
||
GameObject bg;
|
||
GameObject bg_free;
|
||
|
||
public float gradeUp_time = 1.0f;
|
||
|
||
//private CanvasGroup beilvpanel;
|
||
//public Transform beilvpanel_max;
|
||
//public Transform bg_beilvlpanel;
|
||
//private TMP_Text text_beilvpanel_title;
|
||
//private TMP_Text text_beilvpanel_content;
|
||
//GameObject mask;
|
||
//DOTweenAnimation transitionAnimation;
|
||
Animation gradeAnimation;
|
||
Animation barAnimation;
|
||
bool needTransition = false;
|
||
int selectedIndex = 0;
|
||
bool isDataSynced = false;
|
||
int curSelectedIndex = 0;
|
||
WheelDrop selectedDrop;
|
||
Coroutine drew;
|
||
Spine.Unity.SkeletonGraphic skeletonGraphic;
|
||
RewardItemNew rewardItemNew;
|
||
|
||
GameObject fx_ui_fishingturntable_npc_01;
|
||
GameObject fx_ui_fishingturntable_change_01;
|
||
GameObject fx_ui_fishingturntable_dengdai_01;
|
||
GameObject fx_ui_fishingturntable_dengdai_02;
|
||
Animation turntable;
|
||
Button ad_btn;
|
||
[SerializeField] private Animator _animatorDrawButton;
|
||
[SerializeField] private Button _btnPack;
|
||
|
||
void Awake()
|
||
{
|
||
_tables = GContext.container.Resolve<Tables>();
|
||
_fishingEventData = GContext.container.Resolve<FishingEventData>();
|
||
canvasGroup = GetComponent<CanvasGroup>();
|
||
btn_close = transform.Find("root/btn_close").GetComponent<Button>();
|
||
btn_nextLevelInfo = transform.Find("root/turntable/btn_questionmark").GetComponent<Button>();
|
||
btn_Info = transform.Find("root/title/btn_questionmark").GetComponent<Button>();
|
||
btn_draw = transform.Find("root/turntable/btn_draw/btn_green").GetComponent<UIButton>();
|
||
stopClick = transform.Find("StopClick").GetComponent<Button>();
|
||
//btn_beilv = transform.Find("root/turntable/btn_draw/beilv").GetComponent<Button>();
|
||
//btn_beilv_max = transform.Find("root/turntable/btn_draw/beilv_max").GetComponent<Button>();
|
||
btn_levelUp = transform.Find("levelup").GetComponent<Button>();
|
||
text_ticket = transform.Find("root/turntable/icon_ticket/text_num").GetComponent<TMP_Text>();
|
||
text_title = transform.Find("root/title/text_title").GetComponent<TMP_Text>();
|
||
text_time = transform.Find("root/title/text_time").GetComponent<TMP_Text>();
|
||
text_level = transform.Find("root/turntable/grade/text_level").GetComponent<TMP_Text>();
|
||
text_progress = transform.Find("root/turntable/bg_bar/text_progress").GetComponent<TMP_Text>();
|
||
text_draw = transform.Find("root/turntable/btn_draw/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
|
||
bar = transform.Find("root/turntable/bg_bar/bar").GetComponent<Image>();
|
||
//text_multi = transform.Find("root/turntable/btn_draw/beilv/text_beilv").GetComponent<TMP_Text>();
|
||
//text_multi_max = transform.Find("root/turntable/btn_draw/beilv_max/text_beilv").GetComponent<TMP_Text>();
|
||
levelUp = transform.Find("levelup").gameObject;
|
||
ticket = transform.Find("top_area/resource/icon_ticket").gameObject;
|
||
wheelBg = transform.Find("root/turntable/bg").gameObject;
|
||
Bg = transform.Find("bg").GetComponent<Image>();
|
||
wheelBg_free = transform.Find("root/turntable/bg_free").gameObject;
|
||
bg = transform.Find("bg").gameObject;
|
||
bg_free = transform.Find("bg_free").gameObject;
|
||
rewards = new List<TurntableRewardItem>();
|
||
for (int i = 1; i <= 12; i++)
|
||
{
|
||
rewards.Add(transform.Find($"root/turntable/reward{i}").GetComponent<TurntableRewardItem>());
|
||
}
|
||
|
||
selected = transform.Find("root/turntable/selected").gameObject;
|
||
wheelDrops = new List<WheelDrop>();
|
||
gradeAnimation = transform.Find("root/turntable/grade").GetComponent<Animation>();
|
||
barAnimation = transform.Find("root/turntable/bg_bar").GetComponent<Animation>();
|
||
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("FishingTurntablePanel");
|
||
stopClick.gameObject.SetActive(false);
|
||
skeletonGraphic = transform.Find("root/turntable/mask/npc").GetComponent<Spine.Unity.SkeletonGraphic>();
|
||
rewardItemNew = transform.Find("root/reward/reward").GetComponent<RewardItemNew>();
|
||
|
||
fx_ui_fishingturntable_npc_01 =
|
||
transform.Find("root/turntable/mask/npc/fx_ui_fishingturntable_npc_01").gameObject;
|
||
fx_ui_fishingturntable_change_01 = transform.Find("root/fx_ui_fishingturntable_change_01").gameObject;
|
||
fx_ui_fishingturntable_dengdai_01 =
|
||
transform.Find("root/turntable/fx_ui_fishingturntable_dengdai_01").gameObject;
|
||
fx_ui_fishingturntable_dengdai_02 =
|
||
transform.Find("root/turntable/fx_ui_fishingturntable_dengdai_02").gameObject;
|
||
turntable = transform.Find("root/turntable").GetComponent<Animation>();
|
||
|
||
ad_btn = transform.Find("root/turntable/btn_advert").GetComponent<Button>();
|
||
_btnPack.onClick.AddListener(() => _ = UIManager.Instance.ShowUI(UITypes.LackOfTicketPopupPanel));
|
||
}
|
||
|
||
protected override void Start()
|
||
{
|
||
_sm = new FSM();
|
||
_smHandler = new FSMHandler<AFSM<ETurnTableState>, ETurnTableState>(this, _sm);
|
||
_sm.SetState(ETurnTableState.Init);
|
||
// Debug.Log($"[turntable] Current thread ID @ Start: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
|
||
}
|
||
|
||
|
||
#region StateMachine
|
||
|
||
private enum ETurnTableState
|
||
{
|
||
Default,
|
||
Init,
|
||
Standby,
|
||
SingleDraw,
|
||
MultiDraw
|
||
}
|
||
|
||
private class FSM : AFSM<ETurnTableState>
|
||
{
|
||
}
|
||
|
||
private FSM _sm;
|
||
private FSMHandler<AFSM<ETurnTableState>, ETurnTableState> _smHandler;
|
||
private System.Threading.CancellationTokenSource _drawCTS;
|
||
private IDisposable ContinueDisposable;
|
||
[SerializeField] private float _lvlUpDurationInMilliseconds; //升级面板停留时长,毫秒
|
||
|
||
private void Init_Enter()
|
||
{
|
||
//Debug.Log("Init_Enter!");
|
||
//_fishingEventData.CheckTurntable();
|
||
base.Start();
|
||
GContext.OnEvent<ResAddEvent>()
|
||
.Where(x => x.id == 1004)
|
||
.Subscribe(x => { AddAnim(); })
|
||
.AddTo(disposables);
|
||
btn_close.OnClickAsObservable().Subscribe(x =>
|
||
{
|
||
if (_sm.State != ETurnTableState.Standby)
|
||
return;
|
||
canvasGroup.blocksRaycasts = false;
|
||
DestroyUI();
|
||
}).AddTo(disposables);
|
||
btn_nextLevelInfo.OnClickAsObservable().Subscribe(async x =>
|
||
{
|
||
btn_nextLevelInfo.enabled = false;
|
||
await UIManager.Instance.ShowUI(UITypes.TurntableRewardInfoPopupPanel);
|
||
btn_nextLevelInfo.enabled = true;
|
||
}).AddTo(disposables);
|
||
btn_Info.OnClickAsObservable().Subscribe(async x =>
|
||
{
|
||
btn_Info.enabled = false;
|
||
await UIManager.Instance.ShowUI(UITypes.FishingTurntableInfoPopupPanel);
|
||
btn_Info.enabled = true;
|
||
}).AddTo(disposables);
|
||
//btn_draw.onClick.AddListener(ClickDraw);
|
||
btn_draw.onLongPress.AddListener(HoldDraw);
|
||
btn_draw.onClick.AddListener(ClickDraw);
|
||
//btn_draw.onDown.AddListener(() => Debug.Log("Down!"));
|
||
//btn_draw.onUp.AddListener(() => Debug.Log("Up!"));
|
||
|
||
btn_levelUp.onClick.AddListener(() =>
|
||
{
|
||
//Debug.Log("点击升级面板");
|
||
levelUp.SetActive(false);
|
||
});
|
||
//btn_beilv.onClick.AddListener(OnclickMagnification);
|
||
//btn_beilv_max.onClick.AddListener(OnclickMagnification);
|
||
//text_beilvpanel_title.text = "All reward";
|
||
selected.SetActive(false);
|
||
levelUp.SetActive(false);
|
||
isFree = _fishingEventData.freecount > 0;
|
||
fx_ui_fishingturntable_dengdai_01.SetActive(true);
|
||
Init(true);
|
||
SetMulti();
|
||
SetEndTime();
|
||
// ad_btn.onClick.AddListener(() => { _ = UIManager.Instance.ShowUI(UITypes.GiftPopupPanel_3); });
|
||
ad_btn.onClick.AddListener(() => { _ = UIManager.Instance.ShowUI(UITypes.TurntableAdPopupPanel); });
|
||
_sm.SetState(ETurnTableState.Standby);
|
||
//ActionContinueMultiDraw = null;
|
||
ContinueDisposable = GContext.OnEvent<FishingTurnTableContinueMultiDraw>()
|
||
.Subscribe(_ => ContinueMultiDraw());
|
||
}
|
||
|
||
//private void Init_Exit()
|
||
//{
|
||
// Debug.Log("Init Exit!");
|
||
//}
|
||
private void Standby_Enter()
|
||
{
|
||
//Debug.Log("Standby_Enter!");
|
||
_animatorDrawButton.Play("Normal");
|
||
}
|
||
|
||
//private void Standby_Exit()
|
||
//{
|
||
// Debug.Log("Standby_Exit!");
|
||
//}
|
||
private void SingleDraw_Enter()
|
||
{
|
||
//Debug.Log("Single Draw Enter!");
|
||
//_animatorDrawButton.Play("clicked");
|
||
_drawCTS = new System.Threading.CancellationTokenSource();
|
||
_ = TrySingleDraw(_drawCTS.Token);
|
||
}
|
||
|
||
private async System.Threading.Tasks.Task TrySingleDraw(System.Threading.CancellationToken t)
|
||
{
|
||
var res = await Draw(t);
|
||
if (res is not false)
|
||
{
|
||
await OnStop(t);
|
||
}
|
||
else
|
||
{
|
||
_sm.SetState(ETurnTableState.Standby);
|
||
}
|
||
}
|
||
|
||
private void SingleDraw_Exit()
|
||
{
|
||
//Debug.Log("SingleDraw_exit!");
|
||
_drawCTS?.Dispose();
|
||
}
|
||
|
||
private void MultiDraw_Enter()
|
||
{
|
||
//Debug.Log("MultiDraw_Enter!");
|
||
//_animatorDrawButton.Play("Pressed");
|
||
_drawCTS = new System.Threading.CancellationTokenSource();
|
||
_ = MultiDrawAsync(_drawCTS.Token);
|
||
}
|
||
|
||
private void MultiDraw_Exit()
|
||
{
|
||
//Debug.Log("MultiDraw_Exit!");
|
||
_drawCTS?.Dispose();
|
||
}
|
||
|
||
private int _multiDrawAnimationSpeedStage = 0;
|
||
private float _multiDrawAnimationDelayMultiplier = 1.0f;
|
||
|
||
private async System.Threading.Tasks.Task MultiDrawAsync(System.Threading.CancellationToken t)
|
||
{
|
||
_multiDrawAnimationSpeedStage = 0;
|
||
_multiDrawAnimationDelayMultiplier = 1.0f;
|
||
while (_sm.State == ETurnTableState.MultiDraw)
|
||
{
|
||
if (_multiDrawAnimationSpeedStage < 5)
|
||
{
|
||
_multiDrawAnimationSpeedStage++;
|
||
_multiDrawAnimationDelayMultiplier =
|
||
1 - _tables.TbGlobalConfig.WheelPerTime * _multiDrawAnimationSpeedStage;
|
||
}
|
||
|
||
var isDrawn = await Draw(t);
|
||
// Debug.Log($"<color=#24acf2>Is Cancellation requested? {t.IsCancellationRequested}</color>");
|
||
// Debug.Log($"<color=#24acf2>Is Drawn? {isDrawn}</color>");
|
||
if (isDrawn is false)
|
||
{
|
||
_sm.SetState(ETurnTableState.Standby);
|
||
break;
|
||
}
|
||
else
|
||
{
|
||
await OnStop(t);
|
||
}
|
||
}
|
||
|
||
_multiDrawAnimationDelayMultiplier = 1.0f;
|
||
}
|
||
|
||
void ClickDraw()
|
||
{
|
||
_animatorDrawButton.Play("clicked");
|
||
if (_sm.State == ETurnTableState.MultiDraw)
|
||
{
|
||
//stop multidraw
|
||
//Debug.Log("<color=red>Draw Clicked!</color>");
|
||
_drawCTS.Cancel();
|
||
return;
|
||
}
|
||
|
||
if (_sm.State != ETurnTableState.Standby)
|
||
{
|
||
//Debug.Log("<color=red>Do Nothing!</color>");
|
||
return;
|
||
}
|
||
|
||
if (!isFree || _fishingEventData.freecount > 0)
|
||
{
|
||
//Debug.Log("<color=red>SingleDraw! </color>");
|
||
_sm.SetState(ETurnTableState.SingleDraw);
|
||
}
|
||
}
|
||
|
||
void HoldDraw()
|
||
{
|
||
if (_sm.State == ETurnTableState.Standby && !isFree || _fishingEventData.freecount > 0)
|
||
{
|
||
_animatorDrawButton.Play("Selected");
|
||
_sm.SetState(ETurnTableState.MultiDraw);
|
||
}
|
||
}
|
||
|
||
// void OnStopClick()
|
||
// {
|
||
// stopClick.onClick.RemoveAllListeners();
|
||
// _drawCTS.Cancel();
|
||
// OnStopAsync();
|
||
// }
|
||
// private async System.Threading.Tasks.Task<bool> OnStopAsync()
|
||
// {
|
||
// return (bool)await OnStop();
|
||
// }
|
||
|
||
#endregion
|
||
|
||
#if UNITY_EDITOR
|
||
private void OnGUI()
|
||
{
|
||
GUI.Box(new Rect(10, 10, 200, 20), _sm.State.ToString());
|
||
}
|
||
#endif
|
||
async void ChangeDengdai()
|
||
{
|
||
fx_ui_fishingturntable_dengdai_01.SetActive(false);
|
||
fx_ui_fishingturntable_dengdai_02.SetActive(true);
|
||
await Awaiters.Seconds(2.5f);
|
||
fx_ui_fishingturntable_dengdai_01.SetActive(true);
|
||
fx_ui_fishingturntable_dengdai_02.SetActive(false);
|
||
}
|
||
|
||
float[] spineTimer = new float[] { 0, 0, 2.1f };
|
||
|
||
async void PlayIdle(int index)
|
||
{
|
||
//播放Spine音效
|
||
skeletonGraphic.AnimationState.SetAnimation(0, $"Celebrate0{index}", false);
|
||
//PlaySpineSound(index);
|
||
float duration = skeletonGraphic.AnimationState.GetCurrent(0).Animation.Duration;
|
||
await Awaiters.Seconds(duration);
|
||
if (skeletonGraphic)
|
||
{
|
||
skeletonGraphic.AnimationState.SetAnimation(0, "Idle01", true);
|
||
}
|
||
}
|
||
|
||
async void PlaySpineSound(int index)
|
||
{
|
||
await Awaiters.Seconds(spineTimer[index - 1]);
|
||
GContext.Publish(new EventUISound($"audio_ui_turntable_npc_{index}"));
|
||
}
|
||
|
||
//抽奖逻辑
|
||
// 抽奖选项切换的默认速度,秒
|
||
[SerializeField] private float _spinIntervalSingle = 0.07f, _spinIntervalMulti = 0.07f;
|
||
|
||
// 抽到奖前的旋转圈数,非负整数;慢速切换的选项数。
|
||
[SerializeField] private int _spinRoundCountSingle = 1, _slowCountSingle = 4;
|
||
private int rc;
|
||
private float interval;
|
||
|
||
public IEnumerator Draw(System.Threading.CancellationToken t)
|
||
{
|
||
int CostNumber = 0; ;
|
||
if (isFree)
|
||
{
|
||
_fishingEventData.AddFreecount(-1);
|
||
|
||
text_draw.text =
|
||
LocalizationMgr.GetFormatTextValue("UI_TurntableInfoPopupPanel_5", _fishingEventData.freecount);
|
||
}
|
||
else
|
||
{
|
||
CostNumber = wheelLevel.CostNumber;
|
||
//若奖券不足,弹出提示
|
||
int turntableTicketCount = _fishingEventData.TurntableCoupon;
|
||
if (turntableTicketCount < CostNumber)
|
||
{
|
||
//GContext.Publish(new VibrationData(HapticTypes.Failure));
|
||
// _ = UIManager.Instance.ShowUI(UITypes.GiftPopupPanel_3);
|
||
_ = UIManager.Instance.ShowUI(UITypes.LackOfTicketPopupPanel);
|
||
// ToastPanel.Show(LocalizationMgr.GetText("UI_TurntableInfoPopupPanel_6"));
|
||
SetmaxMulti();
|
||
yield return false;
|
||
yield break;
|
||
}
|
||
}
|
||
|
||
if (_sm.State == ETurnTableState.SingleDraw)
|
||
{
|
||
stopClick.gameObject.SetActive(true);
|
||
// stopClick.onClick.AddListener(OnStopClick);
|
||
}
|
||
|
||
List<WheelInitSeq> wheelInitSeqs = _tables.TbWheelInitSeq.DataList;
|
||
selectedDrop = null;
|
||
selectedReward = null;
|
||
curSelectedIndex = 0;
|
||
if (_fishingEventData.WheelOperateCount >= wheelInitSeqs.Count)
|
||
{
|
||
// 计算抽奖结果
|
||
int totalWeight = 0;
|
||
WheelDrop drop;
|
||
for (int i = 0; i < wheelDrops.Count; i++)
|
||
{
|
||
drop = wheelDrops[i];
|
||
totalWeight += isFree ? drop.ExtraWeight : drop.Weight;
|
||
}
|
||
|
||
int randomValue = UnityEngine.Random.Range(0, totalWeight);
|
||
int weightSum = 0;
|
||
for (int i = 0; i < 12; i++)
|
||
{
|
||
drop = wheelDrops[i];
|
||
weightSum += isFree ? drop.ExtraWeight : drop.Weight;
|
||
if (randomValue < weightSum)
|
||
{
|
||
selectedDrop = drop;
|
||
selectedReward = rewards[i];
|
||
curSelectedIndex = i;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
curSelectedIndex = wheelInitSeqs[_fishingEventData.WheelOperateCount].WheelSeq;
|
||
selectedDrop = wheelDrops[curSelectedIndex];
|
||
selectedReward = rewards[curSelectedIndex];
|
||
}
|
||
|
||
//测试
|
||
// curSelectedIndex = 3;
|
||
// selectedDrop = wheelDrops[curSelectedIndex];
|
||
// selectedReward = rewards[curSelectedIndex];
|
||
// Debug.Log("奖品:" + selectedDrop.DropID);
|
||
// 播放抽奖动画
|
||
Vector3 rewardPosition = selectedReward.transform.position;
|
||
if (_sm.State == ETurnTableState.SingleDraw)
|
||
{
|
||
rc = _spinRoundCountSingle;
|
||
interval = _spinIntervalSingle;
|
||
}
|
||
else
|
||
{
|
||
// rc = 0;
|
||
rc = _spinRoundCountSingle;
|
||
interval = _spinIntervalMulti * _multiDrawAnimationDelayMultiplier;
|
||
}
|
||
|
||
#region Connection Check & Give Reward
|
||
|
||
if (selectedDrop is null)
|
||
{
|
||
Debug.LogError($"Selected Drop is null. Current selected index: {curSelectedIndex}");
|
||
yield break;
|
||
}
|
||
|
||
isDataSynced = false;
|
||
if (CostNumber > 0)
|
||
{
|
||
DoConsume();
|
||
}
|
||
else
|
||
{
|
||
isDataSynced = true;
|
||
}
|
||
|
||
//_ = ZZTimeHelper.RequestSvrTime(true);
|
||
while (!isDataSynced)
|
||
{
|
||
selectedIndex++;
|
||
selectedIndex %= 12;
|
||
rewards[selectedIndex].OnSelect();
|
||
yield return new WaitForSeconds(interval);
|
||
break;
|
||
}
|
||
|
||
GContext.container.Resolve<FishingEventData>().RewardTurntableRoll(CostNumber, false);
|
||
UpdateTicketCount();
|
||
var itemData =
|
||
_fishingEventData.UpdateWheel(selectedDrop.DropID, selectedDrop.Type == 9 ? 1 : multiplier, true);
|
||
|
||
#endregion
|
||
|
||
int start = (selectedIndex + 1) % 12;
|
||
int end = start + 12 * (rc) + (curSelectedIndex - start + 12) % 12;
|
||
int fast = end - _slowCountSingle;
|
||
for (int i = start; i < end; i++)
|
||
{
|
||
// if (t.IsCancellationRequested)
|
||
// {
|
||
// yield return true;
|
||
// yield break;
|
||
// }
|
||
if (i <= fast)
|
||
{
|
||
yield return new WaitForSeconds(interval);
|
||
}
|
||
else
|
||
{
|
||
yield return new WaitForSeconds(interval * (i - fast));
|
||
}
|
||
|
||
GContext.Publish(new VibrationData(HapticTypes.LightImpact));
|
||
rewards[i % 12].OnSelect();
|
||
}
|
||
|
||
yield return new WaitForSeconds(0.5f);
|
||
stopClick.onClick.RemoveAllListeners();
|
||
// yield return !t.IsCancellationRequested;
|
||
// if (t.IsCancellationRequested)
|
||
// {
|
||
// _sm.SetState(ETurnTableState.Standby);
|
||
// }
|
||
}
|
||
|
||
void DoConsume()
|
||
{
|
||
if (Application.internetReachability == NetworkReachability.NotReachable)
|
||
{
|
||
NoInternet();
|
||
}
|
||
else
|
||
{
|
||
ConsumeOnPlayfab();
|
||
}
|
||
}
|
||
private async void ConsumeOnPlayfab()
|
||
{
|
||
var success = await PlayFabMgr.Instance.SyncDataImmidiate("TurntableRoll",
|
||
(_fishingEventData.TurntableCoupon - wheelLevel.CostNumber).ToString());
|
||
Debug.Log($"[FishingTurntablePanel::ConsumeOnPlayfab] {success}");
|
||
isDataSynced = true;
|
||
}
|
||
|
||
private async void NoInternet()
|
||
{
|
||
GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel);
|
||
var NoticeConfirmPopupPanel = go.GetComponent<NoticeConfirmPopupPanel>();
|
||
string info = LocalizationMgr.GetText("UI_FishingReconnectPanel_101003");
|
||
string label = LocalizationMgr.GetText("UI_FishingRewardPanel_101022");
|
||
string title = LocalizationMgr.GetText("UI_FishingReconnectPanel_101002");
|
||
NoticeConfirmPopupPanel.Init(1, title, info,
|
||
onClickLeft: DoConsume,
|
||
onClose: DoConsume,
|
||
btn_left_text: label);
|
||
}
|
||
|
||
|
||
//转盘UI显示
|
||
private bool doPauseMultiDraw;
|
||
|
||
IEnumerator OnStop(System.Threading.CancellationToken t)
|
||
{
|
||
// Debug.Log($"[turntable] Current thread ID @ OnStop: {System.Threading.Thread.CurrentThread.ManagedThreadId}");
|
||
selectedReward.OnSelect();
|
||
selectedIndex = curSelectedIndex;
|
||
selected.transform.position = rewards[curSelectedIndex].transform.position;
|
||
//selected.transform.localEulerAngles = new Vector3(0, 0, 90 - 90 * (selectedIndex / 3));
|
||
selected.SetActive(true);
|
||
//播放奖品飞入动画
|
||
int dropId;
|
||
if (isFree)
|
||
{
|
||
dropId = selectedDrop.ExtraDropID;
|
||
}
|
||
else
|
||
{
|
||
dropId = selectedDrop.DropID;
|
||
}
|
||
|
||
var itemData = _fishingEventData.UpdateWheel(dropId, selectedDrop.Type == 9 ? 1 : multiplier, false);
|
||
#if AGG
|
||
using (var e = GEvent.GameEvent("roll_event"))
|
||
{
|
||
e.AddContent("fish_multiple", multiplier)
|
||
.AddContent("gear_info", selectedDrop.Type)
|
||
.AddContent("level_info", wheelLevel.Level);
|
||
if (itemData != null)
|
||
{
|
||
if (itemData.id == 1001)
|
||
{
|
||
e.AddContent("reward_hook", itemData.count);
|
||
}
|
||
else if (itemData.id == 1002)
|
||
{
|
||
e.AddContent("reward_cash", itemData.count);
|
||
}
|
||
}
|
||
}
|
||
#endif
|
||
_fishingEventData.AddIncreaseScore(selectedDrop.Point, multiplier);
|
||
if (selectedDrop.Type == 1)
|
||
{
|
||
//Debug.Log("<color=red>big win</color>");
|
||
ChangeDengdai();
|
||
// 特等奖
|
||
//GContext.Publish(new VibrationData(HapticTypes.Warning));
|
||
PlayIdle(2);
|
||
yield return new WaitForSeconds(2f);
|
||
yield return UIManager.Instance.ShowUI(UITypes.TurntableRewardPopupPanel).AsIEnumerator();
|
||
doPauseMultiDraw = true;
|
||
//ActionContinueMultiDraw += ContinueMultiDraw;
|
||
GContext.Publish(new ShowTurntableData(itemData));
|
||
// Debug.Log($"[turntable] About to pause");
|
||
while (curSelectedIndex is 3 or 9 && doPauseMultiDraw)
|
||
{
|
||
yield return new WaitForSeconds(0.1f);
|
||
}
|
||
//ActionContinueMultiDraw -= ContinueMultiDraw;
|
||
}
|
||
else if (selectedDrop.Type == 9) //currently not used
|
||
{
|
||
ChangeDengdai();
|
||
//GContext.Publish(new VibrationData(HapticTypes.Warning));
|
||
PlayIdle(3);
|
||
fx_ui_fishingturntable_npc_01.SetActive(false);
|
||
fx_ui_fishingturntable_npc_01.SetActive(true);
|
||
yield return new WaitForSeconds(3f);
|
||
}
|
||
else
|
||
{
|
||
//GContext.Publish(new VibrationData(HapticTypes.MediumImpact));
|
||
PlayIdle(1);
|
||
yield return selectedReward.ShowReward(rewardItemNew).AsIEnumerator();
|
||
}
|
||
|
||
//播放积分飞入动画
|
||
yield return StartCoroutine(AddProgress());
|
||
IsFree = _fishingEventData.freecount > 0;
|
||
if (levelUp.activeSelf)
|
||
{
|
||
if (_sm.State == ETurnTableState.SingleDraw)
|
||
yield return new WaitUntil(() => !levelUp.activeSelf);
|
||
else
|
||
{
|
||
yield return new WaitForSeconds(_lvlUpDurationInMilliseconds / 1000);
|
||
levelUp.SetActive(false);
|
||
}
|
||
|
||
turntable.Play();
|
||
yield return Awaiters.Seconds(2.75f);
|
||
wheelLevel = _fishingEventData.wheelLevel;
|
||
wheelDrops.Clear();
|
||
for (int i = 0; i < 12; i++)
|
||
{
|
||
wheelDrops.Add(_tables.TbWheelDrop.Get(wheelLevel.WheelDrop[i]));
|
||
rewards[i].wheelDrop = wheelDrops[i];
|
||
rewards[i].Init(isFree);
|
||
yield return Awaiters.Seconds(0.08485f);
|
||
}
|
||
}
|
||
|
||
//转场
|
||
if (needTransition)
|
||
{
|
||
fx_ui_fishingturntable_change_01.SetActive(false);
|
||
fx_ui_fishingturntable_change_01.SetActive(true);
|
||
yield return new WaitForSeconds(1.5f);
|
||
//mask.SetActive(true);
|
||
//transitionAnimation.DORestart();
|
||
//Debug.Log("播放动画");
|
||
//等待动画播放完毕
|
||
//yield return new WaitForSeconds(transitionAnimation.duration);
|
||
//mask.SetActive(false);
|
||
needTransition = false;
|
||
}
|
||
|
||
stopClick.gameObject.SetActive(false);
|
||
Init();
|
||
int CostNumber = wheelLevel.CostNumber;
|
||
if (_fishingEventData.TurntableCoupon < CostNumber)
|
||
{
|
||
UIManager.Instance.ShowUI(UITypes.LackOfTicketPopupPanel);
|
||
}
|
||
|
||
if (_sm.State == ETurnTableState.SingleDraw)
|
||
{
|
||
_sm.SetState(ETurnTableState.Standby);
|
||
yield return false;
|
||
}
|
||
else if (_sm.State == ETurnTableState.MultiDraw && t.IsCancellationRequested)
|
||
{
|
||
_sm.SetState(ETurnTableState.Standby);
|
||
}
|
||
|
||
yield return true;
|
||
}
|
||
|
||
//public static Action ActionContinueMultiDraw;
|
||
private void ContinueMultiDraw()
|
||
{
|
||
doPauseMultiDraw = false;
|
||
}
|
||
|
||
private void Init(bool init = false)
|
||
{
|
||
selected.SetActive(false);
|
||
//beilvpanel.alpha = 0;
|
||
if (isFree)
|
||
{
|
||
text_title.text = LocalizationMgr.GetText(_fishingEventData.wheelInit.SpecialTitle_l10n_key);
|
||
//btn_beilv.interactable = false;
|
||
//btn_beilv_max.interactable = false;
|
||
ticket.SetActive(false);
|
||
wheelBg_free.SetActive(true);
|
||
wheelBg.SetActive(false);
|
||
bg.SetActive(false);
|
||
bg_free.SetActive(true);
|
||
|
||
//GContext.container.Resolve<IUIService>().SetImageSprite(Bg, _fishingEventData.wheelInit.SpBg,BasePanel.PanelName);
|
||
text_draw.text =
|
||
LocalizationMgr.GetFormatTextValue("UI_TurntableInfoPopupPanel_5", _fishingEventData.freecount);
|
||
}
|
||
else
|
||
{
|
||
text_title.text = LocalizationMgr.GetText(_fishingEventData.wheelInit.Title_l10n_key);
|
||
text_draw.text = LocalizationMgr.GetText("UI_TurntableInfoPopupPanel_4");
|
||
//btn_beilv.interactable = true;
|
||
//btn_beilv_max.interactable = true;
|
||
ticket.SetActive(true);
|
||
wheelBg_free.SetActive(false);
|
||
wheelBg.SetActive(true);
|
||
bg.SetActive(true);
|
||
bg_free.SetActive(false);
|
||
//GContext.container.Resolve<IUIService>().SetImageSprite(Bg, _fishingEventData.wheelInit.Bg, BasePanel.PanelName);
|
||
}
|
||
|
||
wheelLevel = _fishingEventData.wheelLevel;
|
||
//Debug.Log("初始化 wheelLevel.level:" + wheelLevel.Level);
|
||
if (wheelLevel != null)
|
||
{
|
||
text_level.text = wheelLevel.Level.ToString();
|
||
if (init)
|
||
{
|
||
if (wheelLevel.NextLevel == -1 || wheelLevel.NextLevel == wheelLevel.Level)
|
||
{
|
||
bar.fillAmount = 1;
|
||
text_progress.text = "MAX";
|
||
}
|
||
else
|
||
{
|
||
int curCount = _fishingEventData.GetWheelLevelCount(wheelLevel.Level);
|
||
bar.fillAmount = curCount / (float)wheelLevel.NextLevelPoint;
|
||
text_progress.text = $"{curCount}/{wheelLevel.NextLevelPoint}";
|
||
}
|
||
}
|
||
|
||
SetTurntableData();
|
||
}
|
||
else
|
||
{
|
||
Debug.LogError("wheelLevel is null");
|
||
}
|
||
|
||
UpdateTicketCount();
|
||
}
|
||
|
||
//转盘数据
|
||
public void SetTurntableData()
|
||
{
|
||
wheelDrops.Clear();
|
||
for (int i = 0; i < 12; i++)
|
||
{
|
||
wheelDrops.Add(_tables.TbWheelDrop.Get(wheelLevel.WheelDrop[i]));
|
||
rewards[i].wheelDrop = wheelDrops[i];
|
||
rewards[i].Init(isFree);
|
||
}
|
||
}
|
||
|
||
void SetEndTime()
|
||
{
|
||
if (timer == null)
|
||
{
|
||
DateTime endTime = _fishingEventData.GetTurntableEndTime();
|
||
double seconds = (endTime - ZZTimeHelper.UtcNow().UtcNowOffset()).TotalSeconds;
|
||
timer = this.AttachTimer((float)seconds, null,
|
||
(elapsed) =>
|
||
{
|
||
TimeSpan now = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
||
text_time.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_end",
|
||
ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds));
|
||
if (now.TotalSeconds <= 0)
|
||
{
|
||
DestroyUI();
|
||
}
|
||
}, useRealTime: true);
|
||
}
|
||
}
|
||
|
||
void SetMulti()
|
||
{
|
||
//multiplier = GContext.container.Resolve<PlayerShopData>().GetTurntableMag();
|
||
UpdateRewardsShow();
|
||
}
|
||
|
||
|
||
void SetmaxMulti()
|
||
{
|
||
//multiplier = GContext.container.Resolve<PlayerShopData>().GetCurMaxTurntableMag(multiplier);
|
||
UpdateRewardsShow();
|
||
}
|
||
|
||
void UpdateRewardsShow()
|
||
{
|
||
//SetShowMagnification();
|
||
|
||
for (int i = 0; i < 12; i++)
|
||
{
|
||
rewards[i].rewardMulti = multiplier;
|
||
rewards[i].UpDisplay();
|
||
}
|
||
}
|
||
|
||
public bool IsFree
|
||
{
|
||
get { return isFree; }
|
||
set
|
||
{
|
||
if (isFree != value)
|
||
{
|
||
isFree = value;
|
||
// 当isFree值发生变化时,播放transitionAnimation动画
|
||
needTransition = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
private IEnumerator AddProgress()
|
||
{
|
||
if (wheelLevel.NextLevel == -1 || wheelLevel.NextLevel == wheelLevel.Level)
|
||
{
|
||
bar.fillAmount = 1;
|
||
text_progress.text = "MAX";
|
||
yield break;
|
||
}
|
||
|
||
gradeAnimation.Play();
|
||
yield return new WaitForSeconds(gradeAnimation.clip.length);
|
||
|
||
int curCount = _fishingEventData.GetWheelLevelCount(wheelLevel.Level);
|
||
float fill_amount_target = curCount / (float)wheelLevel.NextLevelPoint;
|
||
|
||
if (fill_amount_target < 1)
|
||
{
|
||
bar.DOFillAmount(fill_amount_target, gradeUp_time);
|
||
DOTween.To(() => int.Parse(text_progress.text.Split('/')[0]),
|
||
x => text_progress.text = $"{x}/{wheelLevel.NextLevelPoint}", curCount, gradeUp_time);
|
||
//yield return new WaitForSeconds(gradeUp_time);
|
||
//退出协程
|
||
yield break;
|
||
}
|
||
|
||
while (fill_amount_target >= 1)
|
||
{
|
||
text_level.text = wheelLevel.Level.ToString();
|
||
if (bar.fillAmount == 1)
|
||
{
|
||
bar.fillAmount = 0;
|
||
text_progress.text = $"{0}/{wheelLevel.NextLevelPoint}";
|
||
}
|
||
|
||
bar.DOFillAmount(1, gradeUp_time);
|
||
|
||
DOTween.To(() => int.Parse(text_progress.text.Split('/')[0]),
|
||
x => text_progress.text = $"{x}/{wheelLevel.NextLevelPoint}", wheelLevel.NextLevelPoint, gradeUp_time);
|
||
yield return new WaitForSeconds(gradeUp_time);
|
||
|
||
barAnimation.Play();
|
||
yield return new WaitForSeconds(barAnimation.clip.length);
|
||
|
||
|
||
curCount -= wheelLevel.NextLevelPoint;
|
||
wheelLevel = _tables.TbWheelLevel.Get(wheelLevel.NextLevel);
|
||
fill_amount_target = curCount / (float)wheelLevel.NextLevelPoint;
|
||
}
|
||
|
||
text_level.text = wheelLevel.Level.ToString();
|
||
if (wheelLevel.NextLevel == -1 || wheelLevel.NextLevel == wheelLevel.Level)
|
||
{
|
||
bar.fillAmount = 1;
|
||
text_progress.text = "MAX";
|
||
}
|
||
else
|
||
{
|
||
curCount = _fishingEventData.GetWheelLevelCount(wheelLevel.Level);
|
||
fill_amount_target = curCount / (float)wheelLevel.NextLevelPoint;
|
||
bar.fillAmount = 0;
|
||
bar.DOFillAmount(fill_amount_target, gradeUp_time);
|
||
DOTween.To(() => 0, x => text_progress.text = $"{x}/{wheelLevel.NextLevelPoint}", curCount, gradeUp_time);
|
||
yield return new WaitForSeconds(gradeUp_time);
|
||
}
|
||
|
||
levelUp.SetActive(true);
|
||
}
|
||
|
||
void AddAnim()
|
||
{
|
||
UpdateTicketCount();
|
||
}
|
||
|
||
void DestroyUI()
|
||
{
|
||
RestartShowHomeUIEvent restartShowHomeUIEvent = new RestartShowHomeUIEvent();
|
||
GContext.Publish(restartShowHomeUIEvent);
|
||
UIManager.Instance.DestroyUI(UITypes.FishingTurntablePanel);
|
||
}
|
||
/// <summary>
|
||
/// 更新奖券数量,判断余票数量是否足够下一抽;
|
||
/// </summary>
|
||
/// <returns>余票数量是否足够下一抽</returns>
|
||
private void UpdateTicketCount()
|
||
{
|
||
int TurntableCoupon = _fishingEventData.TurntableCoupon;
|
||
int CostNumber = wheelLevel.CostNumber;
|
||
if (TurntableCoupon < CostNumber)
|
||
{
|
||
text_ticket.text = $"<color=red>{ConvertTools.GetNumberString(TurntableCoupon)}/{CostNumber}</color>";
|
||
}
|
||
else
|
||
{
|
||
text_ticket.text = $"{ConvertTools.GetNumberString(TurntableCoupon)} /{CostNumber}";
|
||
}
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
GContext.Publish(new ConditionTypeEvent(ConditionType.WheelTicketLessThan, 1));
|
||
}
|
||
|
||
protected override void OnDestroy()
|
||
{
|
||
ContinueDisposable.Dispose();
|
||
base.OnDestroy();
|
||
}
|
||
}
|
||
|
||
public struct FishingTurnTableContinueMultiDraw
|
||
{
|
||
}
|