- Home /
Reading - Writing data to - from file?
Hi,
I started building a game in Swift, but decided to restart in Unity to get the benefits of cross-platform. In Swift I was using a .plist file for game data, but do not know quite what to do in Unity. I have been able to save data to a file using a Binary Formatter, which works well enough for some things, but I'd like to have some data in the game at launch in a file (for an in-game store, so product information and such) which can be read, edited and saved back into the file by the game.
Essentially I'd just like to know what the best approach is - I know there will be many approaches, and each situation differs, but I'm just looking to get started, so any advice would be awesome. I'm open to using any file type (XML/JSON/other), so if someone could point me in the right direction, I'd be really grateful.
Thanks.
C# or UnitScript?
See File and FileStream/StreamReader/StreamWriter classes.
I've been using C# so far, apologies for not including that in the question.
Answer by zombience · Dec 22, 2014 at 08:31 PM
for whatever reason, i've most often come across people saving to xml for the purpose of preferences, save data, etc. maybe it's just my experience, maybe it's more widely used in unity3d applications. i'm not sure.
but if you prefer json, there's a decent json parser on the unity3d wiki:
http://wiki.unity3d.com/index.php?title=JSONObject
otherwise, if you just want to know what library to use and how to use it as far as saving to xml, there is a simple example on the wiki as well:
http://wiki.unity3d.com/index.php?title=Save_and_Load_from_XML
hope that helps
Answer by CodePin · Jul 11, 2015 at 07:05 AM
Reference unity asset package : Simple Save
– Game data or App data local save / load.
– Support compress data.
– Support encryption.
– Support Auto save.(time interval)
– Support Hashtable or String data.