Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        public void TestGetAndSetBool()
        {
            var key = "b1";

            Assert.IsFalse(PlayerPrefsV2.GetBool(key, false));
            PlayerPrefsV2.SetBool(key, true);
            Assert.IsTrue(PlayerPrefsV2.GetBool(key, false));
            PlayerPrefsV2.DeleteKey(key);
        }
Example #4
0
 void Start()
 {
     links          = gameObject.GetLinkMap();
     toggle1().isOn = PlayerPrefsV2.GetBool(TOGGLE1, false);
     toggle2().isOn = PlayerPrefsV2.GetBool(TOGGLE2, false);
     toggle3().isOn = PlayerPrefsV2.GetBool(TOGGLE3, false);
     links.Get <Button>("SaveButton").SetOnClickAction(delegate {
         PlayerPrefsV2.SetBool(TOGGLE1, toggle1().isOn);
         PlayerPrefsV2.SetBool(TOGGLE2, toggle2().isOn);
         PlayerPrefsV2.SetBool(TOGGLE3, toggle3().isOn);
         gameObject.GetViewStack().SwitchBackToLastView(gameObject);
     });
 }