As i say in the title, i have this code to load the file in editor:
if (Application.isEditor)
{
Something= Resources.Load("ResourceName") as TextAsset;
}
But how to load the same info once the game is built, if the csv file is stored at Application.dataPath?? i can’t find the function in google/Unity manual…
// Code not tested
string path = Application.dataPath + “/Path/To/File.csv”;
Something = new TextAsset( System.IO.File.ReadAllText(path) ) ;
The question is: are you sure your CSV will be located here when the app runs? You may want to consider putting the file in the StreamingAssets if the file already exist in your project, or use Application.persistentDataPath to save & load the file.
Thanks @Hellium for yout time :D I will try it later
private string m_path;
// Start is called before the first frame update
void Start()
{
m_path = Application.persistentDataPath+ "/newcsv.csv";
if (File.Exists(m_path))
{
byte[] m_bytes = File.ReadAllBytes(m_path);
string s = System.Text.Encoding.UTF8.GetString(m_bytes);
Debug.Log(s);
}
}
Hey, Thanks for your answer, i will try it later. But in your code, "s" is a string, and i should get a TextAsset (it comes from a datatable and i need to be structured with columns) How should i get the info in a textasset format?
Thanks @Hellium for yout time :D I will try it later
– tormentoarmagedoom