A very simple interface-based RPC framework:
// Usage:
- Import the plugin into your Unity project.
- Access the service-side project 'WebRPCServer.sln' by visiting 'https://github.com/TianT66/Web-RPC-Server-For-Unity.git'.
- Start the "WebRPCServer.sln" service project.
// Server-side protocol definition:
- Create an interface protocol on the server and use the [WebRPC] attribute. The interface must have a namespace.
- The return type of the methods defined in the interface must be Task or Task.
- The parameters of the methods defined in the interface can be basic types and their corresponding collections, such as int, string, int[], List, string[], List, etc. They can also be custom structures, but these structures must use the [WebRPCParam] attribute.
// Client-side invocation:
- Copy the interface protocol and custom structures to the Unity client.
- var res = await WebRPC.Call().Fun(arg1 , arg2 , ...)
// Important note:
- In Unity 2021.3, the "Newtonsoft.Json.dll" is already included. For other lower versions, please compile the server project first, then locate the dynamic library in the "WebRPCServer\bin\Debug\netcoreapp3.1" folder, and copy it to the "Assets/Plugins" folder.