Simple Inspector based Map Editor

Hey guys,
Can someone provide me with some information about how to implement a very simple Grid/Map Editor via the Inspector and a Scriptable Object? I tried various implementations but Im not happy at all.

Basically, what Im looking for is the simplest map editor ever: a 2d array grid of Sprites edited via the Inspector and saved as Scriptable Object.

Attached is the code Im using right now, as well as a screen. This shows the implementation of using a Color (was not able to remove the Eyedropper).

But: I would prefer using Sprites to determine the Tile that is placed on a grid space. But Sprites do not show up in the Inspector at all (I see just that selection ring and the beginning of the filename).

I guess I have to replace Color with a CustomPropertyDrawer - any advice here?

[CreateAssetMenu(fileName = "MapData", menuName = "New Map")]
public class MapData : ScriptableObject
{
    private const int defaultGridSize = 3;

    [Range(1, 30)]
    public int gridSize = defaultGridSize;

    public CellRow[] cells = new CellRow[defaultGridSize];


    public Color[,] GetCells()
    {
        Color[,] ret = new Color[gridSize, gridSize];

        for (int i = 0; i < gridSize; i++)
        {
            for (int j = 0; j < gridSize; j++)
            {
                ret[i, j] = cells[i].row[j];
            }
        }

        return ret;
    }

    [System.Serializable]
    public class CellRow
    {
        [ColorUsageAttribute(false)]public Color[] row = new Color[defaultGridSize];
    }
   
}

3468637--275427--test.jpg

Sorry for the double-post (and answering my own question) - if anybody is interested:

Im now using a open-source C# script (2dTilemapEditor) in combination with my own code and project. The script is outdated but easy to adjust and implement if you want to give it a whirl yourself:

And here we have two screenshots, showing the tilemap editor and the prepared scene at runtime:

2 Likes