Пример #1
0
    private CombinedMeshLayer SpawnWallLayer(TmxLayer layer, int mapHeight)
    {
        GameObject        wallPrefab = gameConfig.WallPrefab;
        CombinedMeshLayer meshLayer  = Instantiate(gameConfig.CombinedMeshLayerPrefab);

        meshLayer.Initialize(layer.Name, mapHeight);
        Transform wallContainer = GetContainer("Walls");

        meshLayer.transform.SetParent(wallContainer);
        foreach (TmxLayerTile tile in layer.Tiles)
        {
            if (tile.Gid != 0)
            {
                GameObject wall = Instantiate(wallPrefab);
                int        x    = tile.X;
                int        y    = tile.Y;
                wall.transform.position = new Vector2(x, y);
                MeshFilter meshFilter = wall.GetComponent <MeshFilter>();
                if (meshFilter != null)
                {
                    meshLayer.Add(meshFilter);
                }
                wall.transform.SetParent(GetContainer("DudWalls"));
            }
        }
        meshLayer.Build();
        return(meshLayer);
    }
Пример #2
0
    private void DrawLayers(TmxMap map)
    {
        int mapHeight = map.Height;

        foreach (TmxLayer layer in map.Layers)
        {
            string layerType = layer.Name;
            if (layerType == "Ground")
            {
                MeshTileMap meshTileMap = Instantiate(gameConfig.MeshTileMapPrefab);
                meshTileMap.Init(layer, map);
            }
            else if (layerType == "Wall")
            {
                CombinedMeshLayer combinedMeshLayer = SpawnWallLayer(layer, mapHeight);
            }
        }
    }