using UnityEngine; using UnityEngine.EventSystems; /// <summary> /// 按钮缩放效果 /// </summary> public class UIButtonScale : MonoBehaviour, IPointerDownHandler, IPointerUpHandler { [SerializeField] private RectTransform rectTransform; [SerializeField] private Vector2 downScale = new Vector2(1.1f, 1.1f); [SerializeField] private Vector2 upScale = Vector2.one; private void Awake() { if (rectTransform == null) rectTransform = this.GetComponent<RectTransform>(); } public void OnPointerDown(PointerEventData eventData) { rectTransform.localScale = downScale; } public void OnPointerUp(PointerEventData eventData) { rectTransform.localScale = upScale; } }