void Awake() { // Open a new library. if (playerLib == null) { playerLib = new Perlib("savedata"); } playerLib.Open(); Load(); }
public static void Open() { slash = Path.DirectorySeparatorChar; dataPath = Path.GetDirectoryName(Application.dataPath); folderPath = dataPath + slash + "SaveGame"; settingsLip = new Perlib(new FileInfo(folderPath + slash + "Settings.sav"), PASS_SETTINGS); saveGameLip = new Perlib(new FileInfo(folderPath + slash + "SaveGame.sav"), PASS_SAVEGAME); settingsLip.Open(); saveGameLip.Open(); }
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(); }