简体   繁体   English

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

[英]How can I change the editor window size depending on the content?

For example I set the window size to 800x800 also the scroll view size is 800x800例如,我将窗口大小设置为 800x800,滚动视图大小也为 800x800

But in this case when the content is not expanded so the content is on the top but the rest of the window is empty.但在这种情况下,当内容未展开时,内容位于顶部,但窗口的其余部分为空。 I could resize the window now on my own but then when I expand the content I will have to resize the window again.我现在可以自己调整窗口大小,但是当我展开内容时,我将不得不再次调整窗口大小。

Visual it looks bad.视觉上看起来很糟糕。

内容不多所以大部分窗口都是空的

Then when expanding the content : Now the content is over too much the window size so now the scroll view is show up :然后在扩展内容时:现在内容超过了窗口大小,所以现在显示滚动视图:

内容太长,所以现在显示滚动视图

But now I have another problem.但现在我有另一个问题。 The scroll view vertical is not working.滚动视图垂直不起作用。 When trying to scroll down it keep moving the scroller back up.当尝试向下滚动时,它会不断向上移动滚动条。 It never move down.它永远不会向下移动。

And if I will collapse back up the content it will look like again like in the first screenshot.如果我将内容折叠起来,它会再次像第一个屏幕截图中那样。

In general my problem is how to use the window size with the scroll view and the content so it will not look like in the first screenshot and that the scroll view will work when it show up.一般来说,我的问题是如何将窗口大小与滚动视图和内容一起使用,这样它就不会在第一个屏幕截图中看起来像,并且滚动视图在显示时会起作用。

The editor window script :编辑器窗口脚本:

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();
        }
    }
}

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

scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(800), GUILayout.Height(800));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM