SmartGunView.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class SmartGunView : JCUnityLib.ViewBase
  6. {
  7. [SerializeField] List<Button> smartArcheryButtons;
  8. [SerializeField] Sprite[] arrowImages;
  9. [SerializeField] Material lineMaterial;
  10. Material materialGrey;
  11. Material materialGreen;
  12. void Start()
  13. {
  14. //ins = this;
  15. for (int i = 0; i < smartArcheryButtons.Count; i++)
  16. {
  17. int temp = i;
  18. smartArcheryButtons[i].onClick.AddListener(() => {
  19. AudioMgr.ins.PlayBtn();
  20. OnChangeSmartArcheryButton(temp);
  21. });
  22. }
  23. materialGrey = Instantiate(lineMaterial);
  24. materialGreen = Instantiate(lineMaterial);
  25. materialGreen.SetColor("_BorderColor", new Color32(16, 194, 198, 255));
  26. }
  27. // Update is called once per frame
  28. void OnChangeSmartArcheryButton(int index)
  29. {
  30. bool _selected = false;
  31. for (int i = 0; i < smartArcheryButtons.Count; i++)
  32. {
  33. Button _button = smartArcheryButtons[i];
  34. Color32 _buttonTitle;
  35. if (index == i)
  36. {
  37. _selected = true;
  38. //切换设备类型
  39. if (index == 0)
  40. {
  41. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.Gun);
  42. }
  43. _buttonTitle = new Color32(16, 194, 198, 255);
  44. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[1];
  45. _button.GetComponent<Image>().material = materialGreen;
  46. }
  47. else
  48. {
  49. //_white = new Color32(59, 59, 59, 255);
  50. _buttonTitle = new Color32(0, 0, 0, 255);
  51. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[0];
  52. _button.GetComponent<Image>().material = materialGrey;
  53. }
  54. _button.transform.Find("right/title").GetComponent<Text>().color = _buttonTitle;
  55. }
  56. if (_selected)
  57. {
  58. //进入选中的页面
  59. AudioMgr.ins.PlayBtn();
  60. if (index == 0)
  61. {
  62. //进入红外引导界面
  63. ViewManager2.ShowView(ViewManager2.Path_InfraredView);
  64. }
  65. }
  66. }
  67. public void OnChangeSmartArcheryButtonState(int index)
  68. {
  69. for (int i = 0; i < smartArcheryButtons.Count; i++)
  70. {
  71. Button _button = smartArcheryButtons[i];
  72. // Color32 _white;
  73. Color32 _buttonTitle;
  74. if (index == i)
  75. {
  76. //切换设备类型
  77. if (index == 0)
  78. {
  79. AimHandler.ins.SetTempAimDeviceType(AimDeviceType.Gun);
  80. }
  81. //_white = new Color32(255, 255, 255, 255);
  82. _buttonTitle = new Color32(16, 194, 198, 255);
  83. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[1];
  84. _button.GetComponent<Image>().material = materialGreen;
  85. }
  86. else
  87. {
  88. //_white = new Color32(59, 59, 59, 255);
  89. _buttonTitle = new Color32(0, 0, 0, 255);
  90. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[0];
  91. _button.GetComponent<Image>().material = materialGrey;
  92. }
  93. _button.transform.Find("right/title").GetComponent<Text>().color = _buttonTitle;
  94. }
  95. }
  96. public void OnClick_Back()
  97. {
  98. Debug.Log("SmartGunView OnClick_Back");
  99. AudioMgr.ins.PlayBtn();
  100. ViewMgr.Instance.DestroyView<SmartGunView>();
  101. }
  102. }