Skip to content

Source Code Description

Bil Simser edited this page Mar 6, 2018 · 8 revisions

This page describes the organization of the source code and assets in the Micropolis Unity project.

The main code and assets are found under Micropolis/Assets/Micropolis. Other folders in the /Assets folder are there as a result of installing Cinemachine and TextMesh Pro, two free Unity assets that are used for camera and text UI elements in the project.

Inside the Assets/Micropolis folder you'll find:

  • Resources - images and tiles that are loaded at runtime (using Unity's Resource.Load functions)
  • Scenes - Unity scene files to run the game
  • Scripts - The root folder for all game source code
  • Sprites - Various sprites for UI and game elements

There are three root folders that make up the source code for Micropolis in the Scripts folder:

MicropolisCore

This contains the C# rewrite of the original C++ classes in Micropolis. It holds all of the game logic but none of the UI or system specific functions. There are no references to the Unity Engine in here. Messages are passed to the MicropolisEngine classes via C# delegates and events (formerly the generic callback system in the Python code). If you make any changes in here as to how the simulator works, fundamentally, then you should update the Inside the Simulator page (to keep things in sync) as the Simulator page details how the game works.

MicropolisEngine

This folder contains the MicropolisUnityEngine which inherits from the MicropolisGenericEngine which inherits from the main Micropolis class (in MicropolisCore). This mirrors the original MicropolisGtkEngine classes in the source release for Micropolis and contains generic functions that would be accessed through the MicropolisGame classes. Currently they hold things like game messages and notifications. We'll probably fold these down into a single class or get rid of them entirely, moving functionality into the MicropolisGame namespace.

MicropolisGame

This folder contains the Unity game elements that interact with the UI, input, sound, and end users directly. This folder is the only one that contains classes inheriting from the Unity Engine MonoBehavior class and are attached to GameObjects in the game scene. Some of the core classes in this namespace are:

  • GameManager - main driver for the game interface and links other managers together
  • UIManager - interface between the Micropolis engine and the Unity UI elements in the scene
  • TileManager - responsible for the main display of Unity Tile objects on a TileMap in the scene
  • TileEngine - serves up a tile object based on a tile id from a cache or loads it from an asset resource (see Tilesets below under Resources).

Resources

Unity allows you to load assets (prefab game objects, sprites, textures, sounds, etc.) at runtime through a call to Resources.Load functions. The assets actually live in resource files packaged with the application. Any folder in Unity named "Resources" will get picked up and packaged for use in your application. The Micropolis/Resources folder contains the following content:

  • Tiles - These are individual Tile assets that represent on of the 960 tiles in the game and used to display on the TileMap in the scene. A Tile contains information about the tile like it's position and a reference to a sprite (which can be changed).
  • Tilesets - This folder contains a folder for each graphical tileset to represent the visual sprite for the tile to display. Each folder contains a single file (tile.png) that contains the 960 images for each tile in the game. The TileEngine class uses a path to determine where to load the sprite from based on the current theme.