SmartArcheryView.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. //_white = new Color32(255, 255, 255, 255);
  42. _buttonTitle = new Color32(16, 194, 198, 255);
  43. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[1];
  44. _button.GetComponent<Image>().material = materialGreen;
  45. }
  46. else
  47. {
  48. //_white = new Color32(59, 59, 59, 255);
  49. _buttonTitle = new Color32(0, 0, 0, 255);
  50. _button.transform.Find("right/arrow").GetComponent<Image>().sprite = arrowImages[0];
  51. _button.GetComponent<Image>().material = materialGrey;
  52. }
  53. _button.transform.Find("right/title").GetComponent<Text>().color = _buttonTitle;
  54. //MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
  55. //propertyBlock.SetColor("_BorderColor", _buttonTitle);
  56. //_button.GetComponent<Renderer>().SetPropertyBlock(propertyBlock);
  57. }
  58. if (_selected)
  59. {
  60. //½øÈëÑ¡ÖеÄÒ³Ãæ
  61. AudioMgr.ins.PlayBtn();
  62. }
  63. }
  64. public void OnClick_Back()
  65. {
  66. AudioMgr.ins.PlayBtn();
  67. ViewMgr.Instance.DestroyView<SmartArcheryView>();
  68. }
  69. }