信号器 unity3d 连接 [英] signalr unity3d connection

查看:34
本文介绍了信号器 unity3d 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对信号器相当陌生.我使用信号器核心在统一和信号器之间建立连接,但我的代码根本没有返回任何东西.这让我想知道我的代码是否真的有效.

I am fairly new to signalr. Im using signalr core to make connection between unity and signalr but my code doesn't return me anything at all. That leaving me wondering if my code is actually working or not.

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

After I've established connection, unity will wait for server side to call a function then it will execute what it need to do.

这是我的代码:

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
    }
}

如果有人可以帮助新手,我很感激.谢谢

I appreciate if someone can help a newbie. Thank you

推荐答案

为像我这样希望使用 unity3d 工作 Signalr Core 的初学者回答我自己的问题.

Answering my own question for beginner like me looking to work signalr core with unity3d.

此时我想使用的 SignalR Core 可以还不能与 unity3d 一起使用,因为它不稳定,而且在使用之前必须解决很多问题.

At this moment the SignalR Core which I want to use, can't work with unity3d yet as it is not stable and a lot of things has to be sort out before it can be use.

我发现了一个 教程(但德语) 对我有用.SignalR(非核心)使用版本 2.1.1 并使其与构建一起使用,您需要让您 更改 api 兼容性 到 .Net 2.0(不是子集)

I found a 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 to .Net 2.0 (not subset)

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

Hopefully someone will benefit from my answer.

这篇关于信号器 unity3d 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