signalr unity3d connection

我只是一个虾纸丫 提交于 2019-12-20 14:39:13

问题


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.

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

here is my code :

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


回答1:


Answering my own question for beginner like me looking to work signalr core with 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.

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.



来源:https://stackoverflow.com/questions/47454259/signalr-unity3d-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!