sigtrapgames / SmartData

A designer-friendly, editor-driven Unity3D framework for connecting data and events.
MIT License
271 stars 14 forks source link

Serialization #2

Closed yonoslaw closed 6 years ago

yonoslaw commented 6 years ago

Hi! Great framework, I love it!

I'm trying to use it in my code but I miss something that I did implement in Ryan's examples when researching this idea. I was thinking how to serialize the state of smart variables ( a save game ) and came with an idea of adding a serialize, deserialize method to smart variable. It returned a json of a variable content and could parse a json to setup a variable on load. Then the json was used as a value in a <string,string> dictionary serialized to disk. What is your idea to serialize a bunch of smart variables using your framework?

sigtrapgames commented 6 years ago

I would recommend writing a Decorator. If you write a generic Decorator which does the actual save/load, and then write a custom template and add it to the Generate Smart Type editor settings, you can create a concrete Decorator for each SmartType automatically. Then this Decorator can be added to all the SmartObjects you're interested in saving/loading.

Something I've not tried, but in theory should work, is having an EventListener field on the Decorator too, so you can create Save and Load EventVars which the Decorators then respond to. It might end up being simpler having a static registry of your Decorators and call a static method, but if you want to keep it all in the SmartData way of thinking I think that should work.

yonek commented 6 years ago

Thanks. I will try to dig into the decorators. Looking forward for some more documentation. :)

sigtrapgames commented 6 years ago

Yeah, it's sorely needed!