Is it possible to assign a text asset property in the editor for testing?
So i have a .json save file of the game right before it errored and so i want to be able to run testing agains that save file so i can debug the code with out having to run the whole game. I would like to be able to assign the textAsset in the editor like one dose for game objects and scriptable objects. Not sure how this is possible with my current understanding of how Unity so serialization.
So here would be the code.
public TextAsset intailGameData;
protected GameModel intialGameModel;
protected GameModel finalGameModel;
protected void BuildInitialGameData() {
if(intailGameData == null) {
Debug.LogError("No Game Data Provided");
return;
}
intialGameModel = BaseModel.loadSaveData<GameModel>(intailGameData.bytes);
}
And in the editor window when i select the test file I would like to be able to drag and drop the save file.
I know i can load the file using the specific path to the file but thats not a very clean.
Any ideas on how to achieve something like this? or even some good search terms to get me closer to an answer.
Thanks,
I'm not sure to understand what you are trying to do.
Do you want to call BuildInitialGameData
or do you want to set the value of intailGameData
without running the game? How do you assign it at runtime?
I wan't to be able to set that TextAsset in the editor without having to load the file using something Like File.ReadAllBytes(path)
, not sure if that clarifies anythings. As far as how i load game data at run time the code follows a MVC architecture and so I'm just trying to test the model data and some controller methods that manipulate the model, so i can separate data bugs from visual bugs.
So I guess the code snippet you've provided is not part of a MonoBehaviour?
You might be interested in Unit Testing to test your code.
To load an asset in the editor, you can rely on the AssetDatabase class.