Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

signalr unity3d connection

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

like image 880
kim Avatar asked Nov 23 '17 11:11

kim


1 Answers

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.

like image 125
kim Avatar answered Oct 20 '22 15:10

kim