signalr unity3d connection
Asked Answered
B

1

5

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

Bend answered 23/11, 2017 at 11:18 Comment(8)
what is the output ?What
Supposedly, the output should be "Connection Success!" for unity and "true" from server side but I don't get anything. I'm sorry if I'm asking the obvious. Is there any differences between signalr core and the signalr shown in the tutorial?Bend
where did you find this? Microsoft.AspNetCore.SignalR.Client;What
From NuGet package and then import it to unity3dBend
oh man get singalR implementation in unity3d.What
github.com/gromchen/uSignalRWhat
Ok. Thank you very much sir. I'll give it a try. Does it work with different version of signalr in server side?Bend
i somehow managed to make it work by using unity 2017.2 (previously using unity 2017.1) and also Signalr core but now I'm having a new problem. When I want to build for android, I found get "ArgumentException: The Assembly System.Reflection.Emit is referenced byMicrosoft.AspNetCore.SignalR.Core ('Assets/Plugins/Microsoft.AspNetCore.SignalR.Core.dll'). But the dll is not allowed to be included or could not be found. Which baffled me alot because I'm sure I have included everything inside unity3d plugin folderBend
B
10

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.

Bend answered 2/1, 2018 at 10:40 Comment(2)
I keep getting an error - RuntimeArguments.cs could not be found when I run this demo. How did you make it work?Maribelmaribelle
I followed exactly as the tutorial says.Bend

© 2022 - 2024 — McMap. All rights reserved.