DeviceView.cs 4.7 KB

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