When it comes time to save, transfer your data from their runtime types into a POD, and save that to a disk.Whether you need to save high scores, preferences, or a game state, Unity offers a variety of methods from PlayerPrefs to serializing data, encrypting it, and writing to a file.It covers some of the common ways to save and load data in your Unity project, but its by no means an exhaustive list.That is to say, there are more ways to serialize data than youll ever need, and each approach solves a particular problem and comes with its own set of strengths and weaknesses.
You can use PlayerPrefs to store a players preferences between sessions, such as quality settings, audio volume or other non-essential data. PlayerPrefs are stored somewhere on your device, separate from your project. The exact location varies depending on your operating system, but its usually somewhere thats globally accessible and managed by your OS. Because of their ease of access, they arent safe from users who wish to open and modify them, and they can be deleted by accident since theyre saved outside of the project and managed by your OS. A determined user can overcome this limitation by converting their saved data into some format represented by one of these basic types, but I dont recommend it since that there are better tools to store your data. Save ( ); public void LoadPrefs ( ) int volume PlayerPrefs. That is, its easily understood by people and machines alike which has both advantages and disadvantages. Its much easier to debug your saved data or create new save data for testing purposes when you can read and understand it, but, on the other hand, its easy for players to read and modify the data as well. The ability to read and change data is useful if you support modding but detrimental if you want to prevent cheating. Every use case is different, and its these kinds of tradeoffs that lead developers to create many other data formats. As a result, all platforms support it strongly, which is helpful when building cross-platform games. JSON was developed as a communication protocol for web browsers, making it inherently good for sending data over a network. Because of this, JSON is excellent for sending and receiving data from a server backend. Similar to PlayerPrefs, its also relatively easy to implement. However, unlike PlayerPrefs, you must save the JSON data yourself, either in a file or over a network. Handling the data storage yourself makes it easy to manage multiple save files because you can store each file in a different location. To make this easier, I wrote a basic file manager, which is available in this example repository. If youre used to working with JSON data, you may notice the lack of support for specific features. Holding back certain features was a deliberate design choice, and JsonUtility is faster and more efficient than other.NET JSON solutions as a result. To work around these limitations, you could create Plain Old Data types (or PODS) to hold all your save data.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |