SmartArcheryView.cs 5.9 KB

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