UGUI—UIButtonScale

作者:追风剑情 发布于:2022-7-8 15:17 分类:Unity3d

  1. using UnityEngine;
  2. using UnityEngine.EventSystems;
  3. /// <summary>
  4. /// 按钮缩放效果
  5. /// </summary>
  6. public class UIButtonScale : MonoBehaviour, IPointerDownHandler, IPointerUpHandler
  7. {
  8. [SerializeField]
  9. private RectTransform rectTransform;
  10. [SerializeField]
  11. private Vector2 downScale = new Vector2(1.1f, 1.1f);
  12. [SerializeField]
  13. private Vector2 upScale = Vector2.one;
  14.  
  15. private void Awake()
  16. {
  17. if (rectTransform == null)
  18. rectTransform = this.GetComponent<RectTransform>();
  19. }
  20.  
  21. public void OnPointerDown(PointerEventData eventData)
  22. {
  23. rectTransform.localScale = downScale;
  24. }
  25.  
  26. public void OnPointerUp(PointerEventData eventData)
  27. {
  28. rectTransform.localScale = upScale;
  29. }
  30. }

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号