Monday, October 29, 2012

Battlestar.dll: Trigger and TriggerManager Classes


In the previous batch of blogs, I covered the Trigger Manager script within the actual game.  I did not cover the Trigger class or TriggerManager class created in C# that is used by the game script.  This blog will cover both of these classes.

Both of these classes were compiled in C# as a .dll file.  The statement used at the beginning of the game’s TriggerManager script, “using Battlestar”, gives the game access the methods and properties created in C#. 

Here’s the Trigger class:


It is just a bare-bones class.  It only possesses the variable declarations.  Ordinarily, I would avoid this format; however, the database used by the game requires a barebones format.  Each variable in this class represents a field in each record in the database table, “Trigger”.  Since this class represents a barebones class, I created another class to access the database using this class. 

Here’s the TriggerManager class:


This class has actual operations that access the database.  These are simplistic operations like: a save, delete and load operation.  To access these operations, the game scripts use a statement like “Battlestar.TriggerManager.Load(vPath, vMission)” to access the commands in this class.  The actual game scripts never touch the database; all database interactions are handled in .dll files. 

While it would be simpler, in principle, to have the MonoDeveloper in Unity handle these operations, it’s necessary to implement the .dll file format due to the nature of MonoDeveloper.  Unity dynamically generates class structures.  This means that a class, like the Trigger class detailed above, would vary each game execution.  This makes creating a stable table difficult from inside Unity.  Using .dll files is the easiest solution to this problem. 

No comments:

Post a Comment