Unity3d从右下角用鼠标调整面板大小
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity3d从右下角用鼠标调整面板大小相关的知识,希望对你有一定的参考价值。
我想用鼠标调整UI面板的大小。我自己不知道怎么做。我怎样才能做到这一点?
答案
这是一个简短的问题,所以我不确定你是否想要任何非常具体的东西,但这是我在Unity Tutorials Website上找到的东西。似乎是你在寻找的东西:
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class ResizePanel : MonoBehaviour, IPointerDownHandler, IDragHandler {
public Vector2 minSize;
public Vector2 maxSize;
private RectTransform rectTransform;
private Vector2 currentPointerPosition;
private Vector2 previousPointerPosition;
void Awake () {
rectTransform = transform.parent.GetComponent<RectTransform>();
}
public void OnPointerDown (PointerEventData data) {
rectTransform.SetAsLastSibling();
RectTransformUtility.ScreenPointToLocalPointInRectangle (rectTransform, data.position, data.pressEventCamera, out previousPointerPosition);
}
public void OnDrag (PointerEventData data) {
if (rectTransform == null)
return;
Vector2 sizeDelta = rectTransform.sizeDelta;
RectTransformUtility.ScreenPointToLocalPointInRectangle (rectTransform, data.position, data.pressEventCamera, out currentPointerPosition);
Vector2 resizeValue = currentPointerPosition - previousPointerPosition;
sizeDelta += new Vector2 (resizeValue.x, -resizeValue.y);
sizeDelta = new Vector2 (
Mathf.Clamp (sizeDelta.x, minSize.x, maxSize.x),
Mathf.Clamp (sizeDelta.y, minSize.y, maxSize.y)
);
rectTransform.sizeDelta = sizeDelta;
previousPointerPosition = currentPointerPosition;
}
}
以上是关于Unity3d从右下角用鼠标调整面板大小的主要内容,如果未能解决你的问题,请参考以下文章