Esempio n. 1
0
        public void SetTile(int chunkX, int chunkY, int x, int y, TileString blockID, MapLayers layer,
                            bool callEvent = true, bool refreshSurronding = true, bool ignoreSameTile = false)
        {
            TileBase        tb;
            short           chunkBlockID = 0;
            ChunkDefinition chun         = map.chunks[chunkX, chunkY];
            int             X            = x - (chunkX * chunkWidth);
            int             Y            = y - (chunkY * chunkHeight);

            if (ignoreSameTile)
            {
                if (chun.GetTile(X, Y, layer) == blockID)
                {
                    return;
                }
            }
            //Update pallete
            if (!ReferenceEquals(blockID, null))
            {
                if (!chun.chunkPallete.Contains(blockID))
                {
                    chun.chunkPallete.Add(blockID);
                    chunkBlockID = (short)(chun.chunkPallete.Count);
                }
                else
                {
                    chunkBlockID = (short)(chun.chunkPallete.IndexOf(blockID) + 1);
                }
            }
            //Place block
            if (ReferenceEquals(chun.tileLayers[layer][X, Y], null))
            {
                chun.tileLayers[layer][X, Y] = new TileDefinition();
            }
            chun.tileLayers[layer][X, Y].tile = chunkBlockID;
            tb = null;
            if (refreshSurronding)
            {
                if (!ReferenceEquals(blockID, null))
                {
                    tb = MapManager.instance.GetTileFromCollection(chun.chunkPallete[chunkBlockID - 1]);
                    tb.RefreshTile(new Vector2Int(x, y), layer);
                }
                RefreshTilesAround(new Vector2Int(x, y), layer);
            }
            if (callEvent)
            {
                OnPlaceTile(new Vector2Int(chunkX, chunkY), new Vector2Int(X, Y), tb, layer);
            }
        }
Esempio n. 2
0
        public void SetBitmask(int chunkX, int chunkY, int x, int y, byte mask, MapLayers layer, bool callEvent = true)
        {
            ChunkDefinition chun = map.chunks[chunkX, chunkY];

            map.chunks[chunkX, chunkY].tileLayers[layer][x, y].bitmask = mask;
        }