Not sure how to send a scene but what I made is very simple, just a short script on an empty gameobject in a new default scene.
The script puts 3 buttons on the screen:
- one to Save two integer keys ('first' = 1, 'second' = 2) into a cached file
- one to Load the two integer keys (if missing, first will have value of 100, second of 200)
- one to delete the 'first' key
The script:
Code: Select all
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestES3 : MonoBehaviour
{
private readonly string file = "testes3.dat";
private void OnGUI()
{
if (GUI.Button(new Rect(64, 64, 256, 64), "Save"))
{
ES3Settings settings = new ES3Settings(file, ES3.Location.Cache, ES3.Directory.PersistentDataPath, ES3.CompressionType.None, ES3.ReferenceMode.ByRef);
int first = 1;
int second = 2;
ES3.Save("first", first, settings);
ES3.Save("second", second, settings);
ES3.StoreCachedFile(settings);
Debug.LogFormat("Saved - First: {0}, Second: {1} to {2}", first, second, file);
}
if (GUI.Button(new Rect(64, 160, 256, 64), "Load"))
{
ES3Settings settings = new ES3Settings(file, ES3.Location.Cache, ES3.Directory.PersistentDataPath, ES3.CompressionType.None, ES3.ReferenceMode.ByRef);
ES3.CacheFile(settings);
int first = ES3.Load("first", 100, settings);
int second = ES3.Load("second", 200, settings);
Debug.LogFormat("Loaded - First: {0}, Second: {1} from {2}", first, second, file);
}
if (GUI.Button(new Rect(64, 256, 256, 64), "Delete 'first'"))
{
ES3Settings settings = new ES3Settings(file, ES3.Location.Cache, ES3.Directory.PersistentDataPath, ES3.CompressionType.None, ES3.ReferenceMode.ByRef);
ES3.CacheFile(settings);
ES3.DeleteKey("first", settings);
ES3.StoreCachedFile(settings);
Debug.LogFormat("Deleted 'first' from: {0}", file);
}
}
}
So saving and loadnig works just fine. I can store the values and load them back correctly even after restarting the scene. I can delete the file and try loading it which gives me the new default values (100, 200). I can also manually edit the file and delete 'first' key and on load it correctly loads 'first' as 100 (meaning not found in file) and 'second' as 2 (found in file).
BUT pressing the delete button does not do anything to the file on disk... it stays the same no matter what.