What is the best way to manage large amounts of static data in Unity 4.3?

Just to give a quick background, I’m a web programmer who is completely new to game programming / Unity as of 4.3.

Basically the game I’m working on has points where the player is asked certain questions and given a chance to select one of the pre-programmed answers (there can be anywhere from 2 to X possible answers for each question.) The game will determine what questions to ask at any given point based on whether the player meets certain prerequisites for that question to be asked… these prerequisites are based on certain elements such as how much XP the player currently has, how much money they have, etc.

So for instance let’s call this question #1. This is the data I’d need to store…

ID #: 1

Question: Would you like to purchase housing?

Prerequisites: 10,000 XP, $50k in cash

Answers: A. Buy a $400k house, B. buy a 200k condo, C. rent an apartment at $750/month, D. live on the streets

Player choice: (NULL until player gets this question, then stores the option they chose)

Maybe some other fields I haven’t thought of yet?

There will probably be a good 100 or so of these questions. So basically, for each id # there are fields that have a 1 to 1 relationship (question text and player’s choice) and fields that have a 1 to many relationship (potential answers, prerequisites.)

If I were making a web app I know exactly how I’d manage this… with a MySQL database. Create a table that holds the question id #, question text, and any other fields with a 1 to 1 relationship, then build a few other tables for the 1 to many relationships. Whenever I need some questions just run a query on the database using the prerequisites and such. Simple.

But I’m not sure if this is the best approach in Unity. I’ve searched around a bit and it seems there is hesitance to use databases with Unity? Maybe there is a better way? I thought about arrays but that could get very messy depending on how many fields I end up with and the 1 to many relationships and such.

Ideas? Suggestions? Etc.?

Also known as ‘virtually none’ in terms of complexity or resource usage.

Just standard .net classes, structs and collections (e.g. array, list, dictionary) is what I’d use. To query the data you can either write standard C#/US or use LINQ.

For storing/loading the data I like to use JSON - as it’s human readable, clean and relatively small (especially when compressed).

Experience: Been there done that.

Oh I know 100s is meaningless in resource usage, I’m thinking from a data management standpoint IE how can I manage all of this data in a way to not give myself headaches when I want to add / edit / remove stuff? I’m so used to just turning to databases for anything data-related because they’re so simple to manage, but it seems like maybe that isn’t the best route here?

I’m not even really sure what collections are, I’ll have to look that up. Maybe I should have noted that I’m also relatively new to C#. My coding experience up to this point has been mostly PHP.

public class QuestionDatabase : ScriptableObject
{
    public List<Question> questions = new List<Question>();
}

[Serializable]
public class Question
{
    public int id = -1;
    public int xpRequired = 0;
    public int moneyRequired = 0;
    public string name = "";
    public string description = "";
    public List<Answer> answers = new List<Answer>();
    public int correctAnswerIndex = -1;
}

[Serializable]
public class Answer
{
    public string name;
    public string description;
}

Serialize “QuestionDatabase” as a .asset using: Unity - Scripting API: AssetDatabase

Save the file in “Resources” folder and load it using: Unity - Scripting API: Resources

Finally, you might need to write a small EditorWindow to display and edit your data if you don’t find the Inspector good enough: Unity - Scripting API: EditorWindow

I’m a bit confused, is the above code something that would go together in one file? To this point I’ve only seen a single class declaration per file, but I’ve also only been making .cs files. I’m also not seeing anything about serialization on the AssetDatabase page?

Stuff deriving from Unity classes, such as ScriptableObject, MonoBehaviour or EditorWindow must exist in their own file with the same name. As for other class, it’s up to you.

As for AssetDatabase, the CreateAsset (http://docs.unity3d.com/Documentation/ScriptReference/AssetDatabase.CreateAsset.html) save (serialize) an asset.

The approach of creating a custom serialized classes as suggested by others above has great advantages, but you can start simpler, with just text files - use Resources.Load to get a (i.e. comma) delimited text file with all your data from the Resources folder, then spin through it and split it into arrays that you can work with - first split on the newline character, then on whatever delimits the data elements.

If you want to use mysql/php, take a look at http://wiki.unity3d.com/index.php?title=Server_Side_Highscores