DeviceView.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. public static DeviceView ins;
  12. public Action action_OnClickGyr;
  13. public Action action_OnClickMag;
  14. void Start()
  15. {
  16. ins = this;
  17. PersistenHandler.ins?.menuBackCtr.views.Add(this);
  18. for (int i = 0; i < smartArcheryButtons.Count; i++)
  19. {
  20. int temp = i;
  21. smartArcheryButtons[i].onClick.AddListener(()=>{
  22. AudioMgr.ins.PlayBtn();
  23. OnChangeSmartArcheryButton(temp);
  24. });
  25. }
  26. bowOptions = this.transform.Find("ItemInfo/BowOptions").gameObject;
  27. //初始化弓的校准按钮
  28. Button[] bowOptionBtns = bowOptions.GetComponentsInChildren<Button>();
  29. for (int i = 0; i < bowOptionBtns.Length; i++)
  30. {
  31. int optionID = i;
  32. bowOptionBtns[i].onClick.AddListener(delegate() {
  33. AudioMgr.ins.PlayBtn();
  34. switch (optionID)
  35. {
  36. case 0:
  37. DeviceCalibrateView.Create(DeviceCalibrateItem.Gyr);
  38. action_OnClickGyr?.Invoke();
  39. break;
  40. case 1:
  41. DeviceCalibrateView.Create(DeviceCalibrateItem.Mag);
  42. action_OnClickMag?.Invoke();
  43. break;
  44. }
  45. });
  46. }
  47. }
  48. void OnDestroy()
  49. {
  50. if (ins == this) ins = null;
  51. PersistenHandler.ins?.menuBackCtr.views.Remove(this);
  52. }
  53. void Update()
  54. {
  55. }
  56. public bool OnMenuBack() {
  57. ViewMgr.Instance.DestroyView<DeviceView>();
  58. return true;
  59. }
  60. public void OnClick_Back() {
  61. AudioMgr.ins.PlayBtn();
  62. ViewMgr.Instance.DestroyView<DeviceView>();
  63. }
  64. void OnChangeSmartArcheryButton(int index) {
  65. //Debug.Log("OnChangeSmartArcheryButton按钮:" + index);
  66. bool _selected = false;
  67. for (int i = 0; i < smartArcheryButtons.Count; i++)
  68. {
  69. Button _button = smartArcheryButtons[i];
  70. Color32 _white;
  71. Color32 _buttonBg;
  72. if (index == i)
  73. {
  74. _white = new Color32(255, 255, 255, 255);
  75. _buttonBg = new Color32(16, 194, 198, 255);
  76. _selected = true;
  77. }
  78. else {
  79. _white = new Color32(59, 59, 59, 255);
  80. _buttonBg = new Color32(255, 255, 255, 255);
  81. }
  82. _button.transform.Find("icon").GetComponent<Image>().color = _white;
  83. _button.transform.Find("title").GetComponent<Text>().color = _white;
  84. _button.transform.Find("arrow").GetComponent<Image>().color = _white;
  85. _button.GetComponent<Image>().color = _buttonBg;
  86. }
  87. if (_selected)
  88. {
  89. //进入选中的页面
  90. AudioMgr.ins.PlayBtn();
  91. ViewMgr.Instance.ShowView<SmartArcheryView>();
  92. }
  93. }
  94. //暂时先更新一个
  95. public void RenderBattery(int deviceID, int value)
  96. {
  97. //smartArcheryButtons[0].GetComponent<DeviceView_ItemShow>().RenderBattery(deviceID,value);
  98. }
  99. }