请选择 进入手机版 | 继续访问电脑版

查看: 684|回复: 1

[求助] 怎么制作project编辑器窗口的两列模式的效果?

[复制链接]

2

主题

2

帖子

35

贡献

初级UU族—1级

Rank: 1

积分
35
发表于 2018-4-10 09:05:07 | 显示全部楼层 |阅读模式
如图,图一project窗口,图二shader forge窗口
这两个窗口都有两个子窗口,中间的那条线可以拖动改变两边子窗口的占屏比例,请问这是用哪个方法做的?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

24

主题

87

帖子

1295

贡献

超级版主

Rank: 8Rank: 8

积分
1295
发表于 2018-6-12 04:40:53 | 显示全部楼层
本帖最后由 chenjd 于 2018-6-12 05:30 编辑

hi,可以参考下面的代码:
[C#] 纯文本查看 复制代码
using UnityEngine;
using UnityEditor;

public class ResizablePanels : EditorWindow
{
    private Rect upperPanel;
    private Rect lowerPanel;
    private Rect resizer;

    private float sizeRatio = 0.5f;
    private bool isResizing;

    private GUIStyle resizerStyle;

    [MenuItem("Window/Resizable Panels")]
    private static void OpenWindow()
    {
        ResizablePanels window = GetWindow<ResizablePanels>();
        window.titleContent = new GUIContent("Resizable Panels");
    }

    private void OnEnable()
    {
        resizerStyle = new GUIStyle();
        resizerStyle.normal.background = EditorGUIUtility.Load("icons/d_AvatarBlendBackground.png") as Texture2D;
    }

    private void OnGUI()
    {
        DrawUpperPanel();
        DrawLowerPanel();
        DrawResizer();

        ProcessEvents(Event.current);

        if (GUI.changed) Repaint();
    }

    private void DrawUpperPanel()
    {
        upperPanel = new Rect(0, 0, position.width, position.height * sizeRatio);

        GUILayout.BeginArea(upperPanel);
        GUILayout.Label("Upper Panel");
        GUILayout.EndArea();
    }

    private void DrawLowerPanel()
    {
        lowerPanel = new Rect(0, (position.height * sizeRatio) + 5, position.width, position.height * (1 - sizeRatio) - 5);

        GUILayout.BeginArea(lowerPanel);
        GUILayout.Label("Lower Panel");
        GUILayout.EndArea();
    }

    private void DrawResizer()
    {
        resizer = new Rect(0, (position.height * sizeRatio) - 5f, position.width, 10f);

        GUILayout.BeginArea(new Rect(resizer.position + (Vector2.up * 5f), new Vector2(position.width, 2)), resizerStyle);
        GUILayout.EndArea();

        EditorGUIUtility.AddCursorRect(resizer, MouseCursor.ResizeVertical);
    }

    private void ProcessEvents(Event e)
    {
        switch (e.type)
        {
            case EventType.MouseDown:
                if (e.button == 0 && resizer.Contains(e.mousePosition))
                {
                    isResizing = true;
                }
                break;

            case EventType.MouseUp:
                isResizing = false;
                break;
        }

        Resize(e);
    }

    private void Resize(Event e)
    {
        if (isResizing)
        {
            sizeRatio = e.mousePosition.y / position.height;
            Repaint();
        }
    }
}


慕容小匹夫 微软MVP《Unity 3D脚本编程 》作者 陈嘉栋 公众号chenjd01
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表