DeviceView1.cs 2.2 KB

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