I made a data-driven engine for Text101. Rather than hard-coding a fixed number of states, I can now write any story with any number of states in a JSON resource file.
My starting point was the official serialization guide. The JsonUtility module was introduced in Unity 5, so I had to move the project to that.
The JSON data format has a couple differences from the C# objects’ format. JsonUtility can’t yet parse a JSON object into a dictionary, so in JSON any key/value collection must be an array instead. When the value type is an object, I make the key a member of the object. Otherwise, I store alternating keys and values in the array: [key, value, key, value, key, value, …]
Further ideas:
- Story editor GUI (starting point)
- Variables like time, money, etc.
- AI of other characters: goals and logic for accomplishing them