示例#1
0
    private static void DrawHandle(ResizableContainerState state)
    {
        Rect rect = new Rect();

        if (state.vertical)
        {
            EditorGUILayout.BeginHorizontal(GUILayout.Height(6));
            GUILayout.FlexibleSpace();
            rect = GUILayoutUtility.GetRect(42, 6, CUResizableContainerStyle.DefaultStyle.resizerVertical);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeVertical);
            GUI.Box(rect, "", CUResizableContainerStyle.DefaultStyle.resizerVertical);
        }
        else
        {
            EditorGUILayout.BeginVertical(GUILayout.Width(6));
            GUILayout.FlexibleSpace();
            rect = GUILayoutUtility.GetRect(6, 42, CUResizableContainerStyle.DefaultStyle.resizerHorizontal);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();
            EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeHorizontal);
            GUI.Box(rect, "", CUResizableContainerStyle.DefaultStyle.resizerHorizontal);
        }

        switch (Event.current.GetTypeForControl(state.controlId))
        {
        case EventType.MouseDown:
            if (!rect.Contains(Event.current.mousePosition) || GUIUtility.hotControl != 0)
            {
                break;
            }
            GUIUtility.hotControl = state.controlId;
            Event.current.Use();
            break;

        case EventType.MouseUp:
            if (GUIUtility.hotControl != state.controlId)
            {
                break;
            }
            GUIUtility.hotControl = 0;
            Event.current.Use();
            break;

        case EventType.MouseDrag:
            if (GUIUtility.hotControl != state.controlId)
            {
                break;
            }
            float delta = state.vertical ? Event.current.delta.y : Event.current.delta.x;
            if (state.handlePosition == HandlePosition.Before)
            {
                delta *= -1;
            }
            state.size     += delta;
            state.applySize = true;
            Event.current.Use();
            break;
        }
    }
    private static void DrawHandle(ResizableContainerState state)
    {
        Rect rect = new Rect();
        if (state.vertical) {
            EditorGUILayout.BeginHorizontal(GUILayout.Height(6));
            GUILayout.FlexibleSpace();
            rect = GUILayoutUtility.GetRect(42, 6, CUResizableContainerStyle.DefaultStyle.resizerVertical);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeVertical);
            GUI.Box(rect, "", CUResizableContainerStyle.DefaultStyle.resizerVertical);
        } else {
            EditorGUILayout.BeginVertical(GUILayout.Width(6));
            GUILayout.FlexibleSpace();
            rect = GUILayoutUtility.GetRect(6, 42, CUResizableContainerStyle.DefaultStyle.resizerHorizontal);
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndVertical();
            EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeHorizontal);
            GUI.Box(rect, "", CUResizableContainerStyle.DefaultStyle.resizerHorizontal);
        }

        switch (Event.current.GetTypeForControl(state.controlId)) {
            case EventType.MouseDown:
                if (!rect.Contains(Event.current.mousePosition) || GUIUtility.hotControl != 0) {
                    break;
                }
                GUIUtility.hotControl = state.controlId;
                Event.current.Use();
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl != state.controlId) {
                    break;
                }
                GUIUtility.hotControl = 0;
                Event.current.Use();
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl != state.controlId) {
                    break;
                }
                float delta = state.vertical ? Event.current.delta.y : Event.current.delta.x;
                if (state.handlePosition == HandlePosition.Before) {
                    delta *= -1;
                }
                state.size += delta;
                state.applySize = true;
                Event.current.Use();
                break;
        }
    }