After testing the 3D models I made a new script that worked in the editor rather than game engine and went to work on optimisation.
The initial version of this system would start to suffer from lag when grids went over a certain size, to fix this I made the two changes mentioned below:
- The script only updates its values after a change
- The script only checks if pieces need to be reassigned on the selected slots, and those immediately surrounding them when a change is made, not the whole grid.
With the basic system working in the scene view as an editor script I then worked on a striped down version, without the slot sorting and adding functions, so I could purely focus on making selection tools beyond one at a time clicking. Since the user input is, in the end, just toggling booleans, the sorting system can be overlaid on the result later.
The first new feature, and the one which took the most time, was the wall selection. This was a tool that was made to help shrinking or expanding room sizes easily.
When the wall mode is activate It works by:
- Going through the grid with two loops, one left to right and another down to up along the entire grid.
- As it does this it find valid slots that match the criteria to be the start, and then end of a wall, on the current line.
- These instances are stored to a custom list e.g WallSections_List(int XRow, int ZRow, int StartPoint, int EndPoint, int Direction).
- Finally these list are used to display lines, representing the walls, that have handles over them on the grid that can then be selected and dragged.
Figuring out how to make this work was a challenge for me, but the basics are there and work. While making this I found myself having some major difficulties with unity’s editor handles, while I tried looking through documentation I found means to customize and use them, along with access to such things as mouse click events, limited and will need to look these things up again in the future.
The final addition made to the grid editor was the option to rescale it to any size from any side and have it save the states of the units inside, so they wouldn’t losing their position. Alongside this are a range of other setting options for the grid show above.