上海杨浦大连路地铁站单机版电子沙盘
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

40 lines
1.1 KiB

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<RectTransform>().sizeDelta * eventData.scrollDelta.y * 0.1f;
var sizeDelta = GetComponent<RectTransform>().sizeDelta + step;
if (sizeDelta.x / width > minMultiple && sizeDelta.x / width < maxMultiple)//因为长宽是同比例缩放,所以只判断长即可
{
GetComponent<RectTransform>().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<RectTransform>().sizeDelta = new Vector2(width, height);
}
}