DeviceView.cs 5.9 KB

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