Search Unity

Question How to create an only-vertical scroller?

Discussion in 'Immediate Mode GUI (IMGUI)' started by AzpxMsw, Dec 15, 2022.

  1. AzpxMsw

    AzpxMsw

    Joined:
    Jun 1, 2020
    Posts:
    13
    I used Vector2 scroller = Vector2.zero; to create scroll area in my editor window, but there's a trouble: I have a horizontal scroller. How to create only vertical scroller? Here's a code:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. public class SampleWindow : EditorWindow
    7. {
    8.     bool Colliders;
    9.     bool Components;
    10.     bool Menu;
    11.  
    12.     [MenuItem("Window/Other/Open Sample Window #M")]
    13.     static void onOpen()
    14.     {
    15.         EditorWindow.GetWindow(typeof(SampleWindow));
    16.     }
    17.  
    18.     //Here I need to create only vertical scroller
    19.  
    20.     void OnGUI()
    21.     {
    22.         Menu = EditorGUILayout.Foldout(Menu, "Menu");
    23.         if (Menu)
    24.         {
    25.             EditorGUI.indentLevel++;
    26.             Components = EditorGUILayout.Foldout(Components, "Components");
    27.             if (Components)
    28.             {
    29.                 EditorGUILayout.BeginHorizontal();
    30.                 if (GUILayout.Button("Add Capsule", GUILayout.MinWidth(115), GUILayout.MaxWidth(135)))
    31.                 {
    32.                     if (Selection.activeGameObject != null)
    33.                     {
    34.                         Selection.activeGameObject.AddComponent<CapsuleCollider>();
    35.                     }
    36.                 }
    37.                 if (GUILayout.Button("Add Box 2D", GUILayout.MinWidth(115), GUILayout.MaxWidth(135)))
    38.                 {
    39.                     if (Selection.activeGameObject != null)
    40.                     {
    41.                         Selection.activeGameObject.AddComponent<BoxCollider2D>();
    42.                     }
    43.                 }
    44.                 EditorGUILayout.EndHorizontal();
    45.             }
    46.  
    47.             Colliders = EditorGUILayout.Foldout(Colliders, "Colliders");
    48.             if (Colliders)
    49.             {
    50.                 EditorGUILayout.BeginHorizontal();
    51.                 if (GUILayout.Button("Box", GUILayout.MinWidth(115), GUILayout.MaxWidth(135)))
    52.                 {
    53.                     GameObject build = new GameObject("Box");
    54.                     BoxCollider collider = build.AddComponent<BoxCollider>();
    55.                     collider.isTrigger = true;
    56.                     Selection.activeGameObject = build;
    57.                 }
    58.                 if (GUILayout.Button("Mesh", GUILayout.MinWidth(115), GUILayout.MaxWidth(135)))
    59.                 {
    60.                     GameObject build = new GameObject("Mesh");
    61.                     build.AddComponent<UnityEngine.MeshCollider>();
    62.                     Selection.activeGameObject = build;
    63.                 }
    64.                 EditorGUILayout.EndHorizontal();
    65.             }
    66.             EditorGUI.indentLevel--;
    67.         }
    68.     }
    69. }