❤️ Highly opinionated boilerplate suitable for rapid game development and game jam
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Assets
ProjectSettings
.gitignore
.gitmodules
LICENSE.md
README.md

README.md

unity-boilerplate

This is a highly opinionated boilerplate suitable for quick-and-dirty game development and game jams. This way, you can just simply make your game without having to implement tedious but necessary systems. I created this template taking my experiences from my two previous game jams ggj15-loli and ggj16-wayang. Currently I don't include any game-specific libraries or codes, but this might change in the future.

While it is possible to use this template for game production, I'd advise against it; the template is designed to be easy to code and design, trading performance for simplicity. However, feel free to take parts of this template for your game or modify it to suit your purposes.

I write the template on Unity 5.3. I also avoided certain codes and constructs to ensure that this template works on HTML5 and PC. I don't have time to test it, but the template should work on most other platforms with some work (for example, you might have to create your own input system on mobile phones).

How to use

Simply clone the repository or download it, then open the folder with Unity.

Features

  • Proper .gitignore and meta files settings for git (from github/gitignore)
  • SceneController that contains various public methods that can be targeted by UnityEvent.
  • PauseController that provides a simple mechanism to pause the game without needing to use the dreaded technique Time.timeScale = 0.
  • Automatically generate tag and layer const generation, inspired from Randyanto/CherryTree and others.

Proper .gitignore and settings for git

The only necessary folders are Assets (which contains, well, assets) and ProjectSettings (which contains various Unity project configurations). Everything else is not necessary and will be generated by Unity (most are Unity and C# compiler caches, as well as Visual Studio project files and solutions).

I also make .meta files in assets are visible and assets are serialized as text instead of binary (under Edit > Project Settings > Editor).

PauseController

PauseController provides several mechanisms for your game objects to be notified when the game needs to be paused. This way, you do not have to set Time.timeScale = 0 (which would cause problems with custom UI elements that use Update()). You can also get away from having to build a state machine just for pausing the game.

PauseController provides:

  • OnPause and OnResume as UnityEvent, that can be configured to fire when the application lose focus or manually through PauseController.Pause() and PauseController.Resume()
  • Automatically disable and enable all listed Behaviour, including several Unity components that are not Behaviour but has Pause() or Resume() methods (such as ParticleSystem). Turns out that there are issues with Type.GetType(), I'll take another look later.
  • Use PauseListener to hook from game objects (needed for dynamically instantiated objects).

GameStateController

GameStateController provides several mechanisms for your game objects to be notified when the state changes. It can be seen as a more generic version of PauseController.

GameStateController provides:

  • OnStateChange as UnityEvent, that will fire when the state is changed.
  • Use GameStateListener to hook from game objects (needed for dynamically instantiated objects).

Automatic tag and layer constants generation

Important to avoid runtime errors, as well as slightly improve performance since we use constants. The script is available at Editor/ConstGenerator.cs, inspired by Randyanto/CherryTree, this, and this. I'll add this later; I want a solution that triggers automatically, while Randyanto/CherryTree apparently still needs user trigger.

Since Unity 5.3, you do not need constants for scenes; SceneManager accepts scene names.

Notes

  • Change "Default Behavior Mode" at Edit > Project Settings > Editor to "3D" if you want to create 3D game. There are some differences between 2D and 3D mode regarding default scene view and lighting configurations.
  • Coding conventions follow the [C# Coding Guidelines][Csharp_Coding_Guidelines].
  • Feel free to read the source codes for various other caveats and notes regarding the scripts. Nah, will add documentation and unit tests later.

Todo

  • Automatically disable and enable behaviours in PauseController
  • Add automatic tag and layer constants generation
  • Add documentations and unit tests
  • Add necessary libraries

License

MIT License.