Home > Blockchain >  How can I hide or make space between the add component button and other custom buttons in editor scr
How can I hide or make space between the add component button and other custom buttons in editor scr

Time:11-09

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(AddCameras))]
public class Cameras : Editor
{
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        AddCameras myScript = (AddCameras)target;
        if (GUILayout.Button("Add Cameras"))
        {
            myScript.Add();
        }
    }
}

I tried also to remove the line

DrawDefaultInspector();

but the result is the same :

The custom button Add Cameras is too close to the default Add Component button and it's confusing and too close to each other.

buttons too close

CodePudding user response:

Check out GUILayout.Space

You can specify the amount of pixels you want to space by.

GUILayout.Space(10); // <- will add a space of 10 pixels.

There is also the EditorGUILayout class, which also has a Space() function, that adds a predefined space.

EditorGUILayout.Space(); // <- will add a predefined amount of space

In general the GUILayout and EditorGUILayout classes have a lot of nifty helpers which make editor drawing much less tedious.

  • Related