- Home /
How can I load in data for a derived type class from a CSV?
I'm working on a game that's going to be saving data to a CSV file and the data I've trying to save is derived from a base class. However, I need to be able to load in the data as the derived class because the data is used in different ways for each class. The problem I'm having is that I'm not sure how I can keep track of that in the CSV. I've thought about having a separate CSV file for each class, but that doesn't seem practical since it's all the same data. I'm currently using an enum to track the type, but it seems odd to have that just to keep track of the type. I can't show the actual code that I'm working with, but here's a mock-up of what we basically have:
//The class that our derived classes will inherit from
public abstract class GameDataClass
{
public int Id; //For when we need to reference data by an ID in the List
public GameDataType Type; //The enum used to track the derived type
public List<vector3> Positions;
//The method that is implemented by each class and determines how the data is used
public abstract void UseData();
}
It's not a very complex class. Each class will use the fields in the class and implement the UseData() method differently. When I load in the data from the CSV, I just need to make sure I create an instance of the right class.