37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
namespace CaoCao.Editor
|
|
{
|
|
public class VerticalSplitter
|
|
{
|
|
private const int size = 3;
|
|
private float percent = 0.8f;
|
|
public Rect rect;
|
|
public bool resizing { get; private set; }
|
|
|
|
public void OnGUI(Rect position)
|
|
{
|
|
rect.y = (int) (position.yMin + position.height * percent);
|
|
rect.width = position.width;
|
|
rect.height = size;
|
|
EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeVertical);
|
|
if (UnityEngine.Event.current.type == EventType.MouseDown &&
|
|
rect.Contains(UnityEngine.Event.current.mousePosition))
|
|
resizing = true;
|
|
|
|
if (resizing)
|
|
{
|
|
var mousePosInRect = UnityEngine.Event.current.mousePosition.y - position.yMin;
|
|
percent = Mathf.Clamp(mousePosInRect / position.height, 0.20f, 0.90f);
|
|
rect.y = (int) (position.height * percent + position.yMin);
|
|
|
|
if (UnityEngine.Event.current.type == EventType.MouseUp) resizing = false;
|
|
}
|
|
else
|
|
{
|
|
percent = Mathf.Clamp(percent, 0.20f, 0.90f);
|
|
}
|
|
}
|
|
}
|
|
} |