public override void OnSet(int x, int y, int width, int height) { int minRegionX = Mathf.FloorToInt(x / (float)Grid.REGION_SIZE); int minRegionY = Mathf.FloorToInt(y / (float)Grid.REGION_SIZE); int maxRegionX = Mathf.FloorToInt((x + width) / (float)Grid.REGION_SIZE); int maxRegionY = Mathf.FloorToInt((y + height) / (float)Grid.REGION_SIZE); for (int regionX = minRegionX; regionX <= maxRegionX; regionX++) { for (int regionY = minRegionY; regionY <= maxRegionY; regionY++) { FiniteGrid region = grid.GetRegion(regionX, regionY); if (region.presented) { PositionRegionRenderer renderer = GetRegionRenderer(regionX, regionY); FiniteComponentGrid triangleRegion = triangles.GetRegion(regionX, regionY); int startX = regionX * Grid.REGION_SIZE; int startY = regionY * Grid.REGION_SIZE; int minX = Mathf.Max(x, startX); int minY = Mathf.Max(y, startY); int maxX = Mathf.Min(x + width, (regionX + 1) * Grid.REGION_SIZE); int maxY = Mathf.Min(y + height, (regionY + 1) * Grid.REGION_SIZE); renderer.mesh.PrepareUV(); for (int i = minX; i < maxX; i++) { for (int j = minY; j < maxY; j++) { Tile tile = region.Get(i - startX, j - startY); if (tile != null) { if (triangleRegion != null) { _OnSet(triangleRegion.Get(x - startX, y - startY) as GridTriangle, renderer, i, j, tile); } else { _OnSet(null, renderer, i, j, tile); } } } } renderer.mesh.ApplyUV(); } } } }
/// <summary> /// Wrapper for the underlying InfiniteComponentGrid GetRegion method. /// </summary> /// <returns>The region.</returns> /// <param name="regionX">The X region coordinate.</param> /// <param name="regionY">The Y region coordinate.</param> public FiniteComponentGrid GetRegion(int regionX, int regionY) { return(componentGrid.GetRegion(regionX, regionY)); }
public override void OnHideRegion(int X, int Y) { int bx = X * Grid.REGION_SIZE; int by = Y * Grid.REGION_SIZE; FiniteComponentGrid regionComponents = components.GetRegion(X, Y); if (regionComponents != null) { for (int i = 0; i < Grid.REGION_SIZE; i++) { for (int j = 0; j < Grid.REGION_SIZE; j++) { GridColliderPart wrapper = regionComponents.Get(i, j) as GridColliderPart; if (wrapper != null) { if (wrapper.bottomLeftX >= bx && wrapper.bottomLeftX + wrapper.width <= bx + Grid.REGION_SIZE && wrapper.bottomLeftY >= by && wrapper.bottomLeftY + wrapper.height <= by + Grid.REGION_SIZE) { if (Application.isPlaying) { Destroy(wrapper.gameObject); } else { DestroyImmediate(wrapper.gameObject); } } else if (wrapper.isVertical) { if (wrapper.bottomLeftY < by) { int topY = wrapper.bottomLeftY + wrapper.height; wrapper.SetSize(1, by - wrapper.bottomLeftY); wrapper.ResetSizeAndPosition(grid); if (topY > by + Grid.REGION_SIZE) { GridColliderPart topWrapper = GridColliderPart.CreateColliderPart( containerGO, grid, grid.atlas [wrapper.id], wrapper.bottomLeftX, by + Grid.REGION_SIZE, 1, topY - (by + Grid.REGION_SIZE) ); topWrapper.ResetSizeAndPosition(grid); for (int k = topWrapper.bottomLeftY; k < topWrapper.bottomLeftY + topWrapper.height; k++) { components.Set(topWrapper.bottomLeftX, k, topWrapper); } } } else if (wrapper.bottomLeftY + wrapper.height > by + Grid.REGION_SIZE) { wrapper.SetSize(1, wrapper.bottomLeftY + wrapper.height - (by + Grid.REGION_SIZE)); wrapper.bottomLeftY = by + Grid.REGION_SIZE; wrapper.ResetSizeAndPosition(grid); } } else if (!wrapper.isVertical) { if (wrapper.bottomLeftX < bx) { int rightX = wrapper.bottomLeftX + wrapper.width; wrapper.SetSize(bx - wrapper.bottomLeftX, 1); wrapper.ResetSizeAndPosition(grid); if (rightX > bx + Grid.REGION_SIZE) { GridColliderPart rightWrapper = GridColliderPart.CreateColliderPart( containerGO, grid, grid.atlas [wrapper.id], bx + Grid.REGION_SIZE, wrapper.bottomLeftY, rightX - (bx + Grid.REGION_SIZE), 1 ); rightWrapper.ResetSizeAndPosition(grid); for (int k = rightWrapper.bottomLeftX; k < rightWrapper.bottomLeftX + rightWrapper.width; k++) { components.Set(k, rightWrapper.bottomLeftY, rightWrapper); } } } else if (wrapper.bottomLeftX + wrapper.width > bx + Grid.REGION_SIZE) { wrapper.SetSize(wrapper.bottomLeftX + wrapper.width - (bx + Grid.REGION_SIZE), 1); wrapper.bottomLeftX = bx + Grid.REGION_SIZE; wrapper.ResetSizeAndPosition(grid); } } } } } components.ClearRegion(X, Y); } }