如何根据内容更改编辑器窗口大小?

时间:2019-05-16 01:52:28

标签: c# unity3d

例如,我将窗口大小设置为800x800,滚动视图大小为800x800

但是在这种情况下,如果内容没有展开,则内容在顶部,但窗口的其余部分为空。我现在可以自己调整窗口大小,但是当我扩展内容时,我将不得不再次调整窗口大小。

视觉效果不好。

Content is not much so most of the window is empty

然后在扩展内容时: 现在内容超出了窗口大小,因此现在显示了滚动视图:

Content is too long so the scroll view is now show

但是现在我有另一个问题。垂直滚动视图不起作用。尝试向下滚动时,请继续向上移动滚动条。它永远不会下降。

如果我要收起内容的备份,它将看起来像第一个屏幕截图一样。

通常,我的问题是如何将窗口大小与滚动视图和内容一起使用,以使其在第一个屏幕截图中看起来不像,并且滚动视图在显示时将起作用。

编辑器窗口脚本:

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;

public class ConversationsEditorWindow : EditorWindow
{
    Vector2 scrollPos;

    [MenuItem("Window/Editor Window Test")]
    static void Init()
    {
        const int width = 800;
        const int height = 800;

        var x = (Screen.currentResolution.width - width) / 2;
        var y = (Screen.currentResolution.height - height) / 2;

        GetWindow<ConversationsEditorWindow>().position = new Rect(x, y, width, height);
    }

    void OnGUI()
    {
        GameObject sel = Selection.activeGameObject;
        ConversationTrigger targetComp = sel.GetComponent<ConversationTrigger>();

        if (targetComp != null)
        {
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(800), GUILayout.Height(800));
            var editor = Editor.CreateEditor(targetComp);
            var tar = editor.targets;
            editor.OnInspectorGUI();
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

您的滚动视图不起作用,因为需要保存当前滚动位置:

scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(800), GUILayout.Height(800));
相关问题