Configuring Settings
The settings preset or object allows you to configure some aspects of the Save System and control its behaviour. You can also modify the underlying serializer settings to customize the output and the behaviour of it. Here we will change and configure settings in depth, so let's get started.
Warning
After updating the Save System the default settings will be replaced, so in order to make sure you don't lose your own settings, just copy or duplicate the modified default settings preset and place it outside of the default folder and it'll be safe for updates and changes afterwards.
Note
Leaving the Serializer Settings Preset field as None causes the Save System to use the Default Serializer Settings Preset which is placed at Plugins/Bayat/Json/Resources/Bayat/Json/Settings
Changing the Storage
You can change the storage either by modifying the Storage Connection String field or by assigning a new Storage object to the SaveSystemSettings
Storage
property.
Using Settings Preset
You can do it by creating a new custom Save System Settings Preset file:
And then modify the Storage Connection String based on the below syntax:
<Storage Identifier>://<Parameter Name>=<Parameter Value>
For example:
playerprefs://
Because we don't have any special parameters to give to the PlayerPrefs storage, we just ignore them, but for the File storage, we need to specify a path
or a directory to place the save files, by the way you can check the full list of the PlayerPrefs storage parameters here.
Note
You can also use contexual variables such as {0}, {1}, {2}, ... and so on to use important data here, you can find the full list of these variables inside the Default Settings window but for your ease, here is the full list of them:
- {0} = Application.persistentDataPath
- {1} = Application.dataPath
- {2} = Application.streamingAssetsPath
- {3} = Application.temporaryCachePath
- {4} = Application.absoluteURL
- {5} = Application.buildGUID
- {6} = Application.companyName
- {7} = Application.productName
- {8} = Application.identifier
- {9} = Application.version
- {10} = Application.unityVersion
Or you can modify the existing Default settings preset inside the Plugins/Bayat/SaveSystem/Resources/Bayat/SaveSystem/Settings folder:
Using Settings Object
Note
This approach is for intermediate users who can understand code and programming.
You can either modify the default settings object or create a new one and pass it through the API methods:
Default Settings Object
SaveSystemSettings settings = SaveSystemSettings.DefaultSettings;
// You can either instantiate a new instance of the target storage class
settings.Storage = new LocalDiskStorage();
// Or you can use the StorageFactory.FromConnectionString
settings.Storage = StorageFactory.FromConnectionString("disk://path={0}");
New Settings Object
SaveSystemSettings newSettings = new SaveSystemSettings();
// You can either instantiate a new instance of the target storage class
newSettings.Storage = new LocalDiskStorage();
// Or you can use the StorageFactory.FromConnectionString
newSettings.Storage = StorageFactory.FromConnectionString("disk://path={0}");
// And then path it through the API
string identifier = "demo.dat";
string sampleValue = "This is a sample value.";
await SaveSystemAPI.SaveAsync("demo.dat", sampleValue, newSettings);
Note
Make sure to include using Bayat.SaveSystem.Storage
at the top of your script.
Changing Encryption Algorithm
You can change the storage either by modifying the Encryption Algorithm Name field or by assigning a new Encryption Algorithm object to the SaveSystemSettings
Storage
property.
The possible available encryption algorithms for Symmetric encryption are as below:
- Aes or
aes
- DES or
des
- RC2 or
rc2
- TripleDES or
tripledes
Learn more about Symmetric Encryption here >
Using Settings Preset
You can do it by creating a new custom Save System Settings Preset file:
And then modify the Encryption Algorithm Name to any of the available algorithms above, for example:
des
Or you can modify the existing Default settings preset inside the Plugins/Bayat/SaveSystem/Resources/Bayat/SaveSystem/Settings folder:
Using Settings Object
Note
This approach is for intermediate users who can understand code and programming.
You can either modify the default settings object or create a new one and pass it through the API methods:
Default Settings Object
SaveSystemSettings settings = SaveSystemSettings.DefaultSettings;
string algName = "aes";
// You can instantiate a new instance of the SaveSystemSymmetricEncryption class and pass in the algorithm name
settings.EncryptionAlgorithm = new SaveSystemSymmetricEncryption(algName);
// If you have a custom encryption implementation, you can assign it there instead of SaveSystemSymmetricEncryption
New Settings Object
SaveSystemSettings newSettings = new SaveSystemSettings();
string algName = "aes";
// You can instantiate a new instance of the SaveSystemSymmetricEncryption class and pass in the algorithm name
newSettings.EncryptionAlgorithm = new SaveSystemSymmetricEncryption(algName);
// If you have a custom encryption implementation, you can assign it there instead of SaveSystemSymmetricEncryption
// And then path it through the API
string identifier = "demo.dat";
string sampleValue = "This is a sample value.";
await SaveSystemAPI.SaveAsync("demo.dat", sampleValue, newSettings);
Note
Make sure to include using Bayat.SaveSystem.Security
at the top of your script.
Implementing a Custom Encryption Algorithm
You can implement a custom encryption algorithm by implementing the ISaveSystemEncryption
interface and also creating a new Crypto Stream class for the new encryption algorithm by extending the SaveSystemCryptoStream
abstract class.