Skip to content

Code architecture

Introduction

The code of the kit lives in the BubbleShooterKit/Scripts folder of the project. This folder is further subdivided into three sub-folders:

  • Common: Contains all the game-agnostic code of the kit.
  • Editor: Contains all the editor code of the kit.
  • Game: Contains all the game-related code of the kit.

Common

The Common folder contains all the game-agnostic code of the kit. This is the foundational code that is used through the entirety of the kit and is not specifically tied to any gameplay logic (i.e., can be reused across different projects). We are going to discuss the most important pieces next.

Object pool

Pooling is used for every short-lived, dynamically-instantiated object in the game (e.g., bubbles, particles, sound effects, score texts) in order to improve the runtime performance of the game. The relevant script is ObjectPool, which comes accompanied by the utility script AutoKillPooled that allows to automatically destroy the attached object after a specified time interval.

The object pools are game objects located in the game scene (BubblePool, FxPool and ScoreTextPool).

Base UI classes

The kit provides several useful abstractions on top of Unity's built-in UI system that are used in many places in the game:

  • AnimatedButton: A special button that provides a custom animation and click behaviour.
  • BaseScreen: The base class all the screens in the game (home, map and game) derive from. Each of the three scenes in the game contains a game object with the appropriate screen-specific component attached to it. This object is the entry point to that screen's functionality and game logic, and is usually the best way for you to dive into the internals of a given screen.
  • ScreenTransition: A utility component that provides a smooth, fade-to-color style of transition into a new Unity scene.

Game

The Game folder contains all the game-related code of the kit. It is further divided into the following independent, thematic sub-folders:

  • Bubbles: Contains the scripts of all the different types of bubbles available in the game.
  • Configuration: Contains the configuration scripts of the game.
  • Core: Contains the enumeration types used across the game logic.
  • Events: Contains the events used in the kit. These events are used for keeping track of the level goals (collecting bubbles, leaves and collectables).
  • Gameplay: Contains the scripts implementing the bubble shooter game logic.
  • IAP: Contains the scripts that provide the in-app purchasing functionality in the kit using Unity's IAP library.
  • Level: Contains the scripts that define a game level's configuration. Every level is a Unity asset that you can edit in the kit's level editor.
  • Popups: Contains the scripts of all the popups available in the game.
  • Screens: Contains the scripts of all the screens available in the game.
  • Systems: Contains the coins and lives subsystems available in the game.
  • UI: Contains the scripts of all the UI widgets available in the game. Most of the screens and popups in the game are composed of smaller, reusable pieces of UI and you can find their associated scripts here.