SmartArcheryView.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. //_white = new Color32(255, 255, 255, 255);
  58. _buttonTitle = new Color32(16, 194, 198, 255);
  59. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[1];
  60. _button.GetComponent<Image>().material = materialGreen;
  61. }
  62. else
  63. {
  64. //_white = new Color32(59, 59, 59, 255);
  65. _buttonTitle = new Color32(0, 0, 0, 255);
  66. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[0];
  67. _button.GetComponent<Image>().material = materialGrey;
  68. }
  69. _button.transform.Find("right/title").GetComponent<Text>().color = _buttonTitle;
  70. //MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
  71. //propertyBlock.SetColor("_BorderColor", _buttonTitle);
  72. //_button.GetComponent<Renderer>().SetPropertyBlock(propertyBlock);
  73. }
  74. if (_selected)
  75. {
  76. //进入选中的页面
  77. AudioMgr.ins.PlayBtn();
  78. if (index == 3) {
  79. //进入红外引导界面
  80. ViewManager2.ShowView(ViewManager2.Path_InfraredView);
  81. } else {
  82. ViewManager2.ShowView(ViewManager2.Path_ConnectGuidanceView);
  83. }
  84. }
  85. }
  86. public void OnChangeSmartArcheryButtonState(int index)
  87. {
  88. for (int i = 0; i < smartArcheryButtons.Count; i++)
  89. {
  90. Button _button = smartArcheryButtons[i];
  91. // Color32 _white;
  92. Color32 _buttonTitle;
  93. if (index == i)
  94. {
  95. //切换设备类型
  96. if (index == 0)
  97. {
  98. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYI);
  99. }
  100. else if (index == 1)
  101. {
  102. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYI2);
  103. }
  104. else if (index == 2)
  105. {
  106. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.ARTEMIS);
  107. }
  108. else if (index == 3) {
  109. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYIPRO);
  110. }
  111. //_white = new Color32(255, 255, 255, 255);
  112. _buttonTitle = new Color32(16, 194, 198, 255);
  113. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[1];
  114. _button.GetComponent<Image>().material = materialGreen;
  115. }
  116. else
  117. {
  118. //_white = new Color32(59, 59, 59, 255);
  119. _buttonTitle = new Color32(0, 0, 0, 255);
  120. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[0];
  121. _button.GetComponent<Image>().material = materialGrey;
  122. }
  123. _button.transform.Find("right/title").GetComponent<Text>().color = _buttonTitle;
  124. }
  125. }
  126. public void OnClick_Back()
  127. {
  128. Debug.Log("SmartArcheryView OnClick_Back");
  129. AudioMgr.ins.PlayBtn();
  130. ViewMgr.Instance.DestroyView<SmartArcheryView>();
  131. }
  132. }