Storage
Saving and loading individual storages.
Saving
There are 3 things that require saving here: items, enchantments (applied to items), and currencies. You can use myStorage.CreateSavableData to get an object that contains all of this data. This method will return a InventoolSavableData struct.
InventoolSavableData mySavableData = myStorage.CreateSavableData();Loading
To load you will need to provide your own method of loading. Use the Storage.SetLoader and provide a method that will load a InventoolSavableData object. Inventool will call this to load a storage when necessary. The method should accept a string parameter that represents the ID of the storage.
Storage.SetLoader(MyStorageLoadingMethod);Examples
The code below is how you can save and load storage data with ESave. ESave is my own save system—it's entirely free, and it's been tested with Inventool. ESave is not a requirement; you can use the save system of your choice. However, the example below will only work with ESave.
With ESave Free
using Esper.ESave;
using Esper.Inventool;
using Esper.Inventool.DataManagement;
using Esper.Inventool.Storing;
using UnityEngine;
public class StorageSavingAndLoadingExample : MonoBehaviour
{
private SaveFile saveFile;
private void Start()
{
saveFile = GetComponent<SaveFileSetup>().saveFile;
// Saving when the window is closed
Storage.onStorageClosed.AddListener(SaveStorage);
// Setting the loader—the LoadStorage method is used by Inventool to load all storages
Storage.SetLoader(LoadStorage);
}
/// <summary>
/// Saves a storage.
/// </summary>
/// <param name="storage">The storage.</param>
private void SaveStorage(Storage storage)
{
saveFile.AddOrUpdateData(storage.id, storage.CreateSavableData());
saveFile.Save();
}
/// <summary>
/// Loads and returns saved storage data.
/// </summary>
/// <param name="id">The storage ID.</param>
/// <returns>Loaded storage data.</returns>
private InventoolSavableData LoadStorage(string id)
{
var storageData = saveFile.GetData<InventoolSavableData>(id);
return storageData;
}
}With ESave Pro
In case you're using the pro version...
Last updated