Trys to get the data of a specific type, returns true or false if succeeded.
Example
GetEntriesFromTable
Returns a dictionary with all entries from a table
Example
GetValuesFromEntry
Returns a dictionary with all values from an entry in a table.
Example
SetData
Set data to DataboxObject. Returns true if succeeded.
Example
EntryExists
Checks if an entry in a databox object exists. Returns true or false
Example
ValueExists
Checks if a value in a databox object exists. Returns true or false.
Example
RegisterToDatabase
Takes an existing entry and registers it to a new Databox object. This can be used if you are creating game objects at runtime. The newly created object takes the initial data information from an initial Databox object and registers itself to a runtime save game Databox object. Please see the advanced demo scene example here.
_dbToRegister: The Databox object where we want to add the entry
_tableID: The original table name
_entryID: The original entry name
_newEntryID: The new entry name. You should usually use a unique id for this.
Example
LoadDatabase
Loads the saved databox object
With custom file name.
LoadDatabaseAsync
Loads the saved databox object asynchronously
With custom file name.
Example
SaveDatabase
Saves the databox object to a json file
With custom file name.
SaveDatabaseAsync
Saves the databox object to a json file asynchronously
With custom file name.
Example
UploadToCloud
Uploads the database from the appropriate DataboxObject to the cloud.
Uploading overrides the complete file stored in the cloud.
DownloadFromCloud
Downloads the database from the cloud by using the settings of the appropriate Databox object.
RemoveDatabaseTable
Remove a complete table from the databox object.
RemoveEntry
Remove specific entry from table
RemoveValue
Remove value from entry.
Databox Object Events
OnDatabaseLoaded
Is being called after database has been loaded.
OnDatabaseSaving
Is being called as soon as saving the databox object starts.
OnDatabaseSaved
Is being called after successfully saving the database.
OnDatabaseCloudDownloaded
Is being called after the database has been downloaded.
OnDatabaseCloudDownloadFailed
Is being called after database download failed.
OnDatabaseCloudUploaded
Is being called after the database has been uploaded.
OnDatabaseCloudUploadFailed
Is being called after database upload failed.
Databox Types
Reset
Resets the value back to it's initial value. When creating a custom class you will need to add the reset functionality to it yourself.
See the Create a custom class Example.
Example
OnValueChanged
This event is being called as soon as the appropriate value has been changed.
This is also great for custom data binding.
Example
Databox Object Manager
GetDataboxObject
Returns the Databox object according to it's id specified in the DataboxManager.
Databox UIBinding
The UIBinding component allows you to bind ui elements to your Databox object.
Bind
Binds a Unity UI component at runtime to a Databox object.
_databoxObject: The Databox object which should be used
_dbID: The database id assigned to DataboxManager
_tableID: The name of the Databox table
_entryID: The entry name
_valueID: The value name
public bool TryGetData<T>(string _tableID, string _entryID, string _valueID, out T _data) where T : DataboxType
public DataboxObject database;
public string tableName;
public string entryName;
public string valueName;
FloatType _float;
if (database.TryGetData<FloatType>(tableName, entryName, valueName, out _float))
{
// Return the float value
Debug.Log(_float.Value);
}
public OrderedDictionary<string, DatabaseEntry> GetEntriesFromTable(string _fromTable)
public DataboxObject database;
public string tableName;
var _table = database.GetEntriesFromTable(tableName);
Debug.Log(_table.Count + " Entries in " + tableName);
// Iterate through all entries
foreach(var entry in _table.Keys)
{
// Do something
}
public Dictionary<string, Dictionary<Type, DataboxType>> GetValuesFromEntry(string _fromTable, string _fromEntry)
public DataboxObject database;
public string tableName;
public string entryName;
var _values = database.GetValuesFromEntry(tableName, entryName);
Debug.Log(_values.Count + " Values in " + entryName);
// Then we iterate through all values
foreach ( var value in _values.Keys)
{
// Do something
}
public bool SetData<T>(string _tableID, string _entryID, string _valueID, DataboxType _value) where T : DataboxType
public DataboxObject database;
var _ok = database.SetData<BoolType>(tableID, entryID, valueID, new BoolType(false));
public bool EntryExists(string _tableID, string _entryID)
public DataboxObject database;
var _ok = database.EntryExists(tableID, entryID);
public bool ValueExists(string _tableID, string _entryID, string _valueID)
public DataboxObject database;
var _ok = database.ValueExists(tableID, entryID, valueID);
public bool RegisterToDatabase(DataboxObject _dbToRegister, string _tableID, string _entryID, string _newEntryID)
public DataboxObjectManager manager;
// Get DataboxObject from DataboxObjectManager
DataboxObject _fromDB = manager.GetDataboxObject(fromDBId);
DataboxObject _toDB = manager.GetDataboxObject(toDBId);
// Get unique Instance id from object for new entry id
int _objectId = this.gameObject.GetInstanceID().ToString()
_fromDB.RegisterToDatabase(_toDB, "TableName", "EntryName", _objectId);
public void LoadDatabase()
public void LoadDatabase(string _fileName)
public void LoadDatabaseAsync()
public void LoadDatabaseAsync(string _fileName)
public DataboxObject data;
StartCoroutine(data.LoadDatabaseAsync());
public void SaveDatabase()
public void SaveDatabase(string _fileName)
public void SaveDatabaseAsync()
public void SaveDatabaseAsync(string _fileName)
public DataboxObject data;
StartCoroutine(data.SaveDatabaseAsync());
public void UploadToCloud()
public void DownloadFromCloud()
public void RemoveDatabaseTable(string _tableName)
public void RemoveEntry(string _tableName, string _entryName)
public void RemoveValue(string _tableName, string _entryName, string _valueName);
public DataboxEvents OnDatabaseLoaded;
public DataboxEvents OnDatabaseSaving;
public DataboxEvents OnDatabaseSaved;
public DataboxEvents OnDatabaseCloudDownloaded;
public DataboxEvents OnDatabaseCloudDownloadFailed;
public DataboxEvents OnDatabaseCloudUploaded;
public DataboxEvents OnDatabaseCloudUploadFailed;
public virtual void Reset(){}
public DataboxObject data;
// First get the data you want to reset
var value = data.GetData<FloatType>("Table", "Entry", "Value");
// Now reset the value
value.Reset();
public ValueChanged OnValueChanged;
// Register to event
public void OnEnable()
{
FloatType health = database.GetData<FloatType>("Table", "Entry", "Value");
health.OnValueChanged += ValueChanged;
}
// Called as soon as value has been changed
public void ValueChanged(DataboxType _value)
{
Debug.Log("Value has changed")
}
public DataboxObject GetDataboxObject(string _dbName)
public void Bind(DataboxObject _databoxObject, string _tableID, string _entryID, string _valueID)
public void Bind(string _tableID, string _entryID, string _valueID)
//Passing the databaseID to the method will use the DataboxManager script to retrieve the databox object
public void Bind (string _dbID, string _tableID, string _entryID, string _valueID)