BagButtonChangeUI.cs 1.3 KB

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