Allow player to resize Panel UI,Resizable UI Panel
I'm attempting to create a UI Panel that players would be able to resize as they see fit. I have the following prefab that contains a content area, scroll bar, top bar for dragging, and a panel element that I'm using for the resizing action:

Attached to the prefab, I have the following script I found from the Unity UI Cookbook that I'm currently using for the resizing logic:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ResizablePanelScript : MonoBehaviour
{
private Vector2 initialMousePos;
private Vector2 initialDeltaSize;
private RectTransform rectTransform;
private void Awake()
{
if (rectTransform == null)
{
rectTransform = transform.parent.GetComponent<RectTransform>();
}
}
public void OnDragBegins()
{
initialMousePos = Input.mousePosition;
initialDeltaSize = rectTransform.sizeDelta;
}
public void OnDrag()
{
Vector2 temp = (Vector2)initialMousePos - (Vector2)Input.mousePosition;
temp = new Vector2(-temp.x, temp.y);
temp += initialDeltaSize;
rectTransform.sizeDelta = temp;
}
}
However, as shown in this gif, the resizing occurs from the center of the panel and seems to scale in all 4 directions. It also has the ability to resize negatively past the size of the elements which causes the panel to disappear. I'm fairly new to Unity and am not really sure what I would need to do to be able to edit this so that it only changes the bottom and right lengths of the panel, or to set a minimum size that it can't go past.
Your answer