GithubHelp home page GithubHelp logo

nicolaspcouts / save-and-load-system Goto Github PK

View Code? Open in Web Editor NEW
17.0 1.0 3.0 17 KB

A simple, but yet very powerful save/load system that i have made using C#/.NET and generics...

License: MIT License

C# 100.00%
save filesystem file-manager save-files saver savegame saves games game-development unity

save-and-load-system's Introduction

Save and Load System

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.

How To Use:

The Player.cs Class is an example of a file that you would want to save, the class must derive From the ISaveAndLoad 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 file Player.cs.

Inside of this file you have a class called PlayerData that derives from SaveableObject and the class needs to have the [System.Serializable] Attribute, you must define a key for this class, i used in this example "Player" as the key, but you can create any key that you want.

Are you using Unity?

  • IF YOU ARE using this save system for a Unity game, you can implement the GetPrefabPath() and IsInstantiable() 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 the SaveableObject 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 the SavingPath 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 the SaveData<>() 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 your PlayerData class or any class that you create that derives form SaveableObject.

And the second argument is an integer called Save, 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 the LoadData<>() method in the player class or any class the you create that derives from ISaveAndLoad 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 the SaveData<>() method.

save-and-load-system's People

Contributors

nicolaspcouts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.