贺州人民医院电子沙盘
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.
 
 
 
 

63 lines
2.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class OnZoomPanel : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
{
private RectTransform canvasRect;
public RectTransform transRect;
private Vector2 localPos;
public float minWidth;
public float minHeight;
//private Vector2 offSet;
void Start()
{
canvasRect = GameObject.Find("Canvas").GetComponent<RectTransform>();
//transRect = GetComponent<RectTransform>();
//offSet = localPos = Vector3.zero;
}
public void OnBeginDrag(PointerEventData eventData)
{
if (eventData.button != PointerEventData.InputButton.Left)//不是左键按下就不能拖拽
{
return;
}
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, eventData.position, canvasRect.GetComponent<Canvas>().worldCamera, out localPos))
{
//offSet = localPos - new Vector2(transRect.localPosition.x, transRect.localPosition.y);
InputManager.isDargUI = true;
transform.SetAsLastSibling();
}
}
public void OnDrag(PointerEventData eventData)
{
if (eventData.button != PointerEventData.InputButton.Left) return;//不是左键按下就不能拖拽
Vector2 newPos;
if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRect, eventData.position, canvasRect.GetComponent<Canvas>().worldCamera, out newPos))
{
var dragOffset = newPos - localPos;
var newX = transRect.sizeDelta.x + dragOffset.x;
var newY = transRect.sizeDelta.y - dragOffset.y;
if (newX < minWidth)
{
newX = minWidth;
}
if (newY < minHeight)
{
newY = minHeight;
}
transRect.sizeDelta = new Vector2(newX, newY);
localPos = newPos;
}
}
public void OnEndDrag(PointerEventData eventData)
{
if (eventData.button != PointerEventData.InputButton.Left) return;//不是左键按下就不能拖拽
InputManager.isDargUI = false;
}
}