예제 #1
0
    private void ReceivedTileChange(NetworkMessage message)
    {
        // Called when a tile has changed in the world.
        Msg_SendTile data = message.ReadMessage <Msg_SendTile>();

        if (string.IsNullOrEmpty(data.Prefab))
        {
            data.Prefab = null;
            // Seems pointless, but unet refuses to have null strings! Really annoying when null is a perfectly valid value!
        }

        World.Instance.TileMap.GetLayer(data.Layer).RecievedTileChange(data);
    }
예제 #2
0
    public void RecievedTileChange(Msg_SendTile data)
    {
        // Called on clients when a tile has been set.

        // Confirm to the pending placement system...
        PendingBuildingManager.Instance.ConfirmPlaced(PendingBuildingManager.MakeID(data.X, data.Y));

        // If we are a host, just stop. Tile has already been set.
        if (isServer)
        {
            return;
        }

        // Check if is in bounds.
        if (!InLayerBounds(data.X, data.Y))
        {
            Debug.LogError("Why did the server send me coordinates out of bounds?!?! (" + data.X + ", " + data.Y + ")");
            return;
        }

        // Check if it is loaded. If it is not ignore this. TODO if it is loading, make it be applied once loaded.
        if (IsChunkLoaded(GetChunkIndexFromTileCoords(data.X, data.Y)))
        {
            // Place tile in position.
            BaseTile oldTile = Tiles[data.X][data.Y];

            BaseTile tile = data.Prefab == null ? null : BaseTile.GetTile(data.Prefab);

            Chunk c = GetChunkFromIndex(GetChunkIndexFromTileCoords(data.X, data.Y));

            if (oldTile != null)
            {
                TileRemoved(data.X, data.Y, oldTile, c);
            }

            // Apply tile.
            Tiles[data.X][data.Y] = tile;

            // Update tiles sourrounding and update physics bodies.
            TilePlaced(data.X, data.Y, tile, c);
        }
    }