DeviceView1.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. /* 设备界面 */
  6. public class DeviceView1 : MonoBehaviour, MenuBackInterface
  7. {
  8. GameObject bowOptions;
  9. [SerializeField] GameObject btnConnectBow;
  10. void Start()
  11. {
  12. PersistenHandler.ins?.menuBackCtr.views.Add(this);
  13. btnConnectBow.GetComponent<Button>().onClick.AddListener(delegate() {
  14. BluetoothAim.ins.DoConnect();
  15. });
  16. bowOptions = this.transform.Find("ItemInfo/BowOptions").gameObject;
  17. //初始化弓的校准按钮
  18. Button[] bowOptionBtns = bowOptions.GetComponentsInChildren<Button>();
  19. for (int i = 0; i < bowOptionBtns.Length; i++)
  20. {
  21. int optionID = i;
  22. bowOptionBtns[i].onClick.AddListener(delegate() {
  23. AudioMgr.ins.PlayBtn();
  24. switch (optionID)
  25. {
  26. case 0:
  27. DeviceCalibrateView.Create(DeviceCalibrateItem.Gyr);
  28. break;
  29. case 1:
  30. DeviceCalibrateView.Create(DeviceCalibrateItem.Mag);
  31. break;
  32. }
  33. });
  34. }
  35. }
  36. void OnDestroy()
  37. {
  38. PersistenHandler.ins?.menuBackCtr.views.Remove(this);
  39. }
  40. void Update()
  41. {
  42. UpdateBtnForConnect();
  43. }
  44. BluetoothStatusEnum bowStatus;
  45. void UpdateBtnForConnect() {
  46. if (BluetoothAim.ins && bowStatus != BluetoothAim.ins.status) {
  47. bowStatus = BluetoothAim.ins.status;
  48. (int textID, Color color) = BluetoothStatus.GetStatusInfo(BluetoothAim.ins.status);
  49. btnConnectBow.GetComponentInChildren<TextAutoLanguage>().SetText(textID);
  50. btnConnectBow.GetComponentInChildren<Text>().color = color;
  51. btnConnectBow.transform.Find("Check").gameObject.SetActive(bowStatus == BluetoothStatusEnum.ConnectSuccess);
  52. }
  53. }
  54. public bool OnMenuBack() {
  55. Destroy(gameObject);
  56. return true;
  57. }
  58. public void OnClick_Back() {
  59. AudioMgr.ins.PlayBtn();
  60. Destroy(this.gameObject);
  61. }
  62. }