using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; public class OnScrollPanel : MonoBehaviour, IScrollHandler { public float width; public float height; public float minMultiple; public float maxMultiple; public void OnScroll(PointerEventData eventData) { var step = GetComponent().sizeDelta * eventData.scrollDelta.y * 0.1f; var sizeDelta = GetComponent().sizeDelta + step; if (sizeDelta.x / width > minMultiple && sizeDelta.x / width < maxMultiple)//因为长宽是同比例缩放,所以只判断长即可 { GetComponent().sizeDelta += step; } } // Use this for initialization void Start() { } // Update is called once per frame void Update() { } public void SetSize(Texture2D texture) { width = texture.width; height = texture.height; GetComponent().sizeDelta = new Vector2(width, height); } }