20150709

Saving and loading maps

I am lazy. I wanted to figure out a file structure for storing maps, but then I thought it would be easier to just serialize the whole Map object to a file, and then load it back. It isn't programmer-friendly, meaning it is really hard to write a map file parser, if you don't use C# and you don't know the layout of the Map object. I promise, if the need ever arises, I will rewrite the whole map saving/loading part.

So currently, I'm using System.Serializable for saving and loading maps. There was a little problem, though (other than figuring out how serializing actually works): Unity's Vector2 is not Serializable. I am in a fortunate situation, as I don't use Unity's types extensively in my Map object, so it was easy and fast to write an ad-hoc replacement for Vector2, but if you ever want to use C#'s internal serializer, know about this problem: Unity's types are not serializable by the default C# Serializer.

Anyway, a gif from the Save / New / Load dialog:


No comments:

Post a Comment