SmartArcheryView.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. {
  48. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYI);
  49. }
  50. else if (index == 1)
  51. {
  52. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYI2);
  53. }
  54. else if (index == 2)
  55. {
  56. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.ARTEMIS);
  57. }
  58. else if (index == 3) {
  59. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYIPRO);
  60. }
  61. else if (index == 4)
  62. {
  63. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.ARTEMISPRO);
  64. }
  65. else if (index == 5)
  66. {
  67. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYI3);
  68. }
  69. //_white = new Color32(255, 255, 255, 255);
  70. _buttonTitle = new Color32(16, 194, 198, 255);
  71. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[1];
  72. _button.GetComponent<Image>().material = materialGreen;
  73. }
  74. else
  75. {
  76. //_white = new Color32(59, 59, 59, 255);
  77. _buttonTitle = new Color32(0, 0, 0, 255);
  78. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[0];
  79. _button.GetComponent<Image>().material = materialGrey;
  80. }
  81. _button.transform.Find("right/title").GetComponent<Text>().color = _buttonTitle;
  82. //MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
  83. //propertyBlock.SetColor("_BorderColor", _buttonTitle);
  84. //_button.GetComponent<Renderer>().SetPropertyBlock(propertyBlock);
  85. }
  86. if (_selected)
  87. {
  88. //进入选中的页面
  89. AudioMgr.ins.PlayBtn();
  90. //弓箭的目前都不需要解密
  91. BluetoothAim.ins.NeedDecryption = false;
  92. if (index == 3) {
  93. //进入蓝牙连接页面
  94. GameObject connectGuidanceView = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_ConnectGuidanceView);
  95. connectGuidanceView.GetComponent<ConnectGuidanceView>().showTextipInfrared();
  96. //进入红外引导界面
  97. //ViewManager2.ShowView(ViewManager2.Path_InfraredView);
  98. } else {
  99. ViewManager2.ShowView(ViewManager2.Path_ConnectGuidanceView);
  100. }
  101. }
  102. }
  103. public void OnChangeSmartArcheryButtonState(int index)
  104. {
  105. for (int i = 0; i < smartArcheryButtons.Count; i++)
  106. {
  107. Button _button = smartArcheryButtons[i];
  108. // Color32 _white;
  109. Color32 _buttonTitle;
  110. if (index == i)
  111. {
  112. //切换设备类型
  113. if (index == 0)
  114. {
  115. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYI);
  116. }
  117. else if (index == 1)
  118. {
  119. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYI2);
  120. }
  121. else if (index == 2)
  122. {
  123. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.ARTEMIS);
  124. }
  125. else if (index == 3) {
  126. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYIPRO);
  127. }
  128. else if (index == 4)
  129. {
  130. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.ARTEMISPRO);
  131. }
  132. else if (index == 5)
  133. {
  134. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYI3);
  135. }
  136. //_white = new Color32(255, 255, 255, 255);
  137. _buttonTitle = new Color32(16, 194, 198, 255);
  138. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[1];
  139. _button.GetComponent<Image>().material = materialGreen;
  140. }
  141. else
  142. {
  143. //_white = new Color32(59, 59, 59, 255);
  144. _buttonTitle = new Color32(0, 0, 0, 255);
  145. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[0];
  146. _button.GetComponent<Image>().material = materialGrey;
  147. }
  148. _button.transform.Find("right/title").GetComponent<Text>().color = _buttonTitle;
  149. }
  150. }
  151. public void OnClick_Back()
  152. {
  153. Debug.Log("SmartArcheryView OnClick_Back");
  154. AudioMgr.ins.PlayBtn();
  155. ViewMgr.Instance.DestroyView<SmartArcheryView>();
  156. }
  157. }