Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nothing really works when callback is called. #27

Closed
cheneliezer opened this issue Jul 30, 2022 · 2 comments
Closed

Nothing really works when callback is called. #27

cheneliezer opened this issue Jul 30, 2022 · 2 comments

Comments

@cheneliezer
Copy link

        using System;

using System.Collections.Generic;
using SocketIOClient;
using SocketIOClient.Newtonsoft.Json;
using UnityEngine;
using UnityEngine.UI;
using Newtonsoft.Json.Linq;
using UnityEngine.SceneManagement;

public class ClientSocketManager : MonoBehaviour
{
public SocketIOUnity socket;

public Text ReceivedText;
public Image t;


// Start is called before the first frame update
void Start()
{
    //TODO: check the Uri if Valid.
    var uri = new Uri("http://localhost:3000");
    socket = new SocketIOUnity(uri, new SocketIOOptions
    {
        Query = new Dictionary<string, string>
            {
                {"token", "UNITY" }
            }
        ,
        EIO = 4
        ,
        Transport = SocketIOClient.Transport.TransportProtocol.WebSocket
    }); 
    socket.JsonSerializer = new NewtonsoftJsonSerializer();

    ///// reserved socketio events
    socket.OnConnected += (sender, e) =>
    {
                Debug.Log("connected");
        SceneManager.LoadScene("GameScene");
    };
    socket.Connect();

}

}
this is my code. very simple, LoadScene does not work even do the callback is called ( debug.log connected works )

@itisnajim
Copy link
Owner

see: https://github.com/itisnajim/SocketIOUnity#receiving

UnityThread.executeInUpdate(() => {
    // anything related to unity thread run it here!
    objectToSpin.transform.Rotate(0, 45, 0);
});

so your code should be:

    socket.OnConnected += (sender, e) =>
    {
                Debug.Log("connected");
                UnityThread.executeInUpdate(() => {
                        SceneManager.LoadScene("GameScene");
                });
    };

@cheneliezer
Copy link
Author

thank you ! ( also socket.OnUnityThread worked ! )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants