Some checks failed
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (push) Successful in 5m54s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (push) Successful in 5m43s
Build project / Publish to itch.io (StandaloneLinux64) (push) Successful in 11s
Build project / Publish to itch.io (StandaloneWindows64) (push) Successful in 9s
Build project / Build for (StandaloneWindows64, 6000.0.37f1) (pull_request) Has been cancelled
Build project / Publish to itch.io (StandaloneLinux64) (pull_request) Has been cancelled
Build project / Publish to itch.io (StandaloneWindows64) (pull_request) Has been cancelled
Build project / Build for (StandaloneLinux64, 6000.0.37f1) (pull_request) Has been cancelled
39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.EventSystems;
|
|
|
|
public class ResizePanel : MonoBehaviour, IPointerDownHandler, IDragHandler {
|
|
|
|
public Vector2 minSize = new Vector2 (100, 100);
|
|
public Vector2 maxSize = new Vector2 (400, 400);
|
|
|
|
private RectTransform panelRectTransform;
|
|
private Vector2 originalLocalPointerPosition;
|
|
private Vector2 originalSizeDelta;
|
|
|
|
void Awake () {
|
|
panelRectTransform = transform.parent.GetComponent<RectTransform> ();
|
|
}
|
|
|
|
public void OnPointerDown (PointerEventData data) {
|
|
originalSizeDelta = panelRectTransform.sizeDelta;
|
|
RectTransformUtility.ScreenPointToLocalPointInRectangle (panelRectTransform, data.position, data.pressEventCamera, out originalLocalPointerPosition);
|
|
}
|
|
|
|
public void OnDrag (PointerEventData data) {
|
|
if (panelRectTransform == null)
|
|
return;
|
|
|
|
Vector2 localPointerPosition;
|
|
RectTransformUtility.ScreenPointToLocalPointInRectangle (panelRectTransform, data.position, data.pressEventCamera, out localPointerPosition);
|
|
Vector3 offsetToOriginal = localPointerPosition - originalLocalPointerPosition;
|
|
|
|
Vector2 sizeDelta = originalSizeDelta + new Vector2 (offsetToOriginal.x, -offsetToOriginal.y);
|
|
sizeDelta = new Vector2 (
|
|
Mathf.Clamp (sizeDelta.x, minSize.x, maxSize.x),
|
|
Mathf.Clamp (sizeDelta.y, minSize.y, maxSize.y)
|
|
);
|
|
|
|
panelRectTransform.sizeDelta = sizeDelta;
|
|
}
|
|
} |