In a long time ago I found raknet, compared to several open source network library, found that raknet is a good choice. Raknet is more suitable for game development, but in my mobile phone point-to-point video chat project is still used raknet. Using raknet as a mediation server, mobile phone peer success or use raknet communication. The effect is good, the video voice will not lose packet, very clear and smooth. Of course, in the case of poor network conditions, can be set raknet allow packet loss, still can have a good effect.
Raknet The disadvantage is not support multicast, in the video more professional LIBRTP support multicast, but the shortcomings of LIBRTP is also obvious, it does not support the UDT, and if you use Raknet server, in LIBRTP communication, the interface between them is also very time-consuming.
Nonsense has been said, I have been engaged in the development of the game has been four years, according to market winds, a few people are partnering to do a mobile phone version of the game of instant battle. The opportunity to re-raknet. Official online to see raknet support Swig C #, also vaguely found on the internet said to support Unity3d. Is that true? Non-also, the official online raknet it can only be converted into Windows under the C # interface to use, as long as it can go to C #, it will certainly be able to use in unity under Windows. But if it doesn't work with iOS, Android or Mac, why not, because it's not supported.
Also, Unity says it comes with Raknet, confirmed that the bottom of masterserver is implemented with raknet, you can use C + + raknet to open a server, with Masterserver connection is able to receive the correct response, But the bottom of the masterserver with the raknet, it is only encapsulated to provide me wart a few simple interfaces, and then, want to use raknet method or some, it needs to modify their own.
First look at what Swig is, Swig is a code generation tool that we need to configure data in swig format to generate the language code we want.
The first step is to generate C # code using the Raknet official website, which is directly available in unity under Windows. You can be sure that all raknet C # interfaces are exposed through raknet_wrap.cpp. All C # calls to Raknet are then called by RakNetPINVOKE.cs. Can view the Raknet_wrap file, which is in accordance with a standard package to the outside call, we can say that this standard is the SWIG standard. For this standard, we do not need to know what it is, we will just follow this standard to modify the code inside the Raknet_wrap.
Let me explain the process of using raknet in C # on Windows: First swig genetic a raknet_wrap C + + file, and then use the compiler to generate a dynamic library of the file. Then C # can call this dynamic library directly.
Now that we have the source code, all the questions, the unity iOS down with C + + 's simplest configuration method is to copy the C + + source directly to Plugins\ios, the rest of the work is unity will generate the Xcode project file, and then we compile the project file to generate the program.
Need to note that we want to modify the Raknet_wrap file and corresponding RakNetPINVOKE.cs file, so use the source code as a plug-in way more conducive to our modification. We compile it directly on the XOCDE when we modify it, Xcode will have the corresponding error prompt, then we fix the prompt, compile.
It is pointed out directly that the iosc# call Dynamic library differs from others and must be changed to [DllImport ("__internal", entrypoint= "Funname")], while Android Mac needs [DllImport ("Raknet", Entrypoint= "Funname")], and the name of the entrypoint must be the same as the name of the direct reference, otherwise it will not be called normally.
There is a requirement for unity tools, unity must be genuine, or cracked genuine, the trial version is not support plug-ins, so there will be problems.
The main problem is these, next we can follow the prompts to modify the small problem.
A code address is attached below.
Https://git.oschina.net/no_this/client
Attention, this problem I spent a lot of time to study the solution, there is no such solution at home and abroad, reproduced please indicate the source.
by Wang Xiaoshuai
Raknet for Unity3d Mobile version compilation method