本文整理汇总了C#中TileMap.SetTile方法的典型用法代码示例。如果您正苦于以下问题:C# TileMap.SetTile方法的具体用法?C# TileMap.SetTile怎么用?C# TileMap.SetTile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TileMap
的用法示例。
在下文中一共展示了TileMap.SetTile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
protected override void Initialize()
{
UITexture = Content.Load<Texture2D> ("TDUserInterface.png", TextureConfiguration.Nearest);
SpriteSheet = new SpriteSheet2D (Content.Load<Texture2D> ("TDSheet.png", TextureConfiguration.Nearest), 16, 16);
TileMap = new TileMap (Vector2.Zero, 26 / 2, 18 / 2, new Vector2 (16, 16), 4);
TileMap.AddLayer ("GrassLayer", SpriteSheet);
for (int y = 0; y < TileMap.Height; y++)
for (int x = 0; x < TileMap.Width; x++)
TileMap.SetTile ("GrassLayer", x, y, new Tile { TileId = SpriteSheet.GetTileId(1, 1) });
TileMap.AddLayer ("Track", SpriteSheet);
var tiles = new int[][] {
new int[] { },
new int[] { 20, 1, 1, 2 },
new int[] { -1, -1, -1, 32, 1, 2 },
new int[] { 0, 1, 2, -1, -1, 16, -1, 16 },
new int[] { 16, -1, 16, -1, -1, 18, -1, 16 },
new int[] { 16, -1, 32, 1, 1, 34, -1, 16 },
new int[] { 16, -1, -1, -1, -1, -1, -1, 16 },
new int[] { 32, 1, 1, 1, 1, 1, 1, 34 }
};
for (int y = 0; y < tiles.Length; y++)
for (int x = 0; x < tiles[y].Length; x++)
TileMap.SetTile ("Track", x, y, new Tile { TileId = tiles[y][x] });
Font = Content.Load<Font> ("durselinvenice2015.ttf", 15f);
base.Initialize ();
}
示例2: BuildSomeShit
public void BuildSomeShit()
{
tileMap = GetComponent<TileMap>();
// temporary random tiles algorithm
int rand = 0;
for (int y = 0; y < sizeY; y++)
{
for (int x = 0; x < sizeX; x++)
{
rand = (int)UnityEngine.Random.Range(temp, 2f);
if (rand == 0)
tileMap.SetTile(x, y, new Tile(x, y, Tile.TYPE.ground));
else
tileMap.SetTile(x, y, new Tile(x, y, Tile.TYPE.air));
}
}
if (border)
{
for (int y = 0; y < sizeY; y++)
{
for (int x = 0; x < sizeX; x++)
{
if (y == 0 || y == sizeY - 1 || x == 0 || x == sizeX - 1)
tileMap.SetTile(x, y, new Tile(x, y, Tile.TYPE.ground));
}
}
}
}
示例3: LoadJson
public static TileMap LoadJson( string _fileName )
{
string jsonString = System.IO.File.ReadAllText( _fileName );
Dictionary<string,object> json = (Dictionary<string,object>)MiniJSON.Json.Deserialize( jsonString );
// Load tile bank
List<object> tilesetsJson = (List<object>)json[ "tilesets" ];
Dictionary<string,object> tilesetJson = (Dictionary<string,object>)tilesetsJson[ 0 ];
string imageFileName = (string)tilesetJson[ "image" ];
string imageFullPath = System.IO.Path.GetDirectoryName( _fileName ) + System.IO.Path.DirectorySeparatorChar + imageFileName;
//LoadBMP( imageFullPath );
PalettizedImageConfig imageConfig = new PalettizedImageConfig( imageFullPath + ".config" );
PalettizedImage imageData = PalettizedImage.LoadImage( imageFullPath, imageConfig );
TileBank tileBank = null;
if( imageData != null )
{
//
imageConfig.SetImage( imageData );
bool optimizeBank = (imageConfig.m_importAsSprite==false); // Optimize bank when we're not loading the image as a sprite (i.e. optimize when we're loading as a tile bank)
tileBank = new TileBank( imageData, optimizeBank );
}
// Create map texture
int map_tiles_w = ((int)(long)json[ "width" ]);
int map_tiles_h = ((int)(long)json[ "height" ]);
int map_pixels_w = map_tiles_w * 8;
int map_pixels_h = map_tiles_h * 8;
TileMap ret = new TileMap( map_tiles_w, map_tiles_h );
// Find each layer
List<object> layersJson = (List<object>)json[ "layers" ];
Dictionary<string,object> layerJson = (Dictionary<string,object>)layersJson[ 0 ];
List<object> layerData = (List<object>)layerJson[ "data" ];
int tile_x, tile_y;
for( tile_y=0; tile_y<map_tiles_h; tile_y++ )
{
for( tile_x=0; tile_x<map_tiles_w; tile_x++ )
{
int i = tile_y*map_tiles_w + tile_x;
int tile_id = (int)(long)layerData[i];
tile_id--;
TileInstance tileInstance = tileBank.m_allTileInstances[ tile_id ];
//
ret.SetRawTile( tile_x, tile_y, tile_id );
ret.SetTile( tile_x, tile_y, tileInstance );
}
}
return ret;
}