| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- public class GyrGuidanceView : MonoBehaviour
- {
- [SerializeField] Button btnGyrCalibrate;
- TextAutoLanguage2 _TextAutoLanguage2;
- [SerializeField] List<GameObject> layouts;
- bool bAutoNext = false;
- bool bGyrCompleted = false;
- bool bCanNavTo = false;
- void Start()
- {
- btnGyrCalibrate.GetComponent<Button>().onClick.AddListener(()=> {
- if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
- {
- ClickGyrCalibrate();
- }
- else if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
- {
- ClickGyroCalibrate2P();
- }
-
- });
- transform.Find("BtnNext").GetComponent<Button>().onClick.AddListener(OnClick_Next);
- _TextAutoLanguage2 = btnGyrCalibrate.transform.Find("Text").GetComponent<TextAutoLanguage2>();
- if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
- {
- if (!AimHandler.ins.IsGyrCompleted())
- {
- _TextAutoLanguage2.SetTextKey("Gyro_Initialization");
- }
- else
- {
- _TextAutoLanguage2.SetTextKey("Gyro_Reinitialize");
- }
- }
- else if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
- {
- if (!BluetoothAim.ins.getSmartBowHelper2P().IsGyrCompleted())
- {
- _TextAutoLanguage2.SetTextKey("Gyro_Initialization");
- }
- else
- {
- _TextAutoLanguage2.SetTextKey("Gyro_Reinitialize");
- }
- }
-
- if (AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS)
- {
- ShowDeviceLayout(1);
- }
- else
- {
- ShowDeviceLayout(0);
- }
- }
- void ShowDeviceLayout(int index)
- {
- for (int i = 0; i < layouts.Count; i++)
- {
- GameObject _button = layouts[i];
- _button.SetActive(index == i);
- }
- }
- IEnumerator SetCanNavTo() {
- yield return new WaitForSeconds(1.0f);
- bCanNavTo = true;
- }
- void Update()
- {
- if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
- {
- if (AimHandler.ins.IsGyrCompleted() && !bGyrCompleted && flag_GyrCalibarateOperateAndFinish != 0)
- {
- bGyrCompleted = true;
- //检测到已经初始化陀螺仪
- StartCoroutine(SetCanNavTo());
- }
- UpdateForGyr();
- }
- else if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER) {
- if (BluetoothAim.ins.getSmartBowHelper2P().IsGyrCompleted() && !bGyrCompleted && flag_GyrCalibarateOperateAndFinish != 0)
- {
- bGyrCompleted = true;
- //检测到已经初始化陀螺仪
- StartCoroutine(SetCanNavTo());
- }
- UpdateCalibrateGyr2P();
- }
-
- }
- void OnClick_Next()
- {
- if (!bCanNavTo) return;
- if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
- {
- if (AimHandler.ins.IsGyrCompleted() && !gyrCalibrating)
- {
- ViewManager2.HideView(ViewManager2.Path_GyrGuidanceView);
- ViewManager2.ShowView(ViewManager2.Path_MagGuidanceView);
- }
- }
- else if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
- {
- if (BluetoothAim.ins.getSmartBowHelper2P().IsGyrCompleted() && !gyrCalibrating)
- {
- ViewManager2.HideView(ViewManager2.Path_GyrGuidanceView);
- ViewManager2.ShowView(ViewManager2.Path_MagGuidanceView);
- }
- }
-
- }
- public void OnClick_Back()
- {
- AudioMgr.ins.PlayBtn();
- ViewManager2.HideView(ViewManager2.Path_GyrGuidanceView);
- }
- #region 陀螺仪校准逻辑
- [NonSerialized] public int flag_GyrCalibarateOperateAndFinish = -1;
- public Action action_GyrCalibarateOperateAndFinish;
- public Func<bool> action_OnClickGyrCalibrateInterceptor;
- [NonSerialized] public bool gyrCalibrating = false;
- void ClickGyrCalibrate()
- {
- if (action_OnClickGyrCalibrateInterceptor != null)
- {
- if (action_OnClickGyrCalibrateInterceptor.Invoke()) return;
- }
- if (!gyrCalibrating && BluetoothAim.ins.status != BluetoothStatusEnum.ConnectSuccess)
- {
- PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("device-calibrate_n-connect"));
- return;
- }
- gyrCalibrating = !gyrCalibrating;
- if (gyrCalibrating)
- {
- bAutoNext = true;
- AimHandler.ins.gyrCalibrateCompleteCount = 0;
- canUpdateGyrCalibrateProgress = true;
- flag_GyrCalibarateOperateAndFinish = 0;
- }
- else
- {
- bAutoNext = false;
- canUpdateGyrCalibrateProgress = false;
- _TextAutoLanguage2.SetTextKey("Gyro_Reinitialize");
- }
- AimHandler.ins.ResetGyr();
- AimHandler.ins.CalibrateGyr(gyrCalibrating);
- }
- void FinishGyrCalibrate()
- {
- gyrCalibrating = false;
- canUpdateGyrCalibrateProgress = false;
- AimHandler.ins.CalibrateGyr(false);
- StartCoroutine(AimHandler.ins.SaveGyr());
- }
- bool canUpdateGyrCalibrateProgress = false;
- void UpdateForGyr()
- {
- if (canUpdateGyrCalibrateProgress)
- {
- int progress = AimHandler.ins.gyrCalibrateCompleteCount * 100 / AimHandler.ins.gyrCalibrateTotalCount;
- _TextAutoLanguage2.textFormatArgs = new object[] { progress };
- _TextAutoLanguage2.SetTextKey("Gyro_Initializing");
- if (progress >= 100)
- {
- FinishGyrCalibrate();
- if (flag_GyrCalibarateOperateAndFinish == 0)
- {
- flag_GyrCalibarateOperateAndFinish = 1;
- action_GyrCalibarateOperateAndFinish?.Invoke();
-
- if (AimHandler.ins.IsGyrCompleted())
- {
- _TextAutoLanguage2.SetTextKey("Gyro_Success");
- //如果是点击连接的,判断成功后自动跳转
- if (bAutoNext)
- {
- bAutoNext = false;
- OnClick_Next();
- }
- }
- else
- {
- //_TextAutoLanguage2.textFormatArgs = new object[] { };
- _TextAutoLanguage2.SetTextKey("Gyro_Initialization");
- }
-
- }
- }
- }
- }
- void ClickGyroCalibrate2P()
- {
- gyrCalibrating = !gyrCalibrating;
- if (gyrCalibrating)
- {
- bAutoNext = true;
- canUpdateGyrCalibrateProgress = true;
- flag_GyrCalibarateOperateAndFinish = 0;
- }
- else
- {
- bAutoNext = false;
- canUpdateGyrCalibrateProgress = false;
- _TextAutoLanguage2.SetTextKey("Gyro_Reinitialize");
- }
- BluetoothAim.ins.OnCalibrateGyr2P();
- }
- void UpdateCalibrateGyr2P()
- {
- //string act = BluetoothAim.ins.getSmartBowHelper2P().IsGyrCalibrating() ? "停止" : "开始";
- //text.text = $"点击{act}陀螺仪校准({progress}%)";
- if (canUpdateGyrCalibrateProgress)
- {
- int progress = BluetoothAim.ins.smartBowHelper2_Progress;
- _TextAutoLanguage2.textFormatArgs = new object[] { progress };
- _TextAutoLanguage2.SetTextKey("Gyro_Initializing");
- if (progress >= 100)
- {
- gyrCalibrating = false;
- canUpdateGyrCalibrateProgress = false;
- if (flag_GyrCalibarateOperateAndFinish == 0)
- {
- flag_GyrCalibarateOperateAndFinish = 1;
- action_GyrCalibarateOperateAndFinish?.Invoke();
- if (BluetoothAim.ins.getSmartBowHelper2P().IsGyrCompleted())
- {
- _TextAutoLanguage2.SetTextKey("Gyro_Success");
- //如果是点击连接的,判断成功后自动跳转
- if (bAutoNext)
- {
- bAutoNext = false;
- OnClick_Next();
- }
- }
- else
- {
- //_TextAutoLanguage2.textFormatArgs = new object[] { };
- _TextAutoLanguage2.SetTextKey("Gyro_Initialization");
- }
- }
- }
- }
- }
- #endregion
- }
|