DeviceView.cs 6.2 KB

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