public bool InvalidateChunkAt(int grid_x, int grid_y, bool is_invalidate_mesh = true, bool is_invalidate_mesh_collider = true) { TileMapChunk tileMapChunk = GetOrCreateTileMapChunk(grid_x, grid_y); if (tileMapChunk != null) { tileMapChunk.InvalidateMesh(); tileMapChunk.InvalidateMeshCollider(); return(true); } return(false); }
private void BuildTileMapChunkCacheDict() { tileMapChunk_cache_dict.Clear(); for (int i = 0; i < transform.childCount; ++i) { TileMapChunk tileMapChunk = transform.GetChild(i).GetComponent <TileMapChunk>(); if (tileMapChunk) { Vector2Int chunk_xy = tileMapChunk.GetChunkXY(); uint key = GetTileMapChunkKey(chunk_xy); tileMapChunk_cache_dict[key] = tileMapChunk; } } }
private TileMapChunk GetOrCreateTileMapChunk(int world_grid_x, int world_grid_y, bool is_create_if_doesnt_exist = false) { if (tileMapChunk_cache_dict.Count == 0 && transform.childCount > 0) { BuildTileMapChunkCacheDict(); } Vector2Int chunk_xy = TileMapChunkUtil.GetChunkXY(world_grid_x, world_grid_y); TileMapChunk tileMapChunk = null; uint key = GetTileMapChunkKey(chunk_xy); tileMapChunk_cache_dict.TryGetValue(key, out tileMapChunk); if (tileMapChunk == null && is_create_if_doesnt_exist) { string chunk_name = string.Format("{0}_{1}", chunk_xy.x, chunk_xy.y); GameObject chunk_gameObject = new GameObject(chunk_name); if (is_undo_enabled) { #if UNITY_EDITOR Undo.RegisterCreatedObjectUndo(chunk_gameObject, TileMapConst.Undo_Operation_Name + name); #endif } tileMapChunk = chunk_gameObject.AddComponent <TileMapChunk>(); chunk_gameObject.transform.parent = transform; Vector2Int offset_grid_xy = TileMapChunkUtil.GetOffsetGridXY(chunk_xy); tileMapChunk.offset_grid_x = offset_grid_xy.x; tileMapChunk.offset_grid_y = offset_grid_xy.y; chunk_gameObject.transform.localPosition = new Vector2(tileMapChunk.offset_grid_x * cell_size.x, tileMapChunk.offset_grid_y * cell_size.y); chunk_gameObject.transform.localRotation = Quaternion.identity; chunk_gameObject.transform.localScale = Vector3.one; chunk_gameObject.hideFlags = gameObject.hideFlags | HideFlags.HideInHierarchy; if (Application.isPlaying) { tileMapChunk.Reset(); } tileMapChunk.parent_tileMap = this; tileMapChunk.SetDimensions(TileMapConst.TileMapChunk_Size, TileMapConst.TileMapChunk_Size); tileMapChunk.SetSharedMaterial(material); tileMapChunk.SortingLayerID = sortingLayer; tileMapChunk.OrderInLayer = orderInLayer; tileMapChunk.UpdateRendererProperties(); tileMapChunk_cache_dict[key] = tileMapChunk; } return(tileMapChunk); }
public uint GetTileData(int world_grid_x, int world_grid_y) { TileMapChunk tileMapChunk = GetOrCreateTileMapChunk(world_grid_x, world_grid_y); if (tileMapChunk == null) { return(TileSetConst.TileData_Empty); } else { Vector2Int local_grid_xy = TileMapChunkUtil.GetLocalGridXYOfChunk(world_grid_x, world_grid_y); int local_grid_x = local_grid_xy.x; int local_grid_y = local_grid_xy.y; if (world_grid_x < 0) { local_grid_x = TileMapConst.TileMapChunk_Size - 1 - local_grid_x; } if (world_grid_y < 0) { local_grid_y = TileMapConst.TileMapChunk_Size - 1 - local_grid_y; } return(tileMapChunk.GetTileData(local_grid_x, local_grid_y)); } }
public virtual uint OnPaint(TileMapChunk chunk, int chunkGx, int chunkGy, uint tileData) { return(tileData); }
public virtual void OnErase(TileMapChunk chunk, int chunkGx, int chunkGy, uint tileData, int brushId) { ; }