Get Me Started

Documentation

Table of Contents

  1. What is Get Me Started?
  2. Feature Set
  3. Installation
  4. Editor Tools
  5. Basic Code Layout
  6. How to load a scene
  7. Creating a new scene
  8. Adding scenes
  9. Adding a new manager to the LibraryPrefab
  10. How the HUD works
  11. How to create a new Loading Screen
  12. How Localization works
  13. Adding new localized strings to your game
  14. How saving/loading XML works
  15. How the Credits work
  16. Screenshots
  17. Removing the XML features
  18. Removing Localization
  19. Removing Example Scenes
  20. Shaders
  21. 3rd Party Attribution
  22. About the Author

1. What is Get Me Started?

Have you ever had an awesome game idea and started to work on it only to be faced with the prospect of writing the boring initalization code?  Did you quit in frustration because you just wanted to get started making the "game" part of your game?  Now you don't have to worry about that because Get Me Started does the necessary, but boring parts for you.

Get Me Started is a collection of scripts that form a basic structure to help you code any type of game while trying not to affect your code as much as possible.

2. Feature Set

3. Installation

If you're starting a new project, installation is relitevely simple:

Edit -> GMS -> Setup New GMS Project

The Get Me Started scenes will now populate the first few slots in the "Scenes In Build" list box.  Double check to make sure that Start is the first scene.  If the order of the scenes is a little off, incorrect scenes may load.

This makes sure that the Scene Enum matches the build settings.

Note: You will get a Debug.Log message when you first run Get Me Started because a Library XML file has not been generated.  If you open the Developer dialog (~ key) and select Save Library XML, it will go away.  Alternatively, you can remove the XML classes from your project to get rid of it.

4. Editor Tools

What this script is doing behind the scenes is adding a compiler option to Edit -> Project Settings -> Player, in the "Scripting Define Symbols" textbox called "DEVELOPER"

5. Basic Code Layout

Every scene has a GameObject with a SceneManager script attached.  This class will initialize everything else.

The first task of the SceneManager is to instantiate the Library (Lib) prefab located in the resources folder.  

The Library, when spawned gets the DontDestroy script applied to it so that it's never deleted during the course of the game.  It's a regular prefab that you can access in the Resources folder and are encouraged to add any scripts your game may require.  The provided Library comes with a number of scripts already attached, such as the LocalizationManager to make sure that your game will work in multiple languages and the XMLManager which adds the ability to save data out to XML files.  Drag the prefab into the Hierarchy window and take some time to explore its scripts.

The SceneManager also works with the library to load a unique heads up display (HUD) in every scene.  If the HUD is the same between multiple scenes, it will keep the existing one.

6. How to load a scene

A static function in the Scene class called Load is provided to load a new scene.  It accepts either a SceneNames enum or an integer, which corrisponds to the Scenes number in File -> Build Settings...

Call it at any time and it will load the active loading screen (if there is one), and asynchronously load the level.

If your game needs multiple loading screens, there is Lib.Instance.LoadingScreens.SetActive(), which allows you to switch between them at any time.  Creating a new loading screen is done by copying the formatting provided by one of the existing ones with your own unique images.  They can have a spinner, a progress bar or a static image.

7. Creating a New Scene

That is all that is required, if you hit play, the root manager and Library will be available.  Any other scripts that you add will vary from game to game.  Here is a list of some scripts that are included that you may want to add:

8. Adding Scenes

Adding a scene to the game isn't that hard, just a couple steps and you will be able to access it using an enum.

9. Adding a new manager to the LibraryPrefab

  [...]

public DeveloperManager Developer;

public MyManager mMyManager;

  [...]

  mDeveloper = GetComponent<DeveloperManager>();

  mMyManager = GetComponent<MyManager>();

If Lib.Instance.MyUniqueStuff is ever null, that means that it isn't part of the LibraryPrefab (e.g. if you removed the XMLManager, it won't be able to get the XMLManager component and be null).

10. How the HUD works

All of the HUD's in game inherit from HUDBase a basic class.  The GameObject is typically a uGUI Canvas with a HUD component added although that isn't a requirement.

The SceneManager has a slot that accepts a link to a HUD Prefab and if it is populated, when you play a scene the HUD will automatically load.

If you want any HUD text localized, remember to add the AutoLocalize script and all of the child Text fields will switch languages.

11. How to create a new Loading Screen

Creating a loading screen is fairly simple and you can make any of the standard types.  Static, with a spinning animation, or with a progress bar.

The next time you load a level, you should now see your new loading screen.

12. How Localization works

On startup the LocalizationManager in the Library will read in all of the Language text files included in LocalizationManger's list.  It then looks in the PlayerPrefs to see what the active language is, and copies the strings into the static string fields of Language.cs.

When you change languages in the settings dialog, the Language.cs strings are overwritten with the translated ones and OnLocaleChanged() is broadcasted to every GameObject that has been loaded.  Scripts that include this function are then able to update their text fields with the proper language.  In practice, the LocalizeText and LocalizeImage components already handle this, so you don't have to do anything, unless you're extending the functionality.

If you include the AutoLocalize script on a top level GameObject, on Start() it will add the LocalizeText component to any GameObjects with a Text component attached.  It then uses the text in the text field as the lookup name in Language.cs.

