How can I read binary files from Resources

时间:2023-03-09 00:34:30
How can I read binary files from Resources

How can I read binary files from Resources
http://answers.unity3d.com/questions/8187/how-can-i-read-binary-files-from-resources.html

TextAsset asset = Resources.Load("enemy_seq_bin") as TextAsset;
Stream s = new MemoryStream(asset.bytes);
BinaryReader br = new BinaryReader(s);

http://docs.unity3d.com/Manual/class-TextAsset.html

//Load texture from disk
TextAsset bindata= Resources.Load("Texture") as TextAsset;
Texture2D tex = new Texture2D(,);
tex.LoadImage(bindata.bytes);

Please notice that files with the .txt and .bytes extension will be treated as text and binary files, respectively.

Do not attempt to store a binary file using the .txt extension, as this will create unexpected behaviour when attempting to read data from it.