static int CompressBounds(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); UnityEngine.Tilemaps.Tilemap obj = (UnityEngine.Tilemaps.Tilemap)ToLua.CheckObject(L, 1, typeof(UnityEngine.Tilemaps.Tilemap)); obj.CompressBounds(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// 国战创建一个地图层 /// </summary> /// <param name="parent">父Transform节点</param> /// <param name="lJMapLayer">层的数据对象</param> /// <param name="baseTileConfig">图块对象</param> /// <param name="mapDefaultTilemapMat">地图所用的材质球</param> /// <param name="renderMode">0 Chunk 1 Individual </param> /// <returns>返回一个tilemap</returns> public static UnityEngine.Tilemaps.Tilemap CreateLayerByNation(Transform parent, LJTilemaps.LJMapLayer lJMapLayer, LJTilemaps.LJBaseTileConfig baseTileConfig, Material mapDefaultTilemapMat, int renderMode) { GameObject layerGameObj = new GameObject(lJMapLayer.layerName); UnityEngine.Tilemaps.Tilemap tilemap = layerGameObj.AddComponent <UnityEngine.Tilemaps.Tilemap>(); UnityEngine.Tilemaps.TilemapRenderer tilemapRenderer = layerGameObj.AddComponent <UnityEngine.Tilemaps.TilemapRenderer>(); Transform layerTran = layerGameObj.transform; layerTran.SetParent(parent); layerTran.position = lJMapLayer.worldPosition; tilemapRenderer.mode = (UnityEngine.Tilemaps.TilemapRenderer.Mode)renderMode; //tilemapRenderer.mode = UnityEngine.Tilemaps.TilemapRenderer.Mode.Chunk;//合并DC模式 0 //tilemapRenderer.mode = UnityEngine.Tilemaps.TilemapRenderer.Mode.Individual;// 测试模式 1 tilemapRenderer.sortingOrder = lJMapLayer.orderInLayer; tilemapRenderer.sortingLayerID = lJMapLayer.sortingLayer; tilemap.origin = lJMapLayer.origin; tilemap.size = lJMapLayer.size; tilemap.orientation = lJMapLayer.orientation; tilemap.orientationMatrix = lJMapLayer.orientationMatrix; if (mapDefaultTilemapMat != null) { tilemapRenderer.sharedMaterial = mapDefaultTilemapMat; } if (baseTileConfig == null) { return(tilemap); } List <LJTilemaps.LJTileData> tileDatas = lJMapLayer.tileDatas; for (int i = 0, imax = tileDatas.Count; i < imax; i++) { LJTilemaps.LJTileData v = tileDatas[i]; if (v.tileId < 0) { } else { UnityEngine.Tilemaps.TileBase tileBase = baseTileConfig.GetTileBaseById(v.tileId); if (tileBase != null) { tilemap.SetTile(v.position, tileBase); } } } tilemap.CompressBounds(); return(tilemap); }
private void Awake() { Current = this; tilemap.CompressBounds(); Board = new Board(tilemap.cellBounds); foreach (var pos in Board.Bounds.allPositionsWithin) { var tile = tilemap.GetTile(pos); if (tile && tileMapping.TryGetValue(tile, out var boardTile)) { Board.SetTile(boardTile, pos.XY()); //Debug.Log($"{pos.XY()}: {boardTile}"); } } }