- Home /
Custom map editor running slow due to too many draws.
I'm working on making a custom map editor using a custom Editor Window. It contains 2 grids, one for tiles and one for the actual map. The map itself contains 5 grids for layering.
At the moment, it redraws both grids in OnGUI(), however, this is obvious extremely slow. Not only that, but currently selecting a tile simply copies the tile into the map array, which I believe is creating another copy of the sprite in memory.
Ideally, I only want to draw the grids and sprites when they need to be updated, and rather than store the tile in the map gird I'd rather reference it from the tileset. I kinda have an idea how I'm going to do that part, however I'm wondering, a) Is that the best way to do it, and B) is it possible to only draw the table in a EditorWindow if I mark it as dirty? When I tried to add a bool to only draw when it was dirty and the window was blank....
void OnGUI()
{
Event e = Event.current;
if (isDirty)
{
DrawMapEditorWindow();
isDirty = true; // Set to true as setting to false gives me a blank window.
}
}
void DrawMapEditorWindow()
{
DrawToolBar();
EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
DrawTilePallette();
DrawMapArea();
EditorGUILayout.EndHorizontal();
}
void DrawToolBar()
{
EditorGUILayout.BeginHorizontal("box", GUILayout.ExpandWidth (true), GUILayout.MaxHeight(35));
GUILayout.Label("---ToolBar Here---");
EditorGUILayout.EndHorizontal();
}
void DrawTilePallette()
{
EditorGUILayout.BeginVertical("box", GUILayout.MaxWidth(256), GUILayout.ExpandHeight(true));
palletteScrollViewPosition = GUILayout.BeginScrollView(palletteScrollViewPosition, false, true, GUILayout.MaxWidth(256), GUILayout.ExpandHeight(true));
EditorGUILayout.Space(tilePallette.height * tilePallette.cellSize);
tilePallette.DrawGrid(true);
GUILayout.EndScrollView();
EditorGUILayout.EndVertical();
}
void DrawMapArea()
{
EditorGUILayout.BeginVertical("box", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
mapScrollViewPosition = GUILayout.BeginScrollView(mapScrollViewPosition, false, false, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
EditorGUILayout.Space(tilePallette.height * tilePallette.cellSize);
map.DrawGrid(true);
GUILayout.EndScrollView();
EditorGUILayout.EndVertical();
}
Your answer
Follow this Question
Related Questions
How can I instantiate a prefab/s in all loaded scenes or in selected scenes from list ? 1 Answer
Multiple Cars not working 1 Answer
How can i add a second camera that will be showing only specific gameobject in game window ? 1 Answer
Distribute terrain in zones 3 Answers
How to Activate texture on collison 1 Answer