- Home /
Editor/GUILayout - Draw part of a texture
Hi,
i'm trying to achieve a tiled map editor with the unity editor.
My question is about, how should i draw the tiles from my tileset inside the editor?
First, i'm going to expose what i'm currently doing. I go through all the tiles of the tileset and create a new texture for each one of them using GetPixels and SetPixels methods from Texture.
for (var x = 0; x < TilesetWidth; x++)
{
_tiles[x] = new TileSetTile[TilesetHeight];
for (var y = 0; y < TilesetHeight; y++)
{
var pixels = _tilesetSprite.texture.GetPixels(x * TileSize, ((TilesetHeight - 1) - y) * TileSize, TileSize, TileSize);
var tileTexture = new Texture2D(TileSize, TileSize);
tileTexture.SetPixels(pixels);
tileTexture.Apply();
_tiles[x][y] = ...;
}
}
And then i use those textures with GUI Buttons to let the user select a tile.
It works, but i feel like it's a really naive way of achieving this. I tried this approach with quite big tileset, with like 1000+ tiles, and... it's slow.
So now i'm wondering, how could i do the same without having to recreate a new Texture2D for each tiles? I have heard of Graphics.DrawTexture but i does not seems to be really convinient as i'd like to display textures inside a GUI Layout.
Can i draw part of a texture in a efficient way inside gui code and keep the GUI Layout system?
Thanks.
Your answer
Follow this Question
Related Questions
Why are all my GUITexture elements semi-transparent? 0 Answers
Texture2D not showing in build, but shows up in editor 1 Answer
Health system 2d 2 Answers
Eliminate GUITexture Excess? 1 Answer
Editor scripting: Part of a texture as button content 1 Answer