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;
- }
- }
本文介绍了一个使用Unity创建的自定义编辑器窗口SplitViewWindow,该窗口通过一个可调整大小的分隔条实现了上下两部分视图的展示,并允许用户通过鼠标拖动来调整分界线的位置。
4万+

被折叠的 条评论
为什么被折叠?



