示例#1
0
 public FileStorageApi()
 {
     Storage = PlayerFiles.ReadFromFile <StorageData>(StorageName);
     if (Storage == null)
     {
         Storage = new StorageData();
     }
 }
示例#2
0
        public void UnityObject_TestSimplePasses()
        {
            var storage = new StorageService(StorageType.PlayerPrefs);

            storage.SetBool("test_key_bool", true);
            Assert.That(storage.GetBool("test_key_bool"), Is.EqualTo(true));

            storage.SetInt("test_key_int", 11);
            Assert.That(storage.GetInt("test_key_int"), Is.EqualTo(11));

            storage.SetFloat("test_key_float", 13.37f);
            Assert.That(storage.GetFloat("test_key_float"), Is.EqualTo(13.37f));

            storage.SetString("test_key_str", "value");
            Assert.That(storage.GetString("test_key_str"), Is.EqualTo("value"));


            storage = new StorageService(StorageType.InMemory);

            storage.SetBool("test_key_bool", true);
            Assert.That(storage.GetBool("test_key_bool"), Is.EqualTo(true));

            storage.SetInt("test_key_int", 11);
            Assert.That(storage.GetInt("test_key_int"), Is.EqualTo(11));

            storage.SetFloat("test_key_float", 13.37f);
            Assert.That(storage.GetFloat("test_key_float"), Is.EqualTo(13.37f));

            storage.SetString("test_key_str", "value");
            Assert.That(storage.GetString("test_key_str"), Is.EqualTo("value"));


            storage = new StorageService(StorageType.FileStorage);

            storage.SetBool("test_key_bool", true);
            Assert.That(storage.GetBool("test_key_bool"), Is.EqualTo(true));

            storage.SetInt("test_key_int", 11);
            Assert.That(storage.GetInt("test_key_int"), Is.EqualTo(11));

            storage.SetFloat("test_key_float", 13.37f);
            Assert.That(storage.GetFloat("test_key_float"), Is.EqualTo(13.37f));

            storage.SetString("test_key_str", "value");
            Assert.That(storage.GetString("test_key_str"), Is.EqualTo("value"));


            storage.Save();

            string savedFile = PlayerFiles.UnitySavesPath + FileStorageApi.StorageName;
            string jsonData  = Serializer.Serialize((storage.Api as FileStorageApi)?.Storage);

            Assert.That(PlayerFiles.FileExists(savedFile), Is.EqualTo(true));

            Assert.That(PlayerFiles.ReadAllText(savedFile) == jsonData, Is.EqualTo(true));
        }
示例#3
0
 public override void Commit()
 {
     PlayerFiles.SaveToFile(StorageName, Storage);
 }