Take these 2 functions as an example
class file{ publicstaticbyte[] ReadAllBytes (string path); Public Static void WriteAllBytes (stringbyte[] data);
If you do not do special processing, readallbytes in the return data to JS, is a byte of a byte copy to JS array. This performance is extremely poor. And, in most cases, the logic code does not need to directly modify the 2 binary data, but just hold it.
Therefore, do not use the above 2 functions directly.
The following is an optional scenario.
1. First implement a byte[] wrapper class in the framework code:
Public classbytearray{ PublicByteArray (intLength =0) {bytes=New byte[length]; } PublicByteArray (byte[] bytes_) {bytes=Bytes_; } Public byte[] bytes; Public intLength {Get { returnBytes! =NULL? bytes. Length:0; } } Public Static voidCopy (ByteArray src, ByteArray DST,intLen) {array.copy (src.bytes, Dst.bytes, Len); } Public Static voidCopy (ByteArray src,intSpos, ByteArray DST,intDposintLen) {array.copy (src.bytes, Spos, Dst.bytes, Dpos, Len); }}
2. Fill in the ByteArray into the jsbindingsettings.classes array to export
3. For a function with a byte[] parameter and a return value of byte[] , write another version, and change the byte[] to ByteArray, for example, the above 2 function handwriting, becomes:
class // Change the name of the class { publicstatic ByteArray readallbytes (string path) { byte [] data = file.readallbytes (path); return New ByteArray () {bytes = data}; } Public Static void WriteAllBytes (string path, ByteArray ByteArray) { file.writeallbytes (path, bytearray.bytes);} }
4. Fill in the Fileex into the jsbindingsettings.classes array to export
5. In the logic code, the version of ByteArray is used, which involves byte[]. For example, the following code reads 2 binary data from a file, and then writes it to another file (the use of logical code to byte[] is a typical transit function)
ByteArray data = fileex.readallbytes ("d:/1.png"); Fileex.writeallbytes ("d:/2.png", data);
Back to: jsbinding+bridge.net:unity Game hot Update scheme
Jsbinding+bridge: Manipulating binary data in logical code