示例#1
0
    public async void JoinOrCreateRoom()
    {
        leaveLastRoom();
        this.room = await client.JoinOrCreate <GameState>("GameRoom");

        readMessages();
        setListeners();


        this.gameObject.name += " [" + this.room.SessionId + "]";
    }
示例#2
0
    private async void JoinOrCreateRoom()
    {
        this.room = await client.JoinOrCreate <GameState>("GameRoom", new Dictionary <string, object>() { });

        //room.State["world"].onChange += OnChangeObjects;
        room.State.world.objects.OnChange += OnChangeObjects;
        room.State.world.objects.OnAdd    += AddObject;

        this.room.OnMessage <float>("time", (val) =>
        {
            // Debug.Log("Delta time" + (val - lastTime));
            GUIConsole.Instance.deltaTime = val;
        });
    }
示例#3
0
    /*
     * Joins an already created room. If the room does not exist it is created and then the client joins the newly created room.
     * Username is the clients name, battleName is the name of the room to join, and stateHandler is a callback function that gets
     * invoked on a state change.
     */
    public async void JoinOrCreateRoom(string username, float playerHealth, string battleName, Colyseus.Room <State> .RoomOnStateChangeEventHandler stateHandler, Colyseus.Room <State> .RoomOnMessageEventHandler messageHandler)
    {
        // Joins/sets up the room.
        Debug.LogFormat("{0} is trying to join room: {1}", username, battleName);
        room = await client.JoinOrCreate <State>(roomName, new Dictionary <string, object>() { { "name", username }, { "playerHealth", playerHealth }, { "battleName", battleName } });

        Debug.LogFormat("Room Id: {0}\tSession Id: {1}", room.Id, room.SessionId);

        // Sets event callback functions.
        room.OnStateChange += stateHandler; // look at OnStateChangeHandler below as an example.
        room.OnMessage     += messageHandler;
        room.OnLeave       += (code) => Debug.LogFormat("Left Room with Code: {0}", code);
        room.OnError       += (message) => Debug.LogErrorFormat("Colyseus Error: {0}", message);
    }
    //public async void CreateRoom()
    //{
    //	room = await client.Create<State>(roomName, new Dictionary<string, object>() { });

    //	m_SessionIdText.text = "sessionId: " + room.SessionId;

    //	room.State.entities.OnAdd += OnEntityAdd;
    //	room.State.entities.OnRemove += OnEntityRemove;
    //	room.State.entities.OnChange += OnEntityMove;

    //	PlayerPrefs.SetString("roomId", room.Id);
    //	PlayerPrefs.SetString("sessionId", room.SessionId);
    //	PlayerPrefs.Save();

    //	room.OnLeave += (code) => Debug.Log("ROOM: ON LEAVE");
    //	room.OnError += (message) => Debug.LogError(message);
    //	room.OnStateChange += OnStateChangeHandler;
    //	room.OnMessage += OnMessage;
    //}

    public async void JoinOrCreateRoom()
    {
        room = await client.JoinOrCreate <State>(roomName, new Dictionary <string, object>() { { "name", "Jordan" }, { "battleName", "Node_1" } });

        m_SessionIdText.text = "sessionId: " + room.SessionId;

        PlayerPrefs.SetString("roomId", room.Id);
        PlayerPrefs.SetString("sessionId", room.SessionId);
        PlayerPrefs.Save();

        Debug.LogFormat("Room Id: {0}\tSession Id: {1}", room.Id, room.SessionId);

        room.OnLeave       += (code) => Debug.Log("ROOM: ON LEAVE");
        room.OnError       += (message) => Debug.LogError(message);
        room.OnStateChange += OnStateChangeHandler;
        room.OnMessage     += OnMessage;
    }