SmartArcheryView.cs 5.0 KB

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