Search Unity

Whats the difference GUILayout vs EditorGUILayout

Discussion in 'Immediate Mode GUI (IMGUI)' started by dojo9, Nov 16, 2020.

  1. dojo9

    dojo9

    Joined:
    Sep 18, 2020
    Posts:
    12
    • I was under the impression that GUILayout is automatic layout for UIElements in the GameScreen
    • and EditorGUILayout is for automatically laying out UI elements in the Editor panels.
    Then I was trying this code in the OnGUI() method

    Code (CSharp):
    1. var newID = EditorGUILayout.TextField("TestID");
    2. var newText = EditorGUILayout.TextField("SampleText");
    3.  
    Which created 2 text fields in the Editor, one below the other

    But if I added a GUILayout.BeginArea()

    Code (CSharp):
    1. GUILayout.BeginArea(new Rect(10, 10, 200, 200));
    2.  
    3. var newID = EditorGUILayout.TextField(node.uniqueID);
    4. var newText = EditorGUILayout.TextField(node.text);
    5.  
    6. GUILayout.EndArea();
    Now the 2 text fields are laid on top of each other.

    • The Question is,
      • GUILayout.BeginArea(),
        • Is it for laying out UI Elements on the GameScreen or on the Editor Panel ?
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Well I'm not quite sure of all the details, but GUILayout is for old IMGUI UI, and EditorGUILayout is part of the same IMGUI system, although it is for editor use. So GUI and GUILayout were for general use UI, and EditorGUI and EditorGUILayout are specializing in Editor UI.

    I've got the impression that it is OK to use and mix both for editor scripts. Although I've used Editor classes where possible.
     
    dojo9 likes this.