Tuesday, October 23, 2012

Overview of the Resource Manager

Despite having a limited role of accessing the game’s database, the resource manager is a key component of the game. Any time a mission needs to query the database, the resource manager handles that function; it is the only script that actually interacts with the database. This serves a couple of purposes. First, it centralizes all database interactions. If the data in the database is correct and incorrect data is outputted, the problem is probably within the resource manager. Second, it is designed to centralize key data fields. The database path, mission name and player name do not need to be replicated throughout the other scripts in the game. The resource manager avoids unnecessary replication. Currently, the resource manager is still under development. While a good portion is in place to make a mission functional, there are other procedures and functions that I want to include in the future. Here’s a quick breakdown of the key components.

The script has four global variables to track: the database location, the player’s ID, the mission’s name and a list of factions in the mission. The faction list was originally part of a faction manager; however, it was easier to eliminate the intermediary faction manager script and incorporate this function into the resource manager.

During the startup routine, Start(), this scripts loads the initial values based on the mission. Currently, all of these values are static. In the future, these values will be loaded from the database; I haven’t created this functionality yet. In addition to the variable loads, Start() also sets the default key map.

While this script does not possess an Update() routine, it does have a number utility functions that execute throughout the game. These scripts are called by other scripts to access the database.

Here’s the entire resource manager script:




This script is attached to an empty game object tagged as “Resource Manager” at location (0, 0, 0). This allows the game to locate the game object with ease. However, the resource manager is generally considered a global static script. This means that most of the routines can be called by calling the resource manager directly. For example, the simple statement, ResourceManager.LoadPlayerData(“objtt1Asteroid1”), will work in any script without defining the resource manager as an object. This feature makes the resource manager a versatile tool for the game.

No comments:

Post a Comment