1
votes

What I'm trying to do is to add automatic vertical scroll when expanding the editorwindow too much to the bottom :

If in the screenshot for example this is the original editorwindow size :

Editor Window original size

When clicking for example the Conversations and collapsing it then I want to make it with a vertical scroll :

I can keep stretching down the window with the mouse but I want to use scroll in that case instead :

Editor Window collapsed down stretched with the mouse dragging down

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

The exception message is a bit long : The exception is on line 27 :

EditorGUILayout.EndScrollView();

InvalidOperationException: Stack empty. System.Collections.Stack.Peek () (at :0) UnityEngine.GUI.EndScrollView (System.Boolean handleScrollWheel) (at C:/buildslave/unity/build/Modules/IMGUI/GUI.cs:1481) UnityEngine.GUILayout.EndScrollView (System.Boolean handleScrollWheel) (at C:/buildslave/unity/build/Modules/IMGUI/GUILayout.cs:387) UnityEditor.EditorGUILayout.EndScrollView () (at C:/buildslave/unity/build/Editor/Mono/EditorGUI.cs:9203) ConversationsEditorWindow.OnGUI () (at Assets/Editor/ConversationsEditorWindow.cs:27) System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at :0) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at :0) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at :0) UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:342) UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:336) UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:310) UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect, System.Boolean customBorder, System.Boolean floatingWindow, System.Boolean isBottomTab) (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:361) UnityEditor.DockArea.OldOnGUI () (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:320) UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:244) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

1

1 Answers

1
votes

Stack empty message gives a clue what goes on - you are making a call to : EditorGUILayout.EndScrollView(); (trying to pop from gui stack) without calling BeginScrollView() beforehand.