Organize data in a multi-column table

Hi,

As a complete beginner, I’m working for a study project where I need to do a couple actions and export the resulting data. The way I export this data doesn’t matter but it needs to be organized as a 3 columns table where the first column contains strings, the second floats and the third ints. I also need to increase the length of this table at runtime.

How can I manage to do this?
How will I be able to add a whole new line (length)?
How will I be able access a specific value of this list?

Thanks a lot

What do you mean by “export”? Do you mean visually or just to export the data to a data format like JSON, XML, …? Since you said “organise” it sounds like a pure programming problem. However if you actually mean to visually display the data it would be a completely different problem.

To represent the data in C# the best solution for a fix data values per “line” / data record would be to simply use a class or struct

[System.Serializable]
public class DataRecord
{
    public string nameOfFirstColumn;
    public float nameOfSecondColumn;
    public int nameOfThridColumn;
}

The actual “table” would be just a List<DataRecord>

List<DataRecord> table = new List<DataRecord>();

To add a new record you just do

DataRecord row = new DataRecord();
// set your values of "row".
table.Add(row);

To export the data to JSON you can either represent each “row” as nested array or as object

[
    ["some string", 0.45, 5],
    ["some string", 0.45, 5],
    ["some string", 0.45, 5],
]

Of course when exporting as object the data values do not have a specific “order” but they are named properties. Something like

{
    {
        "name":"some string",
        "weight": 0.45,
        "value": 5
    },
    {
        "name":"some string",
        "weight": 0.45,
        "value": 5
    },
    {
        "name":"some string",
        "weight": 0.45,
        "value": 5
    },
}

JSON text can be created in several ways. One would be to use Unity’s JsonUtility class. However it’s very limited as it’s strictly bound to actual classes and variable names. I’ve created the SimpleJSON framework which allows easy creation and parsing of JSON text.

Another common export format for tables would be CSV, so just a comma / character seperated values. Such files can easily be opened in Excel or similar programs.

some string;0.45;5
some string;0.45;5
some string;0.45;5

Those can be easily constructed since it’s just plain text with a seperator.

If you want to visually display the data inside your Unity application you have to look into the UI system. There are too many ways how you can tackle this so without further details i will stop here ^^.