If you want to exclude a specific Text component from being automatically localized, add the DontLocalize component to it.  It's an empty class that AutoLocalize looks for when it is iterating through all of the Text components.

13. Adding new localized strings to your game

public static string Fantastic;

public static string MyLocalizedString;

MyLocalizedString=My Localized String in English

Press play and the text field should now change to the localized text.

14. How saving/loading XML works

Get Me Started is able to Save & Load public Monobehaviour variables to XML files which are stored in the Application.persistentDataPath folder.  When the XMLManager is included in the Library and the save function is called, the GameObject structure that is passed in will have it's hierarchy searched for MonobehaviourXML scripts and be saved out.

To use a MonobehaviourXML script, instead of your script inheriting from Monobehaviour, have it inherit from MonobehaviourXML.  The saving and loading happens behind the scenes, you just have to make sure that the information you want to save and load is in public variables.

To Load & Save the entire scene during Start and Destroy respectively, place the SceneXML script on the SceneManager GameObject.  If you would like to trigger it at a different time, call the Lib.Instance.XMLManager.Save(filename, gameObject) or Lib.Instance.XMLManager.Load(filename, gameObject) functions at that time.

By default the Library prefab tries to load an XML every time it starts up.  If you just installed Get Me Started you will see a Debug.Log message mentioning that the XML file is missing.  That message can be removed by opening the Developer menu (The ~ key) and selecting "Save Library XML."

In \Assets\GMS\Scripts\Examples\ there are two scripts included to show you how the XML saving works.  ExampleXMLClass is a MonobehaviourXML class that will save its contents out and it references ExampleXMLSerializedClass, a basic class with [System.Serializable] at the top.

15. How the Credits work

The Credits scene contains a Scroller which has the Credits.cs script component on it.  That script links to the Credits.txt file which it reads in on start. Any commands found on a line in the text file are used to instantiate prefabs in the list box.

The commands are always at the start of a line and between <> brackets.  The command corresponds to the name of the prefabs in the Credits script array on the Scroller.

Included prefabs that you can use are:

<lb> - A Large blank space.  Typically used as a header.

<h1> - A large header.

<h2> - A secondary header.

<cl> - A Centered Line.  It is designed to take two words (but mainly it's designed for a persons name) and put one part on the left, and the other on the right, with the space centered.

There are also two special prefabs:

[space] - is used when a blank line is found.

[lineoftext] - is used when there is text, but no command.

Once all of the prefabs have been instantiated, it will scroll up.  When the list hits the bottom, a callback notifies SceneCredits.cs and that script loads the Main Menu.

Overlayed on top of the scroller is a transparent layer called UserInput.  It's a GameObject that keeps an eye out for clicks or keyboard presses.  If the user clicks, a skip message will display for a few seconds.  If they click a second time, the credits will be skipped.  If they don't click the message will fade out and nothing will happen.

16. Screenshots

ScreenshotManager is a static class that can be called from anywhere in your game. It has two functions Take() and TakeAdvanced().  Take() will take a basic screenshot and save it to a file in the Application.persistentDataPath folder with a time stamp to make sure its unique.

TakeAdvanced() also takes a screenshot, but it briefly increases the quality of the image on the screen and optionally removes the HUD before it does so.

17. Removing the XML features

Some games don't need the included XML features.  Follow these steps and you will be able to fully remove the code from your game.

18. Removing Localization

If you don't want to use the included localization code, it can also be removed.

If you go into the Settings dialog, the language section should automatically hide itself, but you can delete it if you don't want it there anymore.

* If you want to remove the Language.cs class, you have to make sure that anywhere that references one of its statics in the code needs to be changed to a string of some sort.  Search project wide for "Language." (Search->Find in Files in Mono Develop).  That will provide a list of everything that references the class and you can go through line by line and replace them with strings.  Skip LocalizeText.cs class if you are going to deleted it.

 

19. Removing Example Scenes

There are a few example scenes included with GMS.  If you want to clean things up, but keep the functionality, here is a list of scenes you can remove:

Remember to go into File -> Build Settings to remove the scenes from the build process and run Edit -> GMS -> Update SceneEnum again.

20. Shaders

Get Me Started comes with a couple shaders that round out the Unity provided ones.

They work by treating two colour channels in the image as two separate black and white images.  The data in the Red channel is treated as the base colour and alpha of the particle.  And the information in the Green Channel is treated as the highlight.  The Blue and Alpha channels of the image are ignored.  The Color plus white shaders are less computationly intensive.  You will want to use those when two colours aren't absolutely required.

Red Channel - Black is transparent.  White is the Color

Green Channel - White is the Highlight Color.

Blue Channel - Ignored

Alpha Channel - Ignored

21. 3rd Party Attribution

Tanner Helland

http://www.tannerhelland.com/music-directory/

Tim Gormly

- 8-Bit Coin http://www.freesound.org/people/timgormly/sounds/170147/

- 8-Bit Hurt http://www.freesound.org/people/timgormly/sounds/170149/

22. About the Author

Neil Marshall has been creating games for over a decade as both a Programmer and Technical Artist.  One of the more recognizable games he has worked on was the freemium Uno for iPhone & Android based phones.