Chapter 10. Building an In-Game Level Editor

Once you have your game mechanics finished up, you will need to fill up your game with content. You could use the Unity Editor to place things by hand, but as you may have seen earlier, it takes a really long time. It's also possible for us to create an array as we did earlier in Chapter 6, Side-scrolling Platformer, but in that case, your levels need to be defined in a script and you'll need to either use an external tool or type in numbers individually for it to work correctly.

Another option is to save and load level files inside the game, and that way you can playtest your levels and make changes on the fly and save them when you're ready. We also have the advantage of being able to see exactly what the level looks like when you're making it.

Project overview

In this chapter, we are going to add in functionality to our previously created side-scrolling platformer game, adding in an in-game level editor, which can be used for future projects.

In addition, we will also gain exposure to the Immediate Mode GUI system (IMGUI), which is a code-driven GUI system that was the only way to create GUIs before Unity 4.6, and is currently a tool primarily used by programmers for tools development and custom inspectors for scripts or new editors to extend Unity itself.

One of the nice things of working with this system is that you do not need to have any art assets to create and can make your menus entirely through code, so it's still worthwhile to touch and then decide which you'd like to use for your own future projects.

Your objectives

This project will be split into a number of tasks. It will be a simple step-by-step process from beginning to end. Here is the outline of our tasks:

  • Level editor – introduction
  • Adding/removing walls at runtime
  • Toggling editor, GUI, and selecting additional tiles
  • Saving/loading levels to file

Prerequisites

In this chapter, we will use projects that we created in the earlier chapters, specifically the project from Chapter 6, Side-scrolling Platformer. You may continue with your previous projects or pick up a copy along with the assets for this chapter from the example code provided for this book on Packt Publishing's website (https://www.packtpub.com/books/content/support).

In addition, the completed project and source files are located there for you to check whether you have any questions or need clarification.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset