Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Question Why EditorGUILayout.BeginScrollView in editorwindow script not showing the horizontal scroll bar?

Discussion in 'Immediate Mode GUI (IMGUI)' started by eshelshlomi1999, May 2, 2023.

  1. eshelshlomi1999

    eshelshlomi1999

    Joined:
    Apr 1, 2023
    Posts:
    17
    it's showing only the vertical scrolling bar.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4. using System.Collections;
    5. using System.Collections.Generic;
    6. using System.Reflection;
    7. using System;
    8. using System.Linq;
    9. using System.Xml;
    10. using static Unity.VisualScripting.Member;
    11.  
    12. public class ScriptFinder : EditorWindow
    13. {
    14.     static ScriptFinder window;
    15.     static Dictionary<GameObject, string> dictio = new Dictionary<GameObject, string>();
    16.     Vector2 scrollPos;
    17.  
    18.     [MenuItem("EditorUtility/Script Finder")]
    19.     static void OpenScriptFinder()
    20.     {
    21.         window = (ScriptFinder)EditorWindow.GetWindow(typeof(ScriptFinder));
    22.  
    23.         MonoBehaviour[] scripts = UnityEngine.Object.FindObjectsOfType<MonoBehaviour>();
    24.         foreach (MonoBehaviour script in scripts)
    25.         {
    26.             Type scriptType = script.GetType();
    27.             var scope = scriptType.Namespace;
    28.             if (scope == null || !scope.StartsWith("Unity"))
    29.             {
    30.                 if (!dictio.Keys.Contains(script.gameObject))
    31.                 {
    32.                     dictio.Add(script.gameObject, scriptType.Name);
    33.                 }
    34.             }
    35.         }
    36.     }
    37.  
    38.     void OnGUI()
    39.     {
    40.         GUI.color = Color.white;
    41.  
    42.         scrollPos =
    43.             EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(position.width), GUILayout.Height(position.height));
    44.         foreach (KeyValuePair<GameObject, string> pair in dictio)
    45.         {
    46.             EditorGUILayout.BeginHorizontal();
    47.  
    48.             EditorGUILayout.ObjectField(pair.Key, typeof(GameObject), true);
    49.             EditorGUILayout.TextField(pair.Value);
    50.  
    51.             EditorGUILayout.EndHorizontal();
    52.         }
    53.         GUILayout.EndScrollView();
    54.     }
    55. }
    56.  
    the result is that some text on the right is getting swallow.
    I can drag and expand more the window size, but I want to display horizontal scroll bar or to set automatic the window width size so it will show all the text on the width.

    result: