Beispiel #1
0
    public void OnMessageReceived(IKingBuffer kingBuffer)
    {
        switch (kingBuffer.ReadMessagePacket <MyPackets>())
        {
        case MyPackets.PlayerPositionsArray:

            var lengthArr = kingBuffer.ReadInteger();

            Debug.Log($"Got positions array data num : {lengthArr}");

            for (int i = 0; i < lengthArr; i++)
            {
                var playerid = kingBuffer.ReadInteger();

                if (!netPlayersDictionary.ContainsKey(playerid))
                {
                    netPlayersDictionary.Add(playerid, new NetPlayer());
                }

                netPlayersDictionary[playerid].X = kingBuffer.ReadFloat();
                netPlayersDictionary[playerid].Y = kingBuffer.ReadFloat();
                netPlayersDictionary[playerid].Z = kingBuffer.ReadFloat();
            }

            break;
        }
    }
Beispiel #2
0
        /// <summary>
        /// Method responsible for execute the callback of on message received handler.
        /// </summary>
        /// <param name="client">The client instance.</param>
        /// <param name="kingBuffer">The king buffer from received message.</param>
        private void OnMessageReceived(IClient client, IKingBuffer kingBuffer)
        {
            try
            {
                switch (kingBuffer.ReadMessagePacket <MyPackets>())
                {
                case MyPackets.PlayerPosition:

                    float x = kingBuffer.ReadFloat();
                    float y = kingBuffer.ReadFloat();
                    float z = kingBuffer.ReadFloat();

                    Console.WriteLine($"Got position packet : {x} | {y} | {z}");

                    _networkPlayersDictionary[client].X = x;
                    _networkPlayersDictionary[client].Y = y;
                    _networkPlayersDictionary[client].Z = z;

                    _networkPlayersDictionary[client].Moved = true;
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error: {ex.Message}.");
            }
        }