信号器 unity3d 连接

signalr unity3d connection

我对信号器还很陌生。我使用 signalr core 在 unity 和 signalr 之间建立联系,但我的代码根本 return 没有任何意义。这让我想知道我的代码是否真的有效。

建立连接后,unity 会等待服务器端调用一个函数,然后它会执行它需要做的事情。

这是我的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Microsoft.AspNetCore.SignalR.Client;

public class tyrNewSignalR : MonoBehaviour {

    void Start()
    {
        var connection = new HubConnectionBuilder()
                .WithUrl("http://api-dev-vrcafe.azurewebsites.net/restart")
                .WithConsoleLogger()
                .Build();

        connection.On<string>("Restart", data =>
        {

             Console.WriteLine($"Received: {data}");

            // Create unity part
            // Unity logic
            Debug.Log("Connection Success!");

            cleanCart();
        });

        connection.On<string>("Cart", data =>
        {

            Console.WriteLine($"Received: {data}");

            // Create unity part
            // Unity logic

        });

        connection.StartAsync();
    }

    void cleanCart()
    {
        // Do cleaning cart here
    }
}

如果有人能帮助新手,我将不胜感激。谢谢

为像我这样希望使用 unity3d 处理 signalr core 的初学者回答我自己的问题。

目前我想要 use 的 SignalR 核心还不能与 unity3d 一起工作,因为它不稳定,在使用之前必须解决很多问题。

我找到了 tutorial (but in German) which is working for me. The SignalR (not core) is using version 2.1.1 and to make it work with build, you need to make you change api compatibility 到 .Net 2.0(不是子集)

希望有人能从我的回答中受益。