SmartGunView.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class SmartGunView : JCUnityLib.ViewBase
  6. {
  7. [SerializeField] List<Button> smartArcheryButtons;
  8. [SerializeField] Sprite[] arrowImages;
  9. [SerializeField] Material lineMaterial;
  10. Material materialGrey;
  11. Material materialGreen;
  12. void Start()
  13. {
  14. //ins = this;
  15. for (int i = 0; i < smartArcheryButtons.Count; i++)
  16. {
  17. int temp = i;
  18. smartArcheryButtons[i].onClick.AddListener(() => {
  19. AudioMgr.ins.PlayBtn();
  20. OnChangeSmartArcheryButton(temp);
  21. });
  22. }
  23. materialGrey = Instantiate(lineMaterial);
  24. materialGreen = Instantiate(lineMaterial);
  25. materialGreen.SetColor("_BorderColor", new Color32(16, 194, 198, 255));
  26. }
  27. // Update is called once per frame
  28. void OnChangeSmartArcheryButton(int index)
  29. {
  30. bool _selected = false;
  31. for (int i = 0; i < smartArcheryButtons.Count; i++)
  32. {
  33. Button _button = smartArcheryButtons[i];
  34. Color32 _buttonTitle;
  35. if (index == i)
  36. {
  37. _selected = true;
  38. //切换设备类型
  39. if (index == 0)
  40. {
  41. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.Gun);
  42. }
  43. _buttonTitle = new Color32(16, 194, 198, 255);
  44. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[1];
  45. _button.GetComponent<Image>().material = materialGreen;
  46. }
  47. else
  48. {
  49. //_white = new Color32(59, 59, 59, 255);
  50. _buttonTitle = new Color32(0, 0, 0, 255);
  51. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[0];
  52. _button.GetComponent<Image>().material = materialGrey;
  53. }
  54. _button.transform.Find("right/title").GetComponent<Text>().color = _buttonTitle;
  55. }
  56. if (_selected)
  57. {
  58. //进入选中的页面
  59. AudioMgr.ins.PlayBtn();
  60. if (index == 0)
  61. {
  62. //进入蓝牙连接页面
  63. GameObject connectGuidanceView = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_ConnectGuidanceView);
  64. connectGuidanceView.GetComponent<ConnectGuidanceView>().showTextipInfrared();
  65. //这个需要解密
  66. BluetoothAim.ins.NeedDecryption = true;
  67. //进入红外引导界面
  68. //ViewManager2.ShowView(ViewManager2.Path_InfraredView);
  69. }
  70. }
  71. }
  72. public void OnChangeSmartArcheryButtonState(int index)
  73. {
  74. for (int i = 0; i < smartArcheryButtons.Count; i++)
  75. {
  76. Button _button = smartArcheryButtons[i];
  77. // Color32 _white;
  78. Color32 _buttonTitle;
  79. if (index == i)
  80. {
  81. //切换设备类型
  82. if (index == 0)
  83. {
  84. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.Gun);
  85. }
  86. //_white = new Color32(255, 255, 255, 255);
  87. _buttonTitle = new Color32(16, 194, 198, 255);
  88. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[1];
  89. _button.GetComponent<Image>().material = materialGreen;
  90. }
  91. else
  92. {
  93. //_white = new Color32(59, 59, 59, 255);
  94. _buttonTitle = new Color32(0, 0, 0, 255);
  95. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[0];
  96. _button.GetComponent<Image>().material = materialGrey;
  97. }
  98. _button.transform.Find("right/title").GetComponent<Text>().color = _buttonTitle;
  99. }
  100. }
  101. public void OnClick_Back()
  102. {
  103. Debug.Log("SmartGunView OnClick_Back");
  104. AudioMgr.ins.PlayBtn();
  105. ViewMgr.Instance.DestroyView<SmartGunView>();
  106. }
  107. }