public void OldUsage2() { /* Its possible to stay closer to the original Unity syntax by using PlayerPrefsV2 where you typically * would write PlayerPrefs but this will couple the code to Unity. Typically Preferences.instance is * the recommended way to interact with persisted preferences. Below are some examples if you want to * stick to PlayerPrefsV2 anyways: */ // PlayerPrefsV2.SetBool and PlayerPrefsV2.GetBool example: bool myBool = true; PlayerPrefsV2.SetBool("myBool", myBool); Assert.AreEqual(myBool, PlayerPrefsV2.GetBool("myBool", defaultValue: false)); // PlayerPrefsV2.SetStringEncrypted and PlayerPrefsV2.GetStringDecrypted example: PlayerPrefsV2.SetStringEncrypted("mySecureString", "some text to encrypt", password: "******"); var decryptedAgain = PlayerPrefsV2.GetStringDecrypted("mySecureString", null, password: "******"); Assert.AreEqual("some text to encrypt", decryptedAgain); // PlayerPrefsV2.SetObject and PlayerPrefsV2.GetObject example (uses JSON internally): MyClass1 myObjectToSave = new MyClass1() { myString = "Im a string", myInt = 123 }; PlayerPrefsV2.SetObject("myObject1", myObjectToSave); MyClass1 objLoadedAgain = PlayerPrefsV2.GetObject <MyClass1>("myObject1", defaultValue: null); Assert.AreEqual(myObjectToSave.myInt, objLoadedAgain.myInt); }
public void ExampleUsage() { // PlayerPrefsV2.SetBool and PlayerPrefsV2.GetBool example: bool myBool = true; PlayerPrefsV2.SetBool("myBool", myBool); Assert.AreEqual(myBool, PlayerPrefsV2.GetBool("myBool", defaultValue: false)); // PlayerPrefsV2.SetStringEncrypted and PlayerPrefsV2.GetStringDecrypted example: PlayerPrefsV2.SetStringEncrypted("mySecureString", "some text to encrypt", password: "******"); var decryptedAgain = PlayerPrefsV2.GetStringDecrypted("mySecureString", null, password: "******"); Assert.AreEqual("some text to encrypt", decryptedAgain); // PlayerPrefsV2.SetObject and PlayerPrefsV2.GetObject example (uses JSON internally): MyClass1 myObjectToSave = new MyClass1() { myString = "Im a string", myInt = 123 }; PlayerPrefsV2.SetObject("myObject1", myObjectToSave); MyClass1 objLoadedAgain = PlayerPrefsV2.GetObject <MyClass1>("myObject1", defaultValue: null); Assert.AreEqual(myObjectToSave.myInt, objLoadedAgain.myInt); }
public void TestGetAndSetEncyptedString() { var key = "b1"; var value = "val 1"; var password = "******"; PlayerPrefsV2.DeleteKey(key); Assert.AreEqual(null, PlayerPrefsV2.GetStringDecrypted(key, null, password)); PlayerPrefsV2.SetStringEncrypted(key, value, password); Assert.AreEqual(value, PlayerPrefsV2.GetStringDecrypted(key, null, password)); Assert.AreNotEqual(value, PlayerPrefsV2.GetStringDecrypted(key, null, "incorrect password")); Assert.AreNotEqual(value, PlayerPrefsV2.GetString(key, null)); PlayerPrefsV2.DeleteKey(key); }