Generating constant strings from your catalogs
Purpose
To simplify coding and reduce errors, Game Foundation supports exporting .cs
compatible code for constant strings from your catalogs. This helps your development in the following ways:
- Enables code completion.
- Limits strings to just one auto-generated configuration file.
- Eliminates typos in constant strings by using class members which are compile-time verified.
When requested, Game Foundation will export user-defined constants from your Game Foundation catalogs for Keys and Properties (both Mutable and Static).
How to generate a constants file from a catalog
To generate a .cs
constants file from one of your catalogs, follow these instructions:
- In your Unity project, go to Window > Game Foundation > Catalogs.
- Select the catalog (for example, Samples/00_Catalog/SampleCatalog.asset) which will be the source catalog to generate all constants from.
- Click the Generate Constants button in the Unity Inspector window.
- Specify a destination file for you constants. This must located in a folder or subfolder of Assets and should use the extension
.cs
. - Click Save.
Output
A new script file containing the constants from your catalog will be automatically created in your Unity project once the constants are generated (see [How to generate a constants file from a catalog] for instructions).
These constants will be implemented as const strings and organized into classes and sub-classes inside of a main
class based on your catalog's name (line 0007) as follows:
class Items
(line 0009) contains information for each item definition used in your Game Foundation > Inventory Item window including sub-classes (line 0011) for each item in your catalog.
Each sub-class contains:
- a const string named 'key' (line 0013) for the item's key (from Inventory Item window's 'key' field).
- sub-class named 'StaticProperties' (line 0022) only if any Static Properties were added to the item.
- const strings (line 0024) for each Static Property key.
- sub-class named 'StaticProperties' (line 0022) only if any Static Properties were added to the item.
- a sub-class named 'Properties' (line 0027) only if any Mutable Properties were added to the item.
- const strings (line 0029) for each Property key.
Note: Only Inventory Items support Mutable Properties, whereas all catalogs support Static Properties (for example: line 0022).
class Currencies
(line 0035) contains sub-classes (line 0037) and constant strings (line 0039) for catalog entries used in your Game Foundation > Currency window.
- Currencies and all remaining systems contain the same sub-classes and const strings for each catalog entry except that they do not permit Mutable Properties. Also, same as the Items class, StaticProperties class will only exist for entries defining one or more Static Property.
class Transactions
(line 0061) contains sub-classes (line 0063) and constant strings (line 0065) for catalog entries used in your Game Foundation > Transaction window for both IAP Transactions and Virtual Transactions.
- Can contain the same sub-classes and const strings as the Currency class. Transactions do not permit Mutable Properties.
class Stores
(line 0082) contains sub-classes (line 0084) and constant strings (line 0086) for catalog entries used in your Game Foundation > Store window.
- Can contain the same sub-classes and const strings as the Transaction class. Stores do not permit Mutable Properties.
class GameParameters
(line 0097) contains sub-classes (line 0099) and constant strings (line 0101) for catalog entries used in Game Foundation > Game Parameter window.
- Can contain the same sub-classes and const strings as the Stores class. Game Parameters do not permit Mutable Properties.
Sample Output
0001: //------------------------------------------------------------------------------
0002: // <auto-generated>
0003: // This code was generated by a tool.
0004: // </auto-generated>
0005: //------------------------------------------------------------------------------
0006:
0007: public class SampleCatalog
0008: {
0009: public class Items
0010: {
0011: public class apple
0012: {
0013: public const string key = "apple";
0014: }
0015: public class banana
0016: {
0017: public const string key = "banana";
0018: }
0019: public class sword
0020: {
0021: public const string key = "sword";
0022: public class StaticProperties
0023: {
0024: public const string hud_icon = "hud_icon";
0025: public const string promotion_icon = "promotion_icon";
0026: }
0027: public class Properties
0028: {
0029: public const string damage = "damage";
0030: public const string quantity = "quantity";
0031: public const string durability = "durability";
0032: }
0033: }
0034: }
0035: public class Currencies
0036: {
0037: public class coin
0038: {
0039: public const string key = "coin";
0040: public class StaticProperties
0041: {
0042: public const string item_icon = "item_icon";
0043: public const string hud_icon = "hud_icon";
0044: public const string purchase_button_icon = "purchase_button_icon";
0045: public const string promotion_icon = "promotion_icon";
0046: public const string reward_icon = "reward_icon";
0047: }
0048: }
0049: public class gem
0050: {
0051: public const string key = "gem";
0052: public class StaticProperties
0053: {
0054: public const string item_icon = "item_icon";
0055: public const string hud_icon = "hud_icon";
0056: public const string purchase_button_icon = "purchase_button_icon";
0057: public const string promotion_icon = "promotion_icon";
0058: }
0059: }
0060: }
0061: public class Transactions
0062: {
0063: public class coinPack_2
0064: {
0065: public const string key = "coinPack_2";
0066: public class StaticProperties
0067: {
0068: public const string item_icon = "item_icon";
0069: public const string item_icon_big = "item_icon_big";
0070: }
0071: }
0072: public class coinPack_10
0073: {
0074: public const string key = "coinPack_10";
0075: public class StaticProperties
0076: {
0077: public const string item_icon = "item_icon";
0078: public const string item_icon_big = "item_icon_big";
0079: }
0080: }
0081: }
0082: public class Stores
0083: {
0084: public class main
0085: {
0086: public const string key = "main";
0087: }
0088: public class secondStore
0089: {
0090: public const string key = "secondStore";
0091: public class StaticProperties
0092: {
0093: public const string store_static_prop = "store_static_prop";
0094: }
0095: }
0096: }
0097: public class GameParameters
0098: {
0099: public class Is_Sample_Catalog
0100: {
0101: public const string key = "Is_Sample_Catalog";
0102: }
0103: public class Additional_Game_Parameter
0104: {
0105: public const string key = "Additional_Game_Parameter";
0106: public class StaticProperties
0107: {
0108: public const string gameParamIntProp = "gameParamIntProp";
0109: public const string gameParamStringProp = "gameParamStringProp";
0110: }
0111: }
0112: }
0113: }