Example #1
0
        void Start()
        {
            Debug.Log("==读取GamePlay的Texture");
            Gfx.Game        = Atlas.FromAtlas(Path.Combine("Graphics", "Atlases", "Gameplay"), Atlas.AtlasDataFormat.Packer);
            foregroundTiles = new Tiles(Path.Combine(Util.GAME_PATH_CONTENT, Path.Combine("Graphics", "ForegroundTiles.xml")));
            backgroundTiles = new Tiles(Path.Combine(Util.GAME_PATH_CONTENT, Path.Combine("Graphics", "BackgroundTiles.xml")));
            AreaData.Load();
            Stage stage = new Stage(0, AreaMode.Normal);

            stage.Load();

            //生成地图数据
            Autotiler.Behaviour fgBehaviour = new Autotiler.Behaviour()
            {
                EdgesExtend             = true,
                EdgesIgnoreOutOfLevel   = false,
                PaddingIgnoreOutOfLevel = true
            };
            Autotiler.Behaviour bgBehaviour = new Autotiler.Behaviour()
            {
                EdgesExtend             = true,
                EdgesIgnoreOutOfLevel   = false,
                PaddingIgnoreOutOfLevel = false
            };
            VirtualMap <char> foregroundData = stage.ForegroundData;

            this.colliderGrid = new ColliderGrid(foregroundData.Columns, foregroundData.Rows, 8f, 8f);
            for (int x = 0; x < foregroundData.Columns; x += 50)
            {
                for (int y = 0; y < foregroundData.Rows; y += 50)
                {
                    if (foregroundData.AnyInSegmentAtTile(x, y))
                    {
                        int index1 = x;
                        for (int index2 = Math.Min(index1 + 50, foregroundData.Columns); index1 < index2; ++index1)
                        {
                            int index3 = y;
                            for (int index4 = Math.Min(index3 + 50, foregroundData.Rows); index3 < index4; ++index3)
                            {
                                if (foregroundData[index1, index3] != '0')
                                {
                                    this.colliderGrid[index1, index3] = true;
                                }
                                else
                                {
                                    this.colliderGrid[index1, index3] = false;
                                }
                            }
                        }
                    }
                }
            }
            //VirtualMap<char> backgroundData = stage.BackgroundData;
            foregroundTiles.GenerateTiles(this.fgTilemap, foregroundData, 0, 0, foregroundData.Columns, foregroundData.Rows, false, '0', fgBehaviour, colliderGrid);
            //bgTileDictionary.GenerateTiles(this.bgTilemap, backgroundData, 0, 0, backgroundData.Columns, backgroundData.Rows, false, '0', bgBehaviour);
        }
Example #2
0
        public void GenerateTiles(Tilemap tilemap, VirtualMap <char> foregroundData, int startX, int startY, int tilesX, int tilesY, bool forceSolid, char forceID, Autotiler.Behaviour behaviour, ColliderGrid colliderGrid)
        {
            Rectangle forceFill = Rectangle.Empty;

            if (forceSolid)
            {
                forceFill = new Rectangle(startX, startY, tilesX, tilesY);
            }
            if (foregroundData != null)
            {
                for (int x1 = startX; x1 < startX + tilesX; x1 += 50)
                {
                    for (int y1 = startY; y1 < startY + tilesY; y1 += 50)
                    {
                        if (!foregroundData.AnyInSegmentAtTile(x1, y1))
                        {
                            y1 = y1 / 50 * 50;
                        }
                        else
                        {
                            int x2 = x1;
                            for (int index1 = Math.Min(x1 + 50, startX + tilesX); x2 < index1; ++x2)
                            {
                                int y2 = y1;
                                for (int index2 = Math.Min(y1 + 50, startY + tilesY); y2 < index2; ++y2)
                                {
                                    Autotiler.Tiles tiles = this.TileHandler(foregroundData, x2, y2, forceFill, forceID, behaviour);
                                    if (tiles != null)
                                    {
                                        SolidTile tile = ScriptableObject.CreateInstance <SolidTile>();
                                        tile.SetTile(tiles);
                                        tile.colliderType = colliderGrid[x2 - startX, y2 - startY]? Tile.ColliderType.Grid:Tile.ColliderType.None;
                                        tilemap.SetTile(new Vector3Int(x2 - startX, -(y2 - startY), 0), tile);
                                        //this.tilemap.SetTile(new Vector3Int(0, 0, 0), tile);
                                        //return;
                                    }
                                    //if (tiles != null)
                                    //{
                                    //    tileGrid.Tiles[x2 - startX, y2 - startY] = RandomUtil.Random.Choose<MTexture>(tiles.Textures);
                                    //    //if (tiles.HasOverlays)
                                    //    //    animatedTiles.Set(x2 - startX, y2 - startY, RandomUtil.Random.Choose<string>(tiles.OverlapSprites), 1f, 1f);
                                    //}
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                for (int x = startX; x < startX + tilesX; ++x)
                {
                    for (int y = startY; y < startY + tilesY; ++y)
                    {
                        Autotiler.Tiles tiles = this.TileHandler((VirtualMap <char>)null, x, y, forceFill, forceID, behaviour);
                        if (tiles != null)
                        {
                            SolidTile tile = ScriptableObject.CreateInstance <SolidTile>();
                            tile.SetTile(tiles);
                            tile.colliderType = colliderGrid[x - startX, y - startY] ? Tile.ColliderType.Grid : Tile.ColliderType.None;
                            tilemap.SetTile(new Vector3Int(x - startX, -(y - startY), 0), tile);
                            //this.tilemap.SetTile(new Vector3Int(0, 0, 0), tile);
                            //return;
                        }
                        //if (tiles != null)
                        //{
                        //    tileGrid.Tiles[x - startX, y - startY] = RandomUtil.Random.Choose<MTexture>(tiles.Textures);
                        //    if (tiles.HasOverlays)
                        //        animatedTiles.Set(x - startX, y - startY, RandomUtil.Random.Choose<string>(tiles.OverlapSprites), 1f, 1f);
                        //}
                    }
                }
            }
        }