void Awake()
    {
        players = new Dictionary <int, GameObject>();

        this.gcws = GameClientWebSocket.getInstance(); //Init WebSocket in Awake()!
        onConnect();
    }
예제 #2
0
    public static GameClientWebSocket getInstance()
    {
        if (instance == null)
        {
            instance = new GameClientWebSocket();
        }

        return(instance);
    }
    async void fetchExistingPlayers()
    {
        Debug.Log("Fetching existing players");
        MessageType message = new MessageType();

        message.action = GameConstants.FETCH_EXISTING_PLAYERS;
        string json = JsonUtility.ToJson(message);

        ArraySegment <byte> b = new ArraySegment <byte>(Encoding.UTF8.GetBytes(json));
        await GameClientWebSocket.getInstance().GetClientWebSocket().SendAsync(b, WebSocketMessageType.Text, true, CancellationToken.None);
    }
    async void getMessagesFromServer()
    {
        ArraySegment <byte> buffer = GameClientWebSocket.getInstance().getBuffer();

        if (buffer == null)
        {
            Debug.Log("ERROR: The buffer is empty!");
        }
        WebSocketReceiveResult r = await this.gcws.GetClientWebSocket().ReceiveAsync(buffer, CancellationToken.None);

        performAction(r, buffer);


        getMessagesFromServer();
    }
예제 #5
0
    async void SendAxis(float deltaTime, float h, float v)
    {
        MovementData movementData = new MovementData();

        movementData.action    = GameConstants.UPDATE_POSITION;
        movementData.deltaTime = deltaTime;
        movementData.h         = h;
        movementData.v         = v;

        string json = JsonUtility.ToJson(movementData);

        Debug.Log(json);
        ArraySegment <byte> b = new ArraySegment <byte>(Encoding.UTF8.GetBytes(json));
        await GameClientWebSocket.getInstance().GetClientWebSocket().SendAsync(b, WebSocketMessageType.Text, true, CancellationToken.None);
    }