Save Roaming Databases data
The database presents a simple key-value interface where:
- The key is a string.
- The value is a byte array of any length.
Use the DatabaseConnection.Put()
or DatabaseConnection.PutString()
APIs to save a key-value pair.
You can also organize keys by specifying a category string in Get()
and Put()
operations. If you don’t specify a category value, it defaults to an empty string (""
).
The following example shows how to save data. It saves the mouse coordinates of the user as a string on every frame if the user presses the primary mouse button.
private void Update()
{
const string keyMousePosition = "mousePosition";
if (Input.GetMouseButtonDown(0))
{
Vector3 mousePos = Input.mousePosition;
string value = JsonUtility.ToJson(mousePos);
// Save to database
db.PutString(keyMousePosition, value);
}
}