GuideButtonChangeUI.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using TMPro;
  2. using UnityEngine.EventSystems;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class GuideButtonChangeUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
  6. {
  7. public Image guideButtonBG;
  8. public Image guideIcon;
  9. public Image xIcon;
  10. public TextMeshProUGUI txt;
  11. public Sprite targetBG;
  12. public Sprite targetIcon;
  13. public Sprite targetXIcon;
  14. private Sprite curBG;
  15. private Sprite curIcon;
  16. private Sprite curXIcon;
  17. private void Awake()
  18. {
  19. curBG = guideButtonBG.sprite;
  20. curIcon = guideIcon.sprite;
  21. curXIcon=xIcon.sprite;
  22. #if UNITY_STANDALONE_WIN
  23. #elif UNITY_ANDROID
  24. xIcon.gameObject.SetActive(false);
  25. #elif UNITY_WEBGL
  26. #endif
  27. }
  28. public void OnPointerEnter(PointerEventData eventData)
  29. {
  30. ChangeUI();
  31. }
  32. public void OnPointerExit(PointerEventData eventData)
  33. {
  34. ResetUI();
  35. }
  36. public void ChangeUI()
  37. {
  38. guideButtonBG.sprite = targetBG;
  39. guideIcon.sprite = targetIcon;
  40. xIcon.sprite = targetXIcon;
  41. txt.color = Color.black;
  42. }
  43. public void ResetUI()
  44. {
  45. guideButtonBG.sprite = curBG;
  46. guideIcon.sprite = curIcon;
  47. xIcon.sprite = curXIcon;
  48. txt.color = Color.white;
  49. }
  50. }