Why i don't see the button in the Inspector on debug mode ?

Button script:

using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor(typeof(LevelMap))]
public class CustomButton : Editor
{
    public override void OnInspectorGUI()
    {
        LevelMap Generate = (LevelMap)target;
        if (GUILayout.Button("Generate Map"))
        {
            Generate.GenerateNew();
        }
    }
}

And a script that is attached to a empty GameObject the Level Map:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

[ExecuteInEditMode]
public class LevelMap : MonoBehaviour
{
    public GameObject Node;
    public Vector3 nodeSize;
    public int Rows;
    public int Columns;
    public int mapWidth;
    public int mapHeight;
    public float Spacing = 2.0f;
    public float spawnSpeed = 0;

    private void Start()
    {

        Generate();
    }

    private void Generate()
    {
        for (int x = 0; x < mapWidth; x++)
        {
            for (int z = 0; z < mapHeight; z++)
            {
                GameObject block = Instantiate(Node, Vector3.zero, Node.transform.rotation) as GameObject;
                block.transform.parent = transform;
                block.transform.localPosition = new Vector3(x, 0, z);
            }
        }
    }

    public void GenerateNew()
    {
        Generate();
    }
}

One of the problems is that in the Inspector if the mode is normal i see the Generate Button. But i don’t see the public variables of Level Map. If i change the mode to Debug then i will see the Level Map public variables but i will not see the button.

How can i make that i will see the button and the variables at the same mode ? (normal or debug)

Another problem is how can i make that if generated a new map now if i will change one or more of the variables values in the editor it will effect the GenerateMap in real time ? For example if i change the Spacing variable value if it was for example 2 and i change it to 4 then generate a new map but with spacing 4.

So the button is like for reset to generate whole new map but changing variables values will effect the current map only.

https://docs.unity3d.com/ScriptReference/Editor.DrawDefaultInspector.html

1 Like

For the first problem i just added in the button script the line:

DrawDefaultInspector();

For the second problem if i’m not using Update and only Start() it will never effect in real time the map if i change any of the public variables values. Then how can i do it ?