DeviceView.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class DeviceViewSelectStatus {
  7. int index = 0;
  8. bool bShow = false;
  9. Sprite ItemPanel;
  10. }
  11. /* 设备界面 */
  12. public class DeviceView : JCUnityLib.ViewBase, MenuBackInterface
  13. {
  14. //GameObject bowOptions;
  15. [SerializeField] List<Button> smartArcheryButtons;
  16. [SerializeField] List<Sprite> smartArcheryBg;
  17. [SerializeField] List<DeviceView_ItemShow> deviceViewItems;
  18. public static DeviceView ins;
  19. public Action action_OnClickGyr;
  20. public Action action_OnClickMag;
  21. public HorizontalLayoutGroup horizontalLayoutGroup;
  22. //[SerializeField] List<DeviceViewSelectStatus> deviceViewItems;
  23. void Start()
  24. {
  25. ins = this;
  26. PersistenHandler.ins?.menuBackCtr.views.Add(this);
  27. for (int i = 0; i < smartArcheryButtons.Count; i++)
  28. {
  29. int temp = i;
  30. smartArcheryButtons[i].onClick.AddListener(()=>{
  31. OnChangeSmartArcheryButton(temp);
  32. });
  33. }
  34. OnChangeSmartArcheryButtonState((int)GlobalData.MyDeviceMode);
  35. //bowOptions = this.transform.Find("ItemInfo/BowOptions").gameObject;
  36. //初始化弓的校准按钮
  37. //Button[] bowOptionBtns = bowOptions.GetComponentsInChildren<Button>();
  38. //for (int i = 0; i < bowOptionBtns.Length; i++)
  39. //{
  40. // int optionID = i;
  41. // bowOptionBtns[i].onClick.AddListener(delegate() {
  42. // AudioMgr.ins.PlayBtn();
  43. // switch (optionID)
  44. // {
  45. // case 0:
  46. // DeviceCalibrateView.Create(DeviceCalibrateItem.Gyr);
  47. // action_OnClickGyr?.Invoke();
  48. // break;
  49. // case 1:
  50. // DeviceCalibrateView.Create(DeviceCalibrateItem.Mag);
  51. // action_OnClickMag?.Invoke();
  52. // break;
  53. // }
  54. // });
  55. //}
  56. //进入连接界面,初始化一下AimDeviceInfo
  57. //AimHandler.ins.OnGetAimDeviceInfos();
  58. AimHandler.ins.onCreateAimDeviceInfoById();
  59. }
  60. void OnDestroy()
  61. {
  62. if (ins == this) ins = null;
  63. PersistenHandler.ins?.menuBackCtr.views.Remove(this);
  64. //退出面板时候,取消正在连接的连接
  65. BluetoothAim.ins.onCancelAllConnecting();
  66. }
  67. void Update()
  68. {
  69. //刷新按钮显示状态2P
  70. if (BluetoothAim.ins && BluetoothAim.ins.isMainConnectToInfraredDevice())
  71. {
  72. if (deviceViewItems[1].gameObject.activeSelf)
  73. {
  74. deviceViewItems[1].gameObject.SetActive(false);
  75. horizontalLayoutGroup.spacing = 60;
  76. }
  77. }
  78. else
  79. {
  80. if (!deviceViewItems[1].gameObject.activeSelf)
  81. {
  82. deviceViewItems[1].gameObject.SetActive(true);
  83. horizontalLayoutGroup.spacing = 40;
  84. }
  85. }
  86. }
  87. public bool OnMenuBack() {
  88. ViewMgr.Instance.DestroyView<DeviceView>();
  89. return true;
  90. }
  91. public void OnClick_Back() {
  92. AudioMgr.ins.PlayBtn();
  93. ViewMgr.Instance.DestroyView<DeviceView>();
  94. }
  95. void OnChangeSmartArcheryButton(int index) {
  96. //Debug.Log("OnChangeSmartArcheryButton按钮:" + index);
  97. bool _selected = false;
  98. for (int i = 0; i < smartArcheryButtons.Count; i++)
  99. {
  100. Button _button = smartArcheryButtons[i];
  101. Color32 _white;
  102. //Color32 _buttonBg;
  103. if (index == i)
  104. {
  105. _white = new Color32(255, 255, 255, 255);
  106. //_buttonBg = new Color32(16, 194, 198, 255);
  107. _selected = true;
  108. _button.GetComponent<Image>().sprite = smartArcheryBg[1];
  109. }
  110. else {
  111. _white = new Color32(59, 59, 59, 255);
  112. //_buttonBg = new Color32(255, 255, 255, 255);
  113. _button.GetComponent<Image>().sprite = smartArcheryBg[0];
  114. }
  115. _button.transform.Find("icon").GetComponent<Image>().color = _white;
  116. _button.transform.Find("title").GetComponent<Text>().color = _white;
  117. _button.transform.Find("arrow").GetComponent<Image>().color = _white;
  118. }
  119. if (_selected)
  120. {
  121. //进入选中的页面
  122. AudioMgr.ins.PlayBtn();
  123. //设置一次 GlobalData.MyDeviceMode
  124. //HomeView.ins.MyTopBarView.onChangeType(index);
  125. if (getEnabelPanelStatus())
  126. {
  127. //取消正在连接的连接
  128. BluetoothAim.ins.onCancelAllConnecting(BluetoothStatusEnum.Connect);
  129. if (index == 0)
  130. {
  131. ViewMgr.Instance.ShowView<SmartArcheryView>();
  132. }
  133. else if (index == 1)
  134. {
  135. Debug.Log("Gun");
  136. ViewMgr.Instance.ShowView<SmartGunView>();
  137. }
  138. AimHandler.ins.onCreateTempAimDeviceInfo();
  139. }
  140. }
  141. }
  142. //暂时先更新一个
  143. public void RenderBattery(int deviceID, int value)
  144. {
  145. //smartArcheryButtons[0].GetComponent<DeviceView_ItemShow>().RenderBattery(deviceID,value);
  146. }
  147. public void OnChangeSmartArcheryButtonState(int index)
  148. {
  149. for (int i = 0; i < smartArcheryButtons.Count; i++)
  150. {
  151. Button _button = smartArcheryButtons[i];
  152. Color32 _white;
  153. //Color32 _buttonBg;
  154. if (index == i)
  155. {
  156. _white = new Color32(255, 255, 255, 255);
  157. _button.GetComponent<Image>().sprite = smartArcheryBg[1];
  158. }
  159. else
  160. {
  161. _white = new Color32(59, 59, 59, 255);
  162. _button.GetComponent<Image>().sprite = smartArcheryBg[0];
  163. }
  164. _button.transform.Find("icon").GetComponent<Image>().color = _white;
  165. _button.transform.Find("title").GetComponent<Text>().color = _white;
  166. _button.transform.Find("arrow").GetComponent<Image>().color = _white;
  167. }
  168. }
  169. public void OnCloseAllPanelStatus() {
  170. for (int i = 0; i < deviceViewItems.Count; i++)
  171. {
  172. deviceViewItems[i].setPanelStatus(false);
  173. }
  174. }
  175. //检测是否选择一个设备情况。用选择框判断
  176. public bool getEnabelPanelStatus() {
  177. bool bHasEnabel = false;
  178. for (int i = 0; i < deviceViewItems.Count; i++)
  179. {
  180. if (deviceViewItems[i].getCurrentPanelEnable()) {
  181. bHasEnabel = true;
  182. break;
  183. }
  184. }
  185. return bHasEnabel;
  186. }
  187. public void onTestClear() {
  188. AimHandler.ins.onClearAimDeviceInfosNew();
  189. }
  190. }