Unigine.Config Class
The Config class is used to read values (settings) from the engine configuration file (unigine.cfg by default) and write back into it.
By using the Config class functionality, it is possible to read from and write to the engine configuration file only (the file specified by using the -engine_config command-line option). To write application-specific settings to a different file, use the File, Xml or Json classes.
Use the appropriate methods depending on the type of the target item. For example, to get the values of the following items, you should use the getInt() and getString() methods corespondingly:
...
<item name="show_fps" type="int">1</item>
<item name="system_script" type="string">unigine_project/unigine.cpp</item>
...
Usage Example
By using the Config class, you can save custom settings to the configuration file and then restore it when required. For example:
AppSystemLogic.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Unigine;
namespace UnigineApp
{
class AppSystemLogic : SystemLogic
{
private string player_avatar;
private int skip_cutscenes;
private int blood_enabled;
private int bulletshell_lifetime;
public override int init()
{
// get the Config instance
Config config = Config.get();
// read custom user-defined settings from the configuration file
player_avatar = config.getString("player_avatar", "usa_soldier1");
skip_cutscenes = config.getBool("skip_cutscenes", 0);
blood_enabled = config.getBool("blood_enabled", 0);
bulletshell_lifetime = config.getInt("bulletshell_lifetime", 100);
return 1;
}
public override int shutdown()
{
// check whether data can be written to the configuration file
if (Unigine.Console.get().getInt("config_readonly") == 1) Unigine.Console.get().setInt("config_readonly",0);
// get the Config instance
Config config = Config.get();
// write the custom settings to the configuration file
config.setString("player_avatar", player_avatar);
config.setBool("skip_cutscenes", skip_cutscenes);
config.setBool("blood_enabled", blood_enabled);
config.setInt("bulletshell_lifetime", bulletshell_lifetime);
// save the configuration file
config.save("unigine_project_9/unigine.cfg");
return 1;
}
}
}
See Also
- Article on Configuration File.
Config Class
Members
Config get()
Returns the existing instance of the Config class.Config.get().getInt("show_fps");
Return value
An instance of the Config class.void setBool(string name, int value)
Sets a value of the given boolean setting. If the setting with this name already exists, its value is overwritten.Arguments
- string name - Name of the setting.
- int value - Boolean value (0 or 1). 0 stands for false, 1 stands for true.
int getBool(string name)
Reads the value of the given boolean setting.Arguments
- string name - Name of the setting.
Return value
Boolean value (0 or 1) of the setting. 0 stands for false, 1 stands for true.int getBool(string name, int value)
Reads the value of the given boolean setting. Returns the value specified as the second argument if the setting isn't found.Arguments
- string name - Name of the setting.
- int value - Custom value to be returned if the setting isn't found.
Return value
Boolean value (0 or 1) of the setting. 0 stands for false, 1 stands for true.int isExist(string name)
Checks if the setting with the given name exists.Arguments
- string name - Name of the setting.
Return value
1 if the setting exists; otherwise, 0.void setFloat(string name, float value)
Sets a value of the given float setting. If the setting with this name already exists, its value is overwritten.Arguments
- string name - Name of the setting.
- float value - Float value of the setting.
float getFloat(string name, float value)
Reads the value of the given float setting. Returns the value specified as the second argument if the setting isn't found.Arguments
- string name - Name of the setting.
- float value - Custom value to be returned if the setting isn't found.
Return value
Float value of the setting.float getFloat(string name)
Reads the value of the given float setting.Arguments
- string name - Name of the setting.
Return value
Float value of the setting.void setInt(string name, int value)
Sets a value of the given integer setting. If the setting with this name already exists, its value is overwritten.Arguments
- string name - Name of the setting.
- int value - Integer value of the setting.
int getInt(string name)
Reads the value of the given integer setting.Arguments
- string name - Name of the setting.
Return value
Integer value of the setting.int getInt(string name, int value)
Reads the value of the given integer setting. Returns the value specified as the second argument if the setting isn't found.Arguments
- string name - Name of the setting.
- int value - Custom value to be returned if the setting isn't found.
Return value
Integer value of the setting.void setString(string name, string value)
Sets a value of the given string setting. If the setting with this name already exists, its value is overwritten.Arguments
- string name - Name of the setting.
- string value - String value of the setting.
string getString(string name, string value)
Reads the value of the given string setting. Returns the value specified as the second argument if the setting isn't found.Arguments
- string name - Name of the setting.
- string value - Custom value to be returned if the setting is found.
Return value
String value of the setting.string getString(string name)
Reads the value of the given string setting.Arguments
- string name - Name of the setting.
Return value
String value of the setting.int flush()
Flushes config into the current file.Return value
1 if the config is successfully flushed into the file; otherwise, 0.int load(string name)
Loads config from the file.Arguments
- string name - Configuration file name.
Return value
1 if the config is successfully loaded from the file; otherwise, 0.void remove(string name)
Removes the setting with the given name from the configuration file.Arguments
- string name - Name of the setting.
int save(string name)
Saves config into the file.Arguments
- string name - Configuration file name.
Return value
1 if the config is successfully saved into the file; otherwise, 0.Last update: 2018-06-04
Help improve this article
Was this article helpful?
(or select a word/phrase and press Ctrl+Enter)