DeviceView.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. /* 设备界面 */
  7. public class DeviceView : JCUnityLib.ViewBase, MenuBackInterface
  8. {
  9. //GameObject bowOptions;
  10. [SerializeField] List<Button> smartArcheryButtons;
  11. [SerializeField] List<Sprite> smartArcheryBg;
  12. [SerializeField] List<DeviceView_ItemShow> deviceViewItems;
  13. public static DeviceView ins;
  14. public Action action_OnClickGyr;
  15. public Action action_OnClickMag;
  16. //默认选中第一个(1p)
  17. public int selectIndex = 0;
  18. void Start()
  19. {
  20. ins = this;
  21. PersistenHandler.ins?.menuBackCtr.views.Add(this);
  22. for (int i = 0; i < smartArcheryButtons.Count; i++)
  23. {
  24. int temp = i;
  25. smartArcheryButtons[i].onClick.AddListener(()=>{
  26. OnChangeSmartArcheryButton(temp);
  27. });
  28. }
  29. //bowOptions = this.transform.Find("ItemInfo/BowOptions").gameObject;
  30. //初始化弓的校准按钮
  31. //Button[] bowOptionBtns = bowOptions.GetComponentsInChildren<Button>();
  32. //for (int i = 0; i < bowOptionBtns.Length; i++)
  33. //{
  34. // int optionID = i;
  35. // bowOptionBtns[i].onClick.AddListener(delegate() {
  36. // AudioMgr.ins.PlayBtn();
  37. // switch (optionID)
  38. // {
  39. // case 0:
  40. // DeviceCalibrateView.Create(DeviceCalibrateItem.Gyr);
  41. // action_OnClickGyr?.Invoke();
  42. // break;
  43. // case 1:
  44. // DeviceCalibrateView.Create(DeviceCalibrateItem.Mag);
  45. // action_OnClickMag?.Invoke();
  46. // break;
  47. // }
  48. // });
  49. //}
  50. //AimHandler.ins.onClearAimDeviceInfos();
  51. //进入连接界面,初始化一下AimDeviceInfo
  52. AimHandler.ins.OnGetAimDeviceInfos();
  53. //for (int j = 0; j < deviceViewItems.Count; j++)
  54. //{
  55. // deviceViewItems[j].onShowDeviceInfo();
  56. //}
  57. }
  58. void OnDestroy()
  59. {
  60. if (ins == this) ins = null;
  61. PersistenHandler.ins?.menuBackCtr.views.Remove(this);
  62. }
  63. void Update()
  64. {
  65. }
  66. public bool OnMenuBack() {
  67. ViewMgr.Instance.DestroyView<DeviceView>();
  68. return true;
  69. }
  70. public void OnClick_Back() {
  71. AudioMgr.ins.PlayBtn();
  72. ViewMgr.Instance.DestroyView<DeviceView>();
  73. }
  74. void OnChangeSmartArcheryButton(int index) {
  75. //Debug.Log("OnChangeSmartArcheryButton按钮:" + index);
  76. bool _selected = false;
  77. for (int i = 0; i < smartArcheryButtons.Count; i++)
  78. {
  79. Button _button = smartArcheryButtons[i];
  80. Color32 _white;
  81. //Color32 _buttonBg;
  82. if (index == i)
  83. {
  84. _white = new Color32(255, 255, 255, 255);
  85. //_buttonBg = new Color32(16, 194, 198, 255);
  86. _selected = true;
  87. _button.GetComponent<Image>().sprite = smartArcheryBg[1];
  88. }
  89. else {
  90. _white = new Color32(59, 59, 59, 255);
  91. //_buttonBg = new Color32(255, 255, 255, 255);
  92. _button.GetComponent<Image>().sprite = smartArcheryBg[0];
  93. }
  94. _button.transform.Find("icon").GetComponent<Image>().color = _white;
  95. _button.transform.Find("title").GetComponent<Text>().color = _white;
  96. _button.transform.Find("arrow").GetComponent<Image>().color = _white;
  97. }
  98. if (_selected)
  99. {
  100. //进入选中的页面
  101. AudioMgr.ins.PlayBtn();
  102. ViewMgr.Instance.ShowView<SmartArcheryView>();
  103. //todo 这里暂时设置选择1p(2p未开发)
  104. AimHandler.ins.onCreateAimDeviceInfoById(selectIndex);
  105. }
  106. }
  107. //暂时先更新一个
  108. public void RenderBattery(int deviceID, int value)
  109. {
  110. //smartArcheryButtons[0].GetComponent<DeviceView_ItemShow>().RenderBattery(deviceID,value);
  111. }
  112. public void OnChangeSmartArcheryButtonState(int index)
  113. {
  114. for (int i = 0; i < smartArcheryButtons.Count; i++)
  115. {
  116. Button _button = smartArcheryButtons[i];
  117. Color32 _white;
  118. //Color32 _buttonBg;
  119. if (index == i)
  120. {
  121. _white = new Color32(255, 255, 255, 255);
  122. _button.GetComponent<Image>().sprite = smartArcheryBg[1];
  123. }
  124. else
  125. {
  126. _white = new Color32(59, 59, 59, 255);
  127. _button.GetComponent<Image>().sprite = smartArcheryBg[0];
  128. }
  129. _button.transform.Find("icon").GetComponent<Image>().color = _white;
  130. _button.transform.Find("title").GetComponent<Text>().color = _white;
  131. _button.transform.Find("arrow").GetComponent<Image>().color = _white;
  132. }
  133. }
  134. }