Skip to content

Commit fda24ea

Browse files
authored
Merge pull request #6 from coryleach/dev
Updated Tests & Creation Menu
2 parents d881c2f + b91b41e commit fda24ea

File tree

5 files changed

+69
-22
lines changed

5 files changed

+69
-22
lines changed

Editor/SaveLoadManagerEditor.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using System.IO;
1+
using System.IO;
42
using UnityEditor;
53
using UnityEngine;
64

75
namespace Gameframe.SaveLoad.Editor
86
{
7+
/// <summary>
8+
/// Editor for SaveLoadManager
9+
/// </summary>
910
[CustomEditor(typeof(SaveLoadManager))]
1011
public class SaveLoadManagerEditor : UnityEditor.Editor
1112
{

README.md

+10-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
<p align="center">
2-
<img align="center" src="https://raw.githubusercontent.com/coryleach/UnityPackages/master/Documentation/GameframeFace.gif" />
3-
</p>
41
<h1 align="center">Gameframe.SaveLoad 👋</h1>
5-
6-
<!-- BADGE-START -->
7-
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/2ba0a4bb579d4a96ac91ab77458f7f76)](https://www.codacy.com/manual/coryleach/UnitySaveLoad?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=coryleach/UnitySaveLoad&amp;utm_campaign=Badge_Grade)
8-
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/coryleach/UnitySaveLoad?include_prereleases)
9-
[![openupm](https://img.shields.io/npm/v/com.gameframe.saveload?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.gameframe.saveload/)
10-
![GitHub](https://img.shields.io/github/license/coryleach/UnitySaveLoad)
11-
12-
[![twitter](https://img.shields.io/twitter/follow/coryleach.svg?style=social)](https://twitter.com/coryleach)
13-
<!-- BADGE-END -->
2+
<p>
3+
<img alt="Version" src="https://img.shields.io/badge/version-1.0.3-blue.svg?cacheSeconds=2592000" />
4+
<a href="https://twitter.com/Cory Leach">
5+
<img alt="Twitter: coryleach" src="https://img.shields.io/twitter/follow/coryleach.svg?style=social" target="_blank" />
6+
</a>
7+
</p>
148

159
Serialization helper utility that supports save, load and encryption.
1610

@@ -19,22 +13,22 @@ Serialization helper utility that supports save, load and encryption.
1913
#### Using UnityPackageManager (for Unity 2019.3 or later)
2014
Open the package manager window (menu: Window > Package Manager)<br/>
2115
Select "Add package from git URL...", fill in the pop-up with the following link:<br/>
22-
https://github.com/coryleach/UnitySaveLoad.git#1.0.2<br/>
16+
https://github.com/coryleach/UnitySaveLoad.git#1.0.3<br/>
2317

2418
#### Using UnityPackageManager (for Unity 2019.1 or later)
2519

2620
Find the manifest.json file in the Packages folder of your project and edit it to look like this:
2721
```js
2822
{
2923
"dependencies": {
30-
"com.gameframe.saveload": "https://github.com/coryleach/UnitySaveLoad.git#1.0.2",
24+
"com.gameframe.saveload": "https://github.com/coryleach/UnitySaveLoad.git#1.0.3",
3125
...
3226
},
3327
}
3428
```
3529

3630
<!-- DOC-START -->
37-
<!--
31+
<!--
3832
Changes between 'DOC START' and 'DOC END' will not be modified by readme update scripts
3933
-->
4034

@@ -76,7 +70,7 @@ manager.LoadUnityObjectOverwrite(myScriptableObject,"MyUnityObjectData.data");
7670

7771
## Enable Json.Net Support
7872

79-
Ensure the Json.Net for Unity package has been imported.</br>
73+
Ensure the [Json.Net for Unity](https://assetstore.unity.com/packages/tools/input-management/json-net-for-unity-11347) package has been imported.</br>
8074
In player settings add the string 'JSON_DOT_NET' to Scripting Define Symbols.
8175

8276
<!-- DOC-END -->

Runtime/SaveLoadManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Gameframe.SaveLoad
99
/// SaveLoadManager
1010
/// Manager for saving and loading objects to/from disk.
1111
/// </summary>
12-
[CreateAssetMenu(menuName = "GameFrame/SaveLoad/SaveLoadManager")]
12+
[CreateAssetMenu(menuName = "Gameframe/SaveLoad/SaveLoadManager")]
1313
public class SaveLoadManager : ScriptableObject
1414
{
1515
[Header("Settings"),SerializeField] private string defaultFolder = "SaveData";

Tests/Runtime/SaveLoadManagerTests.cs

+50
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ public class SaveLoadTestUnityObject : ScriptableObject
2424
public Quaternion rot;
2525
}
2626

27+
[Serializable]
28+
public class SaveLoadDictionaryTestObject
29+
{
30+
public Dictionary<string, int> dict = new Dictionary<string, int>();
31+
public string name = "";
32+
}
33+
2734
private static readonly string BaseDirectory = "GameData";
2835
private static readonly string SaveDirectory = "SaveData";
2936
private static readonly string TestEncryptionKey = "SaveLoadTestEncryptionKey";
@@ -169,6 +176,49 @@ public void CanSaveLoadUnityObject([Values] SerializationMethodType method)
169176
Object.Destroy(manager);
170177
}
171178

179+
[Test]
180+
public void CanSaveAndLoadDictionary([Values(
181+
SerializationMethodType.Binary,
182+
SerializationMethodType.BinaryEncrypted
183+
#if JSON_DOT_NET
184+
,SerializationMethodType.JsonDotNet,
185+
SerializationMethodType.JsonDotNetEncrypted
186+
#endif
187+
)] SerializationMethodType method)
188+
{
189+
var manager = CreateManager(method);
190+
191+
var testObject = new SaveLoadDictionaryTestObject()
192+
{
193+
dict = new Dictionary<string,int>
194+
{
195+
{"one", 1},
196+
{"two", 2}
197+
},
198+
name = "Test",
199+
};
200+
201+
const string filename = "Testfile";
202+
203+
manager.Save(testObject,filename);
204+
205+
var filepath = $"{SaveLoadUtility.GetSavePath(SaveDirectory, BaseDirectory)}/{filename}";
206+
Assert.IsTrue(File.Exists(filepath));
207+
208+
var loadedObject = manager.Load<SaveLoadDictionaryTestObject>(filename);
209+
210+
Assert.IsTrue(loadedObject.name == testObject.name);
211+
Assert.IsTrue(loadedObject.dict.Count == testObject.dict.Count);
212+
Assert.IsTrue(loadedObject.dict.ContainsKey("one"));
213+
Assert.IsTrue(loadedObject.dict.ContainsKey("two"));
214+
Assert.IsTrue(loadedObject.dict["one"] == 1);
215+
Assert.IsTrue(loadedObject.dict["two"] == 2);
216+
217+
manager.DeleteSave(filename);
218+
Assert.IsFalse(File.Exists(filepath));
219+
220+
Object.Destroy(manager);
221+
}
172222

173223
}
174224
}

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.gameframe.saveload",
33
"displayName": "Gameframe.SaveLoad",
4-
"version": "1.0.2",
4+
"version": "1.0.3",
55
"description": "Serialization helper utility that supports save, load and encryption.",
66
"keywords": [],
77
"author": {
@@ -11,5 +11,7 @@
1111
"github": "coryleach",
1212
"twitter": "coryleach"
1313
},
14-
"repositoryName": "UnitySaveLoad"
14+
"repositoryName": "UnitySaveLoad",
15+
"type": "library",
16+
"hideInEditor": false
1517
}

0 commit comments

Comments
 (0)