Ejemplo n.º 1
0
        public void RefreshTile(Vector2Int position, MapLayers layer)
        {
            TileString t = GetTile(position.x, position.y, layer);

            if (!ReferenceEquals(t, null))
            {
                TileBase tb = GetTileFromCollection(t);
                tb.RefreshTile(position, layer);
            }
        }
Ejemplo n.º 2
0
        public void SetTile(int x, int y, TileString blockID, MapLayers layer,
                            bool callEvent = true, bool refreshSurronding = true, bool ignoreSameTile = false)
        {
            if (x < 0 || y < 0)
            {
                return;
            }
            int cX = x / chunkWidth;
            int cY = y / chunkHeight;

            SetTile(cX, cY, x, y, blockID, layer, callEvent, refreshSurronding, ignoreSameTile);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
 public TileBase GetTileFromCollection(TileString ts)
 {
     return(tCollections.GetTile(ts));
 }
Ejemplo n.º 5
0
 public TileBase GetTile(TileString id)
 {
     return(colls[id.nspace]
            .tls[id.tile]);
 }