コード例 #1
0
ファイル: Example.cs プロジェクト: romanlara/Pigmentone
 public void Load()
 {
     if (playerLib.HasKey("State"))
     {
         InfoText.text = "LOADED";
         // You can set and get values of any serializable type.
         CurrentState = playerLib.GetValue <PlayerState>("State");
     }
     else
     {
         InfoText.text = "NO ENTRY FOUND. CREATED NEW PLAYERSTATE";
         CurrentState  = new PlayerState();
     }
 }
コード例 #2
0
        void Awake()
        {
            // Create our Perlib.
            // We pass a filename, and an optional password used for encryption.
            // By default, Perlib will use Application.persistentDataPath for its path.

            Perlib savefile = new Perlib("MyAwesomeGame.sav", "csDKndc30ns");


            // You can also use the overloaded constructor to specify a FileInfo.
            // This will instruct Perlib to use a location you chose:

            string savePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Perlib Example\MyAwesomeGame.sav";

            savefile = new Perlib(new FileInfo(savePath), "csDKndc30ns");


            // Now we can open the Perlib. If the Perlib can't find a file at the path specified,
            // it will attempt to create a new one.

            savefile.Open();


            // That's it. Now you can begin saving any type that can be serialized
            savefile.SetValue("Highscore", 5318008);
            savefile.SetValue("Dexterity", 8.7f);
            savefile.SetValue("Fullscreen", true);
            savefile.SetValue("Name", "Moogledoop the Merciless");


            // Including custom classes
            MyClass myObject = new MyClass();

            myObject.Point = new Vector3(34f, 12f, 7f);

            savefile.SetValue("My Object", myObject);


            // And get them back
            int     Highscore  = savefile.GetValue <int>("Highscore");
            float   Dexterity  = savefile.GetValue <float>("Dexterity");
            bool    Fullscreen = savefile.GetValue <bool>("Fullscreen");
            string  Name       = savefile.GetValue <string>("Name");
            MyClass LoadedObj  = savefile.GetValue <MyClass>("My Object");


            // If a key is not found, a default value can instead be returned

            // This will return 0, if not found
            int x = savefile.GetValue <int>("Population");

            // This will return 55378008, if not found
            int y = savefile.GetValue <int>("Population", 55378008);


            // You can also optionally encrypt individual values.
            savefile.SetValue("Encrypted Highscore", 5318008, "x2eEEE3c");


            // The same password will be required next time you try to get the value.
            int decryptedHighscore = savefile.GetValue <int>("Encrypted Highscore", 0, "x2eEEE3c");


            // Most of Perlib was designed to mimic the PlayerPrefs interface
            if (!savefile.HasKey("Highscore"))
            {
                savefile.SetValue("Highscore", 0);
            }

            // Make sure to Save the Perlib to persist changes
            savefile.Save();
        }