コード例 #1
0
    public void OnRealTimeMessageReceived(bool isReliable, string senderId, byte[] data)
    {
        if (!gameLoaded)
        {
            return;
        }

        byte messageVersion = (byte)data[0];
        char messageType    = (char)data[1];

        if (messageType == 'U' && data.Length == updateMessageLength)
        {
            Dictionary <string, GameObject> players = levelManager.PlayerList();
            float posX           = System.BitConverter.ToSingle(data, 2);
            float posY           = System.BitConverter.ToSingle(data, 6);
            float velX           = System.BitConverter.ToSingle(data, 10);
            float velY           = System.BitConverter.ToSingle(data, 14);
            bool  facingLeft     = System.Convert.ToBoolean(data [18]);
            bool  attacking      = System.Convert.ToBoolean(data [19]);
            bool  blocking       = System.Convert.ToBoolean(data [20]);
            float health         = System.BitConverter.ToSingle(data, 21);
            float blockingAmount = System.BitConverter.ToSingle(data, 25);

            players [senderId].GetComponent <PlayerController> ().UpdateMultiplayerData(posX, posY, velX, velY, facingLeft, attacking, blocking, health, blockingAmount);
        }
        else if (messageType == 'H' && data.Length == hostMessageLength)
        {
            int spawnPoint  = System.BitConverter.ToInt32(data, 2);
            int pickupValue = System.BitConverter.ToInt32(data, 6);

            PickupSpawner spawner = levelManager.pickupSpawner;

            spawner.SetSpawn(spawnPoint, pickupValue);
        }
        else if (messageType == 'M' && data.Length == mapMessageLength)
        {
            int    mapIndex = System.BitConverter.ToInt32(data, 2);
            string mapName  = mapList[mapIndex];

            LoadMultiplayerGame(mapName);
        }
        else if (messageType == 'S' && data.Length == mapMessageLength)
        {
            int mapIndex = System.BitConverter.ToInt32(data, 2);
            GameObject.Find("Canvas").GetComponent <UIControl_MapSelector>().UpdateMap(mapIndex);
        }
    }