DeviceView.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. public static DeviceView ins;
  13. public Action action_OnClickGyr;
  14. public Action action_OnClickMag;
  15. void Start()
  16. {
  17. ins = this;
  18. PersistenHandler.ins?.menuBackCtr.views.Add(this);
  19. for (int i = 0; i < smartArcheryButtons.Count; i++)
  20. {
  21. int temp = i;
  22. smartArcheryButtons[i].onClick.AddListener(()=>{
  23. AudioMgr.ins.PlayBtn();
  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. }
  49. void OnDestroy()
  50. {
  51. if (ins == this) ins = null;
  52. PersistenHandler.ins?.menuBackCtr.views.Remove(this);
  53. }
  54. void Update()
  55. {
  56. }
  57. public bool OnMenuBack() {
  58. ViewMgr.Instance.DestroyView<DeviceView>();
  59. return true;
  60. }
  61. public void OnClick_Back() {
  62. AudioMgr.ins.PlayBtn();
  63. ViewMgr.Instance.DestroyView<DeviceView>();
  64. }
  65. void OnChangeSmartArcheryButton(int index) {
  66. //Debug.Log("OnChangeSmartArcheryButton按钮:" + index);
  67. bool _selected = false;
  68. for (int i = 0; i < smartArcheryButtons.Count; i++)
  69. {
  70. Button _button = smartArcheryButtons[i];
  71. Color32 _white;
  72. Color32 _buttonBg;
  73. if (index == i)
  74. {
  75. _white = new Color32(255, 255, 255, 255);
  76. //_buttonBg = new Color32(16, 194, 198, 255);
  77. _selected = true;
  78. _button.GetComponent<Image>().sprite = smartArcheryBg[1];
  79. }
  80. else {
  81. _white = new Color32(59, 59, 59, 255);
  82. //_buttonBg = new Color32(255, 255, 255, 255);
  83. _button.GetComponent<Image>().sprite = smartArcheryBg[0];
  84. }
  85. _button.transform.Find("icon").GetComponent<Image>().color = _white;
  86. _button.transform.Find("title").GetComponent<Text>().color = _white;
  87. _button.transform.Find("arrow").GetComponent<Image>().color = _white;
  88. }
  89. if (_selected)
  90. {
  91. //进入选中的页面
  92. AudioMgr.ins.PlayBtn();
  93. ViewMgr.Instance.ShowView<SmartArcheryView>();
  94. }
  95. }
  96. //暂时先更新一个
  97. public void RenderBattery(int deviceID, int value)
  98. {
  99. //smartArcheryButtons[0].GetComponent<DeviceView_ItemShow>().RenderBattery(deviceID,value);
  100. }
  101. }