问题描述
我对Signalr相当陌生.我使用signaler核心在unity和signalr之间建立连接,但是我的代码根本没有返回任何信息.这让我想知道我的代码是否真的有效.
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中使用signaler 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版,并且要使其与build一起使用,您需要使您将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连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!