Example #1
0
            //Return only 1 TileData has change
            public TileData DoAction(AutoTileMap _autoTileMap)
            {
                TileData onlyChange = null;
                //Check is ok with Size Large
                {
                    var brush   = aTileData[0];
                    int tile_id = brush.Tile_id;
                    if (_autoTileMap.Tileset.IsExitSlot(tile_id))
                    {
                        var slot = _autoTileMap.Tileset.GetSlot(tile_id);
                        if (slot.Size.x > 1 || slot.Size.y > 1)
                        {
                            if (brush.Tile_x < 0)
                            {
                                Debug.Log("Out Left Map");
                                return(onlyChange);
                            }
                            if (brush.Tile_y < 0)
                            {
                                Debug.Log("Out Top Map");
                                return(onlyChange);
                            }
                            if (brush.Tile_x + slot.Size.x > (_autoTileMap.MapTileWidth))
                            {
                                Debug.Log("Out Right Map");
                                return(onlyChange);
                            }
                            if (brush.Tile_y + slot.Size.x > (_autoTileMap.MapTileWidth))
                            {
                                Debug.Log("Out Bot Map");
                                return(onlyChange);
                            }
                            //Check all tile will be brush don't have other Size Large
                            for (int x = brush.Tile_x; x < brush.Tile_x + slot.Size.x; x++)
                            {
                                for (int y = brush.Tile_y; y < brush.Tile_y + slot.Size.y; y++)
                                {
                                    int idCheck = _autoTileMap.GetAutoTile(x, y, brush.Tile_layer).Id;
                                    if (_autoTileMap.Tileset.IsExitSlot(idCheck))
                                    {
                                        var slotCheck = _autoTileMap.Tileset.GetSlot(idCheck);
                                        if (slotCheck.Size.x > 1 || slotCheck.Size.y > 1)
                                        {
                                            Debug.Log("Have other Size Large");
                                            return(onlyChange);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //
                int  tileMinX       = _autoTileMap.MapTileWidth - 1;
                int  tileMinY       = _autoTileMap.MapTileHeight - 1;
                int  tileMaxX       = 0;
                int  tileMaxY       = 0;
                bool HasChangedTile = false;

                for (int i = 0; i < aTileData.Count; ++i)
                {
                    TileData tileData = aTileData[i];
                    // save prev tile type for undo action
                    // tileData.Tile_type_prev = _autoTileMap.GetAutoTile( tileData.Tile_x, tileData.Tile_y, tileData.Tile_layer ).Id;
                    // if(!_autoTileMap.Tileset.IsExitSlot(tileData.Tile_id)){
                    //  continue;
                    // }
                    int idCheck = _autoTileMap.GetAutoTile(tileData.Tile_x, tileData.Tile_y, tileData.Tile_layer).Id;
                    if (_autoTileMap.Tileset.IsExitSlot(idCheck))
                    {
                        var slotCheck = _autoTileMap.Tileset.GetSlot(idCheck);
                        if (!slotCheck.IsCanCopyWhenDraw)
                        {
                            continue;
                        }
                    }
                    if (tileData.Tile_id >= -1)
                    {
                        bool isUpdate = _autoTileMap.SetAutoTile(tileData.Tile_x, tileData.Tile_y, tileData.Tile_id, tileData.Tile_layer, true);
                        if (isUpdate)
                        {
                            HasChangedTile = true;
                        }
                    }
                    if (tileData.Tile_high >= 0)
                    {
                        bool isUpdate = _autoTileMap.MapSelect.SetHighRef(tileData.Tile_x, tileData.Tile_y, tileData.Tile_high);
                        if (isUpdate)
                        {
                            HasChangedTile = true;
                            int tile_layer_high = (int)eSlotAonTypeLayer.Trigger;
                            _autoTileMap.RefreshTile(tileData.Tile_x, tileData.Tile_y, tile_layer_high);
                        }
                    }
                    if (aTileData.Count == 1)
                    {
                        onlyChange = tileData;
                    }

                    // if(slot.Size.x == 1 && slot.Size.y == 1){

                    // }else{
                    //  // _autoTileMap.SetAutoTile( tileData.Tile_x, tileData.Tile_y, tileData.Tile_id, tileData.Tile_layer );
                    //  for(int x = tileData.Tile_x; x < tileData.Tile_x + slot.Size.x; x++){
                    //      for(int y = tileData.Tile_y; y < tileData.Tile_y + slot.Size.y; y++){
                    //          // _autoTileMap.SetAutoTile( x, y, -2, tileData.Tile_layer );
                    //          _autoTileMap.SetAutoTile( x, y, tileData.Tile_id, tileData.Tile_layer );
                    //      }
                    //  }
                    // }
                    if (HasChangedTile)
                    {
                        tileMinX = Mathf.Min(tileMinX, tileData.Tile_x);
                        tileMinY = Mathf.Min(tileMinY, tileData.Tile_y);
                        tileMaxX = Mathf.Max(tileMaxX, tileData.Tile_x);
                        tileMaxY = Mathf.Max(tileMaxY, tileData.Tile_y);
                    }
                }
                if (HasChangedTile)
                {
                    // if (_autoTileMap.BrushGizmo.IsRefreshMinimapEnabled)
                    {
                        _autoTileMap.RefreshMinimapTexture(tileMinX, tileMinY, (tileMaxX - tileMinX) + 1, (tileMaxY - tileMinY) + 1);
                    }
                    _autoTileMap.UpdateChunks();
                }
                return(onlyChange);
            }