DeviceView.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. if (!deviceViewItems[1].gameObject.activeSelf)
  80. {
  81. deviceViewItems[1].gameObject.SetActive(true);
  82. horizontalLayoutGroup.spacing = 40;
  83. }
  84. }
  85. }
  86. public bool OnMenuBack() {
  87. ViewMgr.Instance.DestroyView<DeviceView>();
  88. return true;
  89. }
  90. public void OnClick_Back() {
  91. AudioMgr.ins.PlayBtn();
  92. ViewMgr.Instance.DestroyView<DeviceView>();
  93. }
  94. void OnChangeSmartArcheryButton(int index) {
  95. //Debug.Log("OnChangeSmartArcheryButton按钮:" + index);
  96. bool _selected = false;
  97. for (int i = 0; i < smartArcheryButtons.Count; i++)
  98. {
  99. Button _button = smartArcheryButtons[i];
  100. Color32 _white;
  101. //Color32 _buttonBg;
  102. if (index == i)
  103. {
  104. _white = new Color32(255, 255, 255, 255);
  105. //_buttonBg = new Color32(16, 194, 198, 255);
  106. _selected = true;
  107. _button.GetComponent<Image>().sprite = smartArcheryBg[1];
  108. }
  109. else {
  110. _white = new Color32(59, 59, 59, 255);
  111. //_buttonBg = new Color32(255, 255, 255, 255);
  112. _button.GetComponent<Image>().sprite = smartArcheryBg[0];
  113. }
  114. _button.transform.Find("icon").GetComponent<Image>().color = _white;
  115. _button.transform.Find("title").GetComponent<Text>().color = _white;
  116. _button.transform.Find("arrow").GetComponent<Image>().color = _white;
  117. }
  118. if (_selected)
  119. {
  120. //进入选中的页面
  121. AudioMgr.ins.PlayBtn();
  122. //设置一次 GlobalData.MyDeviceMode
  123. //HomeView.ins.MyTopBarView.onChangeType(index);
  124. if (getEnabelPanelStatus())
  125. {
  126. //取消正在连接的连接
  127. BluetoothAim.ins.onCancelAllConnecting(BluetoothStatusEnum.Connect);
  128. if (index == 0)
  129. {
  130. ViewMgr.Instance.ShowView<SmartArcheryView>();
  131. }
  132. else if (index == 1)
  133. {
  134. Debug.Log("Gun");
  135. ViewMgr.Instance.ShowView<SmartGunView>();
  136. }
  137. AimHandler.ins.onCreateTempAimDeviceInfo();
  138. }
  139. }
  140. }
  141. //暂时先更新一个
  142. public void RenderBattery(int deviceID, int value)
  143. {
  144. //smartArcheryButtons[0].GetComponent<DeviceView_ItemShow>().RenderBattery(deviceID,value);
  145. }
  146. public void OnChangeSmartArcheryButtonState(int index)
  147. {
  148. for (int i = 0; i < smartArcheryButtons.Count; i++)
  149. {
  150. Button _button = smartArcheryButtons[i];
  151. Color32 _white;
  152. //Color32 _buttonBg;
  153. if (index == i)
  154. {
  155. _white = new Color32(255, 255, 255, 255);
  156. _button.GetComponent<Image>().sprite = smartArcheryBg[1];
  157. }
  158. else
  159. {
  160. _white = new Color32(59, 59, 59, 255);
  161. _button.GetComponent<Image>().sprite = smartArcheryBg[0];
  162. }
  163. _button.transform.Find("icon").GetComponent<Image>().color = _white;
  164. _button.transform.Find("title").GetComponent<Text>().color = _white;
  165. _button.transform.Find("arrow").GetComponent<Image>().color = _white;
  166. }
  167. }
  168. public void OnCloseAllPanelStatus() {
  169. for (int i = 0; i < deviceViewItems.Count; i++)
  170. {
  171. deviceViewItems[i].setPanelStatus(false);
  172. }
  173. }
  174. //检测是否选择一个设备情况。用选择框判断
  175. public bool getEnabelPanelStatus() {
  176. bool bHasEnabel = false;
  177. for (int i = 0; i < deviceViewItems.Count; i++)
  178. {
  179. if (deviceViewItems[i].getCurrentPanelEnable()) {
  180. bHasEnabel = true;
  181. break;
  182. }
  183. }
  184. return bHasEnabel;
  185. }
  186. public void onTestClear() {
  187. AimHandler.ins.onClearAimDeviceInfosNew();
  188. }
  189. }