- Notifications
You must be signed in to change notification settings - Fork3
A simple, but yet very powerful save/load system that i have made using C#/.NET and generics...
License
NicolasPCouts/Save-and-Load-System
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A simple, but yet very powerful save system that i have made using C#/.NET and generics...I've made for using in games made with Unity, but with very few alterations you can use it for everything that you want.
ThePlayer.cs Class is an example of a file that you would want to save, the class must derive From theISaveAndLoad interface and Implement the Save and Load methods.
To save the player's data you need to Create a class just for the data, like i did in the example filePlayer.cs.
Inside of this file you have a class calledPlayerData that derives fromSaveableObject and the class needs to have the[System.Serializable]
Attribute, you must define akey for this class, i used in this example "Player" as the key, but you can create anykey that you want.
IF YOU ARE using this save system for a Unity game, you can implement the
GetPrefabPath()
andIsInstantiable()
methods, these are the methods that you can use to define if you want to Instantiate the Object when loading the game or not.IF YOU ARE NOT using this save system for a Unity game, you can just delete these methods from theSaveableObject class.
The Saving Manager is where all the magic happens, the first thing that you want to do when you acess this script is to define theSavingPath variable, you need to define a path to save your files.
After defining the path to save your files, you are ready to go. you can save your data by calling theSaveData<>()
method in the player class or any class the you create that derives from ISaveAndLoad interface and passing 2 arguments.
The first argument(or parameter) is the dataToSave, this would be yourPlayerData class or any class that you create that derives formSaveableObject.
And the second argument is an integer calledSave, this parameter is useful if you want to have multiple save files, but if you just want to have one save file, you can pass the number 1(or any number that you want) to the argument.
If want to load the file, is basically the same process, first you need to call theLoadData<>()
method in the player class or any class the you create that derives fromISaveAndLoad interface.In the first argument you pass the key, in this example case the key would be "Player", and the second parameter you need to put the same number that you put in theSaveData<>()
method.