WebSocket SignalR 2 Unity 2018 .Net 4.x

WebSocket SignalR 2 Unity 2018 .Net 4.x

結論:

1.下載以下兩個套件

Microsoft.AspNet.SignalR.Client

Newtonsoft.Json

2.提取Dll

下載的.nupkg改成.zip後解壓縮

把 \lib\net45\*.dll 放進Unity專案\Assets\Plugins

Ex:newtonsoft.json.12.0.2\lib\net45\Newtonsoft.Json.dll

3.建立\Assets\link.xml

<linker>
  <assembly fullname="System.Core">
    <type fullname="System.Linq.Expressions.Interpreter.LightLambda" preserve="all" />
  </assembly>
</linker>

4.建立Script

async void Start()
{
    var hubConnection = new HubConnection("http://192.168.0.62:7800/");
    IHubProxy _chatHubProxy = hubConnection.CreateHubProxy("ChatHub");
    chatHubProxy.On<string,string>("BroadcastMessage", (cname, message) =>
    {
        // do something
        Debug.Log($"{cname} say {message}.");
    });
    // connect
    await hubConnection.Start();
        
    // send something to server
    await _chatHubProxy.Invoke("Send", "JAKE","測試訊息" );
}

5.確認腳本執行版本與API相容性是 4.x

SignalR Client API 相關說明文件請到下面連結查詢

ASP.NET SignalR Hubs API Guide - .NET Client (C#)

參照:在 Unity 中使用 .NET 4.x

測試環境:Unity 2018.3.7f1

PS5