| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class ConnectGuidanceView : MonoBehaviour
- {
- [SerializeField] List<GameObject> layouts;
- bool isNext = false;
- [SerializeField] GameObject textTip01;
- [SerializeField] GameObject textTip02;
- //定位进来时候调用
- public void showTextipInfrared() {
- textTip01.SetActive(false);
- textTip02.SetActive(true);
- }
- void Start()
- {
- //进入指南页面,onCreateAimDeviceInfoById 一下 aimdevice,和设置一下type
- resetAimType();
- InitConfirmStorage();
- transform.Find("BtnNext").GetComponent<Button>().onClick.AddListener(OnClick_Next);
- if (AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS || AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMISPRO)
- {
- ShowDeviceLayout(1);
- }
- else if (AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.Gun)
- {
- ShowDeviceLayout(2);
- }
- else
- {
- ShowDeviceLayout(0);
- }
-
- //NewUserGuiderManager newUserGuiderManager = FindObjectOfType<NewUserGuiderManager>();
- //newUserGuiderManager.curConfigKey = "视角归位-触发";
- //newUserGuiderManager.isNewModule = AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.ARTEMIS;
- ////进入射箭场景
- //GlobalData.pkMatchType = PKMatchType.None;
- //GameMgr.gameType = 1;
- ////射一箭回到连接页面,Device.view
- //GameMgr.bNavBack = true;
- //GameMgr.bShowDistance = false;
- //AimHandler.ins.bInitOne = true;
- //UnityEngine.SceneManagement.SceneManager.LoadScene(
- // "Game", UnityEngine.SceneManagement.LoadSceneMode.Single);
- }
- void ShowDeviceLayout(int index)
- {
- for (int i = 0; i < layouts.Count; i++)
- {
- GameObject _button = layouts[i];
- _button.SetActive(index == i);
- }
- }
- void Update()
- {
- UpdateBtnForConnect();
- }
- void OnClick_Next()
- {
- //onEnterInfrared();
- //return;
- if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
- {
- if (bowStatus == BluetoothStatusEnum.ConnectSuccess)
- {
- AimHandler.ins.OnSaveAimDeviceInfos();
- BluetoothAim.ins.SetMainConnectDeviceType();
- if (AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.HOUYIPRO
- && AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.Gun
- && AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.ARTEMISPRO)
- {
- //如果不是红外设备,才进入校准?
- ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
- ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
- }
- else
- {
- //修改步骤
- ViewManager2.ShowView(ViewManager2.Path_InfraredView);
- //if (!PlayerPrefs.HasKey("hideInfraredBowAndArrow"))
- //{
- // //如果是红外连接成功,记录一个tag
- // PlayerPrefs.SetInt("hideInfraredBowAndArrow", 1);
- //}
- //onEnterInfrared();
- }
- }
- }
- else if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
- {
- if (bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connected)
- {
- AimHandler.ins.OnSaveAimDeviceInfos();
- BluetoothAim.ins.SetMainConnectDeviceType();
- if (AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.HOUYIPRO
- && AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.Gun
- && AimHandler.ins.aimDeviceInfo.type != (int)AimDeviceType.ARTEMISPRO)
- {
- //如果不是红外设备,才进入校准?
- ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
- ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
- }
- else
- {
- //修改步骤
- ViewManager2.ShowView(ViewManager2.Path_InfraredView);
- //if (!PlayerPrefs.HasKey("hideInfraredBowAndArrow"))
- //{
- // //如果是红外连接成功,记录一个tag
- // PlayerPrefs.SetInt("hideInfraredBowAndArrow", 1);
- //}
- //onEnterInfrared();
- }
- //ViewManager2.ShowView(ViewManager2.Path_GyrGuidanceView);
- }
-
- }
- }
- void InitConfirmStorage()
- {
- transform.Find("ConfirmStep/Toggle").GetComponent<Toggle>().SetIsOnWithoutNotify(IsConfirmInStorage());
- transform.Find("ConfirmStep/Toggle").GetComponent<Toggle>().onValueChanged.AddListener(v =>
- {
- SetConfirmToStorage(v);
- });
- }
- bool IsConfirmInStorage()
- {
- return PlayerPrefs.GetInt("connect-confirm-" + LoginMgr.myUserInfo.id, 0) == 1;
- }
- void SetConfirmToStorage(bool value)
- {
- PlayerPrefs.SetInt("connect-confirm-" + LoginMgr.myUserInfo.id, value ? 1 : 0);
- }
- [SerializeField] GameObject btnConnectBow;
- [SerializeField] Text btnOmitText;
- private int dotCount = 0;
- private float interval = 0.5f; // 标点更新间隔
- private float timer = 0f;
- BluetoothStatusEnum bowStatus;
- SmartBowSDK.BluetoothStatusEnum bowStatus2P;
- void UpdateBtnForConnect()
- {
- if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
- {
- if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status)
- {
- bowStatus = BluetoothAim.ins.status;
- (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
- btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
- btnConnectBow.GetComponentInChildren<Text>().color = color;
- btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus == BluetoothStatusEnum.ConnectSuccess);
- btnOmitText.color = color;
- }
- if (bowStatus != BluetoothStatusEnum.ConnectSuccess) {
- isNext = false;
- }
- //自动跳转
- else if (!isNext && bowStatus == BluetoothStatusEnum.ConnectSuccess)
- {
- isNext = true;
- OnClick_Next();
- }
- if (bowStatus == BluetoothStatusEnum.Connecting)
- {
- btnOmitText.gameObject.SetActive(true);
- UpdateLoadingText();
- }
- else
- {
- StopLoading();
- }
- }
- else if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
- {
- SmartBowSDK.SmartBowHelper smartBowHelper = BluetoothAim.ins.getSmartBowHelper2P();
- if (smartBowHelper == null) return;
- if (BluetoothAim.ins && bowStatus2P != smartBowHelper.GetBluetoothStatus())
- {
- bowStatus2P = smartBowHelper.GetBluetoothStatus();
- (int textID, Color color) = BluetoothStatus.GetBLE2StatusInfo(bowStatus2P);
- btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
- btnConnectBow.GetComponentInChildren<Text>().color = color;
- btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connected);
- btnOmitText.color = color;
- }
- if (bowStatus2P != SmartBowSDK.BluetoothStatusEnum.Connected)
- {
- isNext = false;
- }
- //自动跳转
- if (!isNext && bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connected)
- {
- isNext = true;
- OnClick_Next();
- }
- if (bowStatus2P == SmartBowSDK.BluetoothStatusEnum.Connecting)
- {
- btnOmitText.gameObject.SetActive(true);
- UpdateLoadingText();
- }
- else
- {
- StopLoading();
- }
- }
-
- }
- void UpdateLoadingText()
- {
- timer += Time.deltaTime;
- // 每隔 `interval` 秒更新一次标点符号
- if (timer >= interval)
- {
- dotCount = (dotCount + 1) % 4; // 标点数量从 0 到 3 循环
- btnOmitText.text = new string('.', dotCount); // 添加相应数量的点
- timer = 0f; // 重置计时器
- }
- }
- // 停止加载效果
- public void StopLoading()
- {
- dotCount = 0;
- btnOmitText.text = ""; // 停止时恢复为基础文本
- }
- public void OnClick_ConnectBLE()
- {
- if (!IsConfirmInStorage())
- {
- //PopupMgr.ins.ShowTip("Please Confirmed the completion of the above steps");
-
- PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("Guidance_Checked"));
- return;
- }
- //此页面连接当作重新初始化
- resetAimDevice();
- if (HomeView.ShowProminentBeforeConnectBLE()) return;
- Debug.Log("BluetoothAim.ins.getBLEPlayer():"+ BluetoothAim.ins.getBLEPlayer());
- if (BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.FIRST_PLAYER)
- {
- BluetoothAim.ins.DoConnect();
- }
- else if(BluetoothAim.ins.getBLEPlayer() == BluetoothPlayer.SECONDE_PLAYER)
- {
- BluetoothAim.ins.DoConnect2P();
- }
- }
- public void OnClick_Back()
- {
- AudioMgr.ins.PlayBtn();
- ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
- }
- public void resetAimDevice() {
- //进行重新初始化的时候。重置一下对应的mac
- AimHandler.ins.onCreateAimDeviceInfoById();
- AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type);
- AimHandler.ins.ResetAimDeviceMac();
- Debug.Log("重新初始化时候 bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac);
- }
- public void resetAimType() {
- AimHandler.ins.onCreateAimDeviceInfoById();
- AimHandler.ins.SetAimDeviceType(AimHandler.ins.tempAimDeviceInfo.type);
- //如果有正在连接的情况,重置一下mac。其他不需要
- if (BluetoothAim.ins)
- {
- if (BluetoothAim.ins.status == BluetoothStatusEnum.Connecting)
- {
- AimHandler.ins.ResetAimDeviceMac();
- }
- SmartBowSDK.SmartBowHelper smartBowHelper = BluetoothAim.ins.getSmartBowHelper2P();
- if (smartBowHelper != null) {
- SmartBowSDK.BluetoothStatusEnum bluetoothStatusEnum = smartBowHelper.GetBluetoothStatus();
- if (bluetoothStatusEnum == SmartBowSDK.BluetoothStatusEnum.Connecting)
- {
- AimHandler.ins.ResetAimDeviceMac();
- }
- }
- }
- Debug.Log("重新初始化时候 resetAimType bInitMac :" + AimHandler.ins.aimDeviceInfo.bInitMac);
- }
- void OnDestroy()
- {
- //退出面板时候,取消正在连接的连接
- BluetoothAim.ins.onCancelAllConnecting();
- }
- //连接之后,跳转进入场景
- //void onEnterInfrared() {
- // //添加进入射箭场景
- // if (PlayerPrefs.GetInt("entry-guider-infrared-" + LoginMgr.myUserInfo.id, 0) == 0)
- // {
- // Debug.Log("-----进入射箭场景!");
- // NewUserGuiderManager newUserGuiderManager = FindObjectOfType<NewUserGuiderManager>();
- // newUserGuiderManager.curConfigKey = "开始-红外调整";
- // newUserGuiderManager.isNewModule = AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.HOUYIPRO || AimHandler.ins.aimDeviceInfo.type == (int)AimDeviceType.Gun ;
- // //进入射箭场景
- // GlobalData.pkMatchType = PKMatchType.None;
- // GameMgr.gameType = 1;
- // //射一箭回到连接页面,Device.view
- // GameMgr.bNavBack = true;
- // GameMgr.bShowDistance = false;
- // AimHandler.ins.bInitOne = true;
- // //关闭计时器
- // GameMgr.turnOffTimer = true;
- // UnityEngine.SceneManagement.SceneManager.LoadScene(
- // "Game", UnityEngine.SceneManagement.LoadSceneMode.Single);
- // PlayerPrefs.SetInt("entry-guider-infrared-" + LoginMgr.myUserInfo.id, 1);
- // }
- // else
- // {
- // Debug.Log("-----跳转回连接界面!");
- // //如不是第一次,则应该跳转回连接界面
- // ViewMgr.Instance.DestroyView<SmartArcheryView>();
- // ViewManager2.HideView(ViewManager2.Path_ConnectGuidanceView);
- // }
- //}
- }
|