【问题标题】:How can I change the editor window size depending on the content?如何根据内容更改编辑器窗口大小?
【发布时间】:2020-01-11 07:32:25
【问题描述】:

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

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

视觉上看起来很糟糕。

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

但现在我遇到了另一个问题。垂直滚动视图不起作用。当试图向下滚动时,它会继续向上移动滚动条。它永远不会向下移动。

如果我将内容折叠起来,它会再次像第一个屏幕截图一样。

一般来说,我的问题是如何将窗口大小与滚动视图和内容一起使用,这样它就不会像第一个屏幕截图中那样,并且滚动视图在显示时会起作用。

编辑器窗口脚本:

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

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    您的滚动视图无法正常工作,因为需要保存当前滚动位置:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      • 1970-01-01
      • 2016-11-23
      相关资源
      最近更新 更多