我想做的是在将编辑器窗口扩展到底部太多时添加自动垂直滚动:
例如在屏幕截图中,这是原始编辑器窗口大小:
例如,单击“对话”并将其折叠起来时,我想使用垂直滚动条进行滚动:
我可以继续用鼠标向下拉窗口,但在这种情况下,我想使用滚动:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
public class ConversationsEditorWindow : EditorWindow
{
[MenuItem("Window/Editor Window Test")]
static void Init()
{
// Get existing open window or if none, make a new one:
ConversationsEditorWindow window = (ConversationsEditorWindow)EditorWindow.GetWindow(typeof(ConversationsEditorWindow));
}
void OnGUI()
{
GameObject sel = Selection.activeGameObject;
ConversationTrigger targetComp = sel.GetComponent<ConversationTrigger>();
if (targetComp != null)
{
EditorGUILayout.BeginVertical();
var editor = Editor.CreateEditor(targetComp);
var tar = editor.targets;
editor.OnInspectorGUI();
EditorGUILayout.EndScrollView();
EditorGUILayout.EndVertical();
}
}
}
异常消息有点长: 例外是第27行:
EditorGUILayout.EndScrollView();
InvalidOperationException:堆栈为空。 System.Collections.Stack.Peek()(在:0) UnityEngine.GUI.EndScrollView(System.Boolean handleScrollWheel)(在C:/buildslave/unity/build/Modules/IMGUI/GUI.cs:1481) UnityEngine.GUILayout.EndScrollView(System.Boolean handleScrollWheel)(在C:/buildslave/unity/build/Modules/IMGUI/GUILayout.cs:387) UnityEditor.EditorGUILayout.EndScrollView()(在C:/buildslave/unity/build/Editor/Mono/EditorGUI.cs:9203) ConversationsEditorWindow.OnGUI()(在Assets / Editor / ConversationsEditorWindow.cs:27) System.Reflection.MonoMethod.Invoke(System.Object obj,System.Reflection.BindingFlags invokeAttr,System.Reflection.Binder活页夹,System.Object []参数,System.Globalization.CultureInfo文化)(在:0) 作为TargetInvocationException重新抛出:调用的目标已抛出异常。 System.Reflection.MonoMethod.Invoke(System.Object obj,System.Reflection.BindingFlags invokeAttr,System.Reflection.Binder活页夹,System.Object []参数,System.Globalization.CultureInfo文化)(在:0) System.Reflection.MethodBase.Invoke(System.Object obj,System.Object []参数)(位于:0) UnityEditor.HostView.Invoke(System.String methodName,System.Object obj)(在C:/buildslave/unity/build/Editor/Mono/HostView.cs:342) UnityEditor.HostView.Invoke(System.String methodName)(在C:/buildslave/unity/build/Editor/Mono/HostView.cs:336) UnityEditor.HostView.InvokeOnGUI(UnityEngine.Rect onGUIPosition,UnityEngine.Rect viewRect)(在C:/buildslave/unity/build/Editor/Mono/HostView.cs:310) UnityEditor.DockArea.DrawView(UnityEngine.Rect viewRect,UnityEngine.Rect dockAreaRect,System.Boolean customBorder,System.Boolean floatWindow,System.Boolean isBottomTab)(位于C:/ buildslave / unity / build / Editor / Mono / GUI / DockArea。 cs:361) UnityEditor.DockArea.OldOnGUI()(在C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:320) UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI(UnityEngine.Event evt,UnityEngine.Matrix4x4 worldTransform,UnityEngine.Rect clipRect,System.Boolean isComputingLayout)(在C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:244 ) UnityEngine.GUIUtility:ProcessEvent(Int32,IntPtr)
答案 0 :(得分:1)
堆栈为空的消息提供了一个线索-您正在调用:EditorGUILayout.EndScrollView(); (尝试从GUI堆栈弹出)而无需事先调用BeginScrollView()。