I want to include a data file in my app bundle so that I don’t have to hard-code the data into my program.
In PC, it is easy and works great. But when I export it to iOS.
It crashes since in the data path, the file doesn’t exist.
I want to use “Application.dataPath” or “Application.persistentDataPath”.
Something like “Application.dataPath/my_data_file” but
I don’t know how I can put my_data_file into that directory,
when I export my game into iOS.
You can create a binary file in a Resources folder that Unity will include into your assets and then you can use the asset like:
For example a binary file in Assets/Resources/myBinaryFile.bytes (yes call it .bytes for this to work) then:
TextAsset asset = Resources.Load ("myBinaryFile") as TextAsset;
Then use asset.bytes and asset.bytes.length etc as you see fit. Note, no file extension is given to the Resources.Load() call. It’s confusing that it’s referring to a TextAsset, but this works fine I use it on all platforms.
You can do the same with text files also, except you’d use asset.text instead of asset.bytes.