Editor splitview 示例

using UnityEngine;
using UnityEditor;

public class SplitViewWindow : EditorWindow
{
    private Vector2 scrollPos = Vector2.zero;
    float currentScrollViewHeight;
    bool resize = false;
    Rect cursorChangeRect;

    [MenuItem("MyWindows/SplitView")]
    public static void Init()
    {
        EditorWindow t = GetWindow<SplitViewWindow>();
    }

    void OnEnable()
    {
        this.position = new Rect(200, 200, 400, 300);
        currentScrollViewHeight = this.position.height / 2;
        cursorChangeRect = new Rect(0, currentScrollViewHeight, this.position.width, 5f);
    }

    void OnGUI()
    {
        GUILayout.BeginVertical();
        scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(currentScrollViewHeight));
        for (int i = 0; i < 20; i++)
            GUILayout.Label("dfs");
        GUILayout.EndScrollView();

        ResizeScrollView();

        GUILayout.FlexibleSpace();
        GUILayout.Label("Lower part");

        GUILayout.EndVertical();
        Repaint();
    }

    private void ResizeScrollView()
    {
        GUI.color = Color.blue;
        GUI.DrawTexture(cursorChangeRect, EditorGUIUtility.whiteTexture);
        EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeVertical);

        if (Event.current.type == EventType.mouseDown && cursorChangeRect.Contains(Event.current.mousePosition))
        {
            resize = true;
        }
        if (resize)
        {
            currentScrollViewHeight = Event.current.mousePosition.y;
            cursorChangeRect.Set(cursorChangeRect.x, currentScrollViewHeight, cursorChangeRect.width, cursorChangeRect.height);
        }
        if (Event.current.type == EventType.MouseUp)
            resize = false;
    }
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容