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(1,1);
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.

posted @ 2016-04-07 13:48  elfnaga  阅读(672)  评论(0编辑  收藏  举报