PLAYERPREFS EXTENSION ON THE ASSET STORE
Hello guys! I want to introduce my first asset in Asset Store - PPE.
PPE == PlayerPrefs Extension
PPE is the extension of standard PlayerPrefs. It has visual editor, supports extensive list of types (arrays of types) and also it has crypto manager (AES 256, salted).
Supported types:
- bool, bool[ ]
- int, int[ ], long, long[ ]
- float, float[ ], double, double[ ]
- string, string[ ]
- Vector2, Vector2[ ], Vector3, Vector3[ ], Vector4, Vector4[ ]
- Quaternion, Quaternion[ ]
- Rect, Rect[ ]
- Color, Color[ ]
- DateTime, DateTime[ ]
- Texture2D
- Serializable objects
Supported all platforms:
- iOS, Android, Windows Phone
- Windows, Mac OS, Linux
- WebGL
- …
Features:
- Simple to use
- Extensive list of supported types
- PlayerPrefs interface
- Code was tested (included 58 tests)
- Values are encrypted (AES 256, salted)
- Documented (IntelliSense)
- Included source code
Requirements:
- Unity 5.1.0 and above
How to use:
Method 1
using ZBS;
// ...
PPE.SetInt("TheUltimateQuestionOfLife", 42);
Method 2
using PlayerPrefs = ZBS.PPE;
// ...
PlayerPrefs.SetInt("TheUltimateQuestionOfLife", 42);
Examples:
Example 1
using PlayerPrefs = ZBS.PPE;
// ...
Vector2[] positions = { new Vector2(100, 20), new Vector2(-1, 13) };
var key = "positions";
PlayerPrefs.SetVector2Array(key, positions);
PlayerPrefs.Save();
// ...
if (PlayerPrefs.HasKey(key))
{
var savedPosition = PlayerPrefs.GetVector2Array(key);
var startX = savedPosition[1].x;
Debug.Log("startX = " + startX);
}
Example 2
var foo = new Foo();
foo.a = 12;
foo.b = -1254.0f;
foo.c = true;
PPE.SetObject("foo", foo, true); // 3rd param - crypto
PPE.Save();
// ...
var savedFoo = PPE.GetObject<Foo>("foo");
Debug.Log("savedFoo.b = " + savedFoo.b);
Example 3
PPE.SetDateTime("lastGameDate", DateTime.Now);
PPE.SetBoolList("settings", new List<bool> { true, false, false }, true); // crypto
PPE.Save();
// ...
DateTime lastGameDate = PPE.GetDateTime("lastGameDate");
List<bool> savedSettings = PPE.GetBoolList("settings");
Debug.Log("lastGameDate = " + lastGameDate);
Debug.Log("savedSettings[1] = " + savedSettings[1]);
Protected:
Very simple way to add encryption just set true for 3rd param (isNeedCrypto) in the setter method.
Protected example
string key = "cryptoTest";
string stringValue = "bla bla bla";
// 3rd param - crypto (default - false)
PPE.SetString(key, stringValue, true); // encrypted and salted value
// save
PPE.Save();
// get string
string resultStringValue = PPE.GetString(key);
Publishing:
If you want to publish your project, make sure to use unique protect key (see PPECryptoManager prefab).
Changelog:
Current version: 1.1.0
1.2.0 (In progress…)
- ADDED: Generic method for GetObject().
- UPDATED: Tests for Unity 5.5.
1.1.0 (Released)
- FIXED: default values.
- FIXED: problem with raw data for Texture2D.
- UPDATED: documentation.
1.0.0
- Initial release.
Questions/Suggestions:
If you have any questions or suggestions please drop a line for me.
Thanks.
// Vladimir Sakhan