Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何根据内容更改编辑器窗口的大小?_C#_Unity3d - Fatal编程技术网

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

C# 如何根据内容更改编辑器窗口的大小?,c#,unity3d,C#,Unity3d,例如,我将窗口大小设置为800x800,滚动视图大小也设置为800x800 但在这种情况下,当内容未展开时,内容位于顶部,而窗口的其余部分为空。我现在可以自己调整窗口大小,但当我展开内容时,我必须再次调整窗口大小 看起来很糟糕 然后在展开内容时: 现在内容超过了窗口大小,因此现在显示滚动视图: 但现在我有另一个问题。垂直滚动视图不工作。当尝试向下滚动时,请继续向上移动滚动条。它从不向下移动 如果我将折叠备份内容,它将再次出现在第一个屏幕截图中 一般来说,我的问题是如何在滚动视图和内容中使用窗

例如,我将窗口大小设置为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();
        }
    }
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEditor;
使用UnityEditorInternal;
使用UnityEngine;
公共类会话编辑器窗口:编辑器窗口
{
向量2;
[菜单项(“窗口/编辑器窗口测试”)]
静态void Init()
{
常数int宽度=800;
const int height=800;
var x=(Screen.currentResolution.width-width)/2;
变量y=(Screen.currentResolution.height-height)/2;
GetWindow().position=新矩形(x、y、宽度、高度);
}
void OnGUI()
{
GameObject sel=Selection.activeGameObject;
ConversationTrigger targetComp=sel.GetComponent();
如果(targetComp!=null)
{
EditorGUILayout.beginitalic();
EditorGUILayout.BeginScrollView(scrollPos,Guillayout.Width(800),Guillayout.Height(800));
var editor=editor.CreateEditor(targetComp);
var tar=editor.targets;
OnInspectorGUI();
EditorGUILayout.EndScrollView();
EditorGUILayout.EndVertical();
}
}
}

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

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

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

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