SmartArcheryView.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. int temp = i;
  20. smartArcheryButtons[i].onClick.AddListener(() => {
  21. AudioMgr.ins.PlayBtn();
  22. OnChangeSmartArcheryButton(temp);
  23. });
  24. }
  25. materialGrey = Instantiate(lineMaterial);
  26. materialGreen = Instantiate(lineMaterial);
  27. materialGreen.SetColor("_BorderColor", new Color32(16, 194, 198, 255));
  28. }
  29. // Update is called once per frame
  30. void OnChangeSmartArcheryButton(int index)
  31. {
  32. bool _selected = false;
  33. for (int i = 0; i < smartArcheryButtons.Count; i++)
  34. {
  35. Button _button = smartArcheryButtons[i];
  36. // Color32 _white;
  37. Color32 _buttonTitle;
  38. if (index == i)
  39. {
  40. _selected = true;
  41. //切换设备类型
  42. if (index == 0)
  43. {
  44. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYI);
  45. }
  46. else if (index == 1)
  47. {
  48. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYI2);
  49. }
  50. else if (index == 2)
  51. {
  52. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.ARTEMIS);
  53. }
  54. else if (index == 3) {
  55. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYIPRO);
  56. }
  57. else if (index == 4)
  58. {
  59. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.ARTEMISPRO);
  60. }
  61. //_white = new Color32(255, 255, 255, 255);
  62. _buttonTitle = new Color32(16, 194, 198, 255);
  63. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[1];
  64. _button.GetComponent<Image>().material = materialGreen;
  65. }
  66. else
  67. {
  68. //_white = new Color32(59, 59, 59, 255);
  69. _buttonTitle = new Color32(0, 0, 0, 255);
  70. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[0];
  71. _button.GetComponent<Image>().material = materialGrey;
  72. }
  73. _button.transform.Find("right/title").GetComponent<Text>().color = _buttonTitle;
  74. //MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
  75. //propertyBlock.SetColor("_BorderColor", _buttonTitle);
  76. //_button.GetComponent<Renderer>().SetPropertyBlock(propertyBlock);
  77. }
  78. if (_selected)
  79. {
  80. //进入选中的页面
  81. AudioMgr.ins.PlayBtn();
  82. //弓箭的目前都不需要解密
  83. BluetoothAim.ins.NeedDecryption = false;
  84. if (index == 3) {
  85. //进入蓝牙连接页面
  86. GameObject connectGuidanceView = ViewManager2.getGameObjectAndShowView(ViewManager2.Path_ConnectGuidanceView);
  87. connectGuidanceView.GetComponent<ConnectGuidanceView>().showTextipInfrared();
  88. //进入红外引导界面
  89. //ViewManager2.ShowView(ViewManager2.Path_InfraredView);
  90. } else {
  91. ViewManager2.ShowView(ViewManager2.Path_ConnectGuidanceView);
  92. }
  93. }
  94. }
  95. public void OnChangeSmartArcheryButtonState(int index)
  96. {
  97. for (int i = 0; i < smartArcheryButtons.Count; i++)
  98. {
  99. Button _button = smartArcheryButtons[i];
  100. // Color32 _white;
  101. Color32 _buttonTitle;
  102. if (index == i)
  103. {
  104. //切换设备类型
  105. if (index == 0)
  106. {
  107. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYI);
  108. }
  109. else if (index == 1)
  110. {
  111. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYI2);
  112. }
  113. else if (index == 2)
  114. {
  115. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.ARTEMIS);
  116. }
  117. else if (index == 3) {
  118. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYIPRO);
  119. }
  120. else if (index == 4)
  121. {
  122. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.ARTEMISPRO);
  123. }
  124. //_white = new Color32(255, 255, 255, 255);
  125. _buttonTitle = new Color32(16, 194, 198, 255);
  126. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[1];
  127. _button.GetComponent<Image>().material = materialGreen;
  128. }
  129. else
  130. {
  131. //_white = new Color32(59, 59, 59, 255);
  132. _buttonTitle = new Color32(0, 0, 0, 255);
  133. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[0];
  134. _button.GetComponent<Image>().material = materialGrey;
  135. }
  136. _button.transform.Find("right/title").GetComponent<Text>().color = _buttonTitle;
  137. }
  138. }
  139. public void OnClick_Back()
  140. {
  141. Debug.Log("SmartArcheryView OnClick_Back");
  142. AudioMgr.ins.PlayBtn();
  143. ViewMgr.Instance.DestroyView<SmartArcheryView>();
  144. }
  145. }