Search Unity

Alternatives to using GameObjects for a level editor view?

Discussion in 'Immediate Mode GUI (IMGUI)' started by eses, Nov 18, 2019.

  1. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    1,778
    Hi,

    I was testing an idea for a level editor. So far I had considered creating a Tilemap based editor, but I don't think it is possible to draw several tiles in one cell (correct me if I'm wrong... as this would already help).

    I would like to show/store several overlapping items in one "tile". So if I was using a Tilemap, creating several layers to just show three items in tile doesn't sound like a right way to do this.

    So I decided to go for Editor Window so that I could take advantage of Unity serialization and serialized objects and do rendering of the "view" with GameObjects.

    Using GameObjects as containers for sprites works, but feels cumbersome - I have the data and I also have to do instancing / removal of GameObjects, only to be able to show sprites.

    So I was thinking - what alternatives do I have?

    Would it be possible to use bitmap / texture to render the editor view? Replace GameObjects with a texture that gets updated when user clicks specific scene view area. I would only need something like 32x32 or 64x64 tiles area and symbols could be quite small (like 8x8 or 16x16 tiles). I guess 512 or 1024 would be the max size of the map image.

    Creating / texturing custom meshes on the other hand sound like something that could also work, but it probably might be too much work...

    Any Ideas?

    I would only be using this editor to create level data, not the actual 3d scene.
     
  2. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    358
    Hi eses

    Could you elaborate why using multiple Tilemaps does not sound like a good solution to you? To me that sounds like it would be the simplest solution by far. No need to waste time reinventing the wheel unless there's some real benefit to it.

    If you want to avoid placing any objects into the scene, you could also just use GUI.DrawTexture to manually draw your tiles inside the EditorWindow itself.

    You can use Texture2D.SetPixel to merge the pixel data of multiple tiles together, if you need to do this for performance reasons, but I don't believe that would be necessary with such small map sizes. You could take these merged textures and stick them into the Renderer components of scene objects, to avoid having multiple layers per tile.
     
    eses likes this.
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    1,778
    @SisusCo

    Hi and thank you.

    GUI.DrawTexture sounds like something I could use.

    "Could you elaborate why using multiple Tilemaps does not sound like a good solution to you?"


    Yes - what I'm trying to do is to simulate old school RPG tilemap. I'm trying to show x amount of items that possibly exist in tile. Like dropped items. Tilemap would have worked, if only I could have several tiles in one cell. So far based on what I've used tilemap, the fact is that there can be only one tile in one cell, and to avoid that I would have to create more layers to show more "sprites" in that cell. So I could have zero items in most tiles, and in some tiles I could have five, or maybe 10 - I don't know yet. Something like this:



    So I would probably have to have some max item amount per tile and comparable amount of layers, and somehow manage adding items to layers based on how many items already exist in that cell. I think removing and adding items in layers could be also bit challenging for me at least.

    I already did some tests with SetPixels so I might go that route as it might be the easiest way to do this.
     

    Attached Files:

    Last edited: Nov 19, 2019
  4. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    358
    Oh, I see. In that case using tiles indeed would probably not make sense for the items. SetPixels sounds like a good approach.
     
  5. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    1,778
    @SisusCo

    I went the SetPixels route, and built some helper methods yesterday. Seems like this would work nicely, no problems with larger maps (more than 1024 tiles) either as I only re-draw the dirty tiles. And it is way less hassle than using GameObjects (which I got working fine before trying this) now I only have one quad/texture bitmap and the data that gets serialized automatically by Unity. It renders nicely too but GIF tool I used ruined the image quality.

    tilemap_editor2.gif
     
  6. SisusCo

    SisusCo

    Joined:
    Jan 29, 2019
    Posts:
    358
    Very nice! That looks really snappy and like it would be fast to work with :)
    I'm glad to hear that the approach you chose to go with worked out well for you.
     
    eses likes this.
unityunity