Example #1
0
        public override void OnShowRegion(int regionX, int regionY)
        {
            FiniteGrid             region         = grid.GetRegion(regionX, regionY);
            FiniteComponentGrid    regionTriangle = triangles.GetRegion(regionX, regionY);
            PositionRegionRenderer renderer       = GetRegionRenderer(regionX, regionY);

            ClearRenderers();
            renderer.mesh.PrepareUV();

            int bx = regionX * Grid.REGION_SIZE;
            int by = regionY * Grid.REGION_SIZE;

            for (int i = 0; i < Grid.REGION_SIZE; i++)
            {
                for (int j = 0; j < Grid.REGION_SIZE; j++)
                {
                    Tile tile = region.Get(i, j);

                    if (tile != null && tile.id != 0)
                    {
                        if (regionTriangle == null)
                        {
                            _OnSet(null, renderer, i + bx, j + by, tile);
                        }
                        else
                        {
                            _OnSet(regionTriangle.Get(i, j) as GridTriangle, renderer, i + bx, j + by, tile);
                        }
                    }
                }
            }

            renderer.mesh.ApplyUV();
            ApplyRenderers();
        }
Example #2
0
        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();
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Called when a square of tile's information is set.
        /// </summary>
        /// <param name="x">The bottom left x coordinate of the square.</param>
        /// <param name="y">The bottom left y coordinate of the square.</param>
        /// <param name="width">The width of the square.</param>
        /// <param name="height">The height of the square.</param>
        public virtual 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)
                    {
                        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);

                        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)
                                {
                                    OnSet(i, j, tile);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Called when a region is presented.
        /// </summary>
        /// <param name="regionX">The X coordinate of the region.</param>
        /// <param name="regionY">The Y coordinate of the region.</param>
        public virtual void OnShowRegion(int regionX, int regionY)
        {
            FiniteGrid region = grid.GetRegion(regionX, regionY);

            int startX = regionX * Grid.REGION_SIZE;
            int endX   = (regionX + 1) * Grid.REGION_SIZE;
            int startY = regionY * Grid.REGION_SIZE;
            int endY   = (regionY + 1) * Grid.REGION_SIZE;

            for (int i = startX; i < endX; i++)
            {
                for (int j = startY; j < endY; j++)
                {
                    Tile tile = region.Get(i - startX, j - startY);

                    if (tile != null)
                    {
                        OnSet(i, j, tile);
                    }
                }
            }
        }
Example #5
0
        public override void OnShowRegion(int regionX, int regionY)
        {
            int bx = regionX * Grid.REGION_SIZE;
            int by = regionY * Grid.REGION_SIZE;

            FiniteGrid          region           = grid.GetRegion(regionX, regionY);
            FiniteComponentGrid regionComponents = components.GetOrCreateRegion(regionX, regionY);

            for (int y = 0; y < Grid.REGION_SIZE; y++)
            {
                GridColliderPart currentWrapper = components.Get(bx - 1, y + by) as GridColliderPart;

                for (int x = 0; x < Grid.REGION_SIZE - 1; x++)
                {
                    Tile tile = region.Get(x, y);

                    if (tile != null)
                    {
                        TileInfo info = grid.atlas [tile.id];

                        if (currentWrapper != null && currentWrapper.Compatible(info) && !info.isVertical && !currentWrapper.isVertical)
                        {
                            currentWrapper.width++;
                        }
                        else
                        {
                            if (currentWrapper != null)
                            {
                                currentWrapper.ResetSizeAndPosition(grid);
                            }

                            if (info.shape != TileShape.EMPTY && !info.isVertical)
                            {
                                currentWrapper = GridColliderPart.CreateColliderPart(containerGO, grid, info, bx + x, by + y, 1, 1);
                            }
                            else
                            {
                                currentWrapper = null;
                            }
                        }

                        regionComponents.Set(x, y, currentWrapper);
                    }
                    else
                    {
                        if (currentWrapper != null)
                        {
                            currentWrapper.ResetSizeAndPosition(grid);
                            currentWrapper = null;
                        }

                        regionComponents.Set(x, y, null);
                    }
                }

                if (currentWrapper != null)
                {
                    currentWrapper.ResetSizeAndPosition(grid);
                }

                Tile edgeTile = region.Get(Grid.REGION_SIZE - 1, y);
                if (edgeTile != null)
                {
                    OnSet(bx + Grid.REGION_SIZE - 1, by + y, edgeTile);
                }
            }

            for (int x = 0; x < Grid.REGION_SIZE; x++)
            {
                GridColliderPart currentWrapper = components.Get(bx + x, by - 1) as GridColliderPart;

                for (int y = 0; y < Grid.REGION_SIZE - 1; y++)
                {
                    Tile tile = region.Get(x, y);

                    if (tile != null)
                    {
                        TileInfo info = grid.atlas [tile.id];

                        if (currentWrapper != null && currentWrapper.Compatible(info) && info.isVertical && currentWrapper.isVertical)
                        {
                            currentWrapper.height++;

                            regionComponents.Set(x, y, currentWrapper);
                        }
                        else
                        {
                            if (currentWrapper != null)
                            {
                                currentWrapper.ResetSizeAndPosition(grid);
                            }

                            if (info.shape != TileShape.EMPTY && info.isVertical)
                            {
                                currentWrapper = GridColliderPart.CreateColliderPart(containerGO, grid, info, bx + x, by + y, 1, 1);

                                regionComponents.Set(x, y, currentWrapper);
                            }
                            else
                            {
                                currentWrapper = null;
                            }
                        }
                    }
                    else
                    {
                        if (currentWrapper != null)
                        {
                            currentWrapper.ResetSizeAndPosition(grid);
                            currentWrapper = null;
                        }
                    }
                }

                if (currentWrapper != null)
                {
                    currentWrapper.ResetSizeAndPosition(grid);
                }

                Tile edgeTile = region.Get(x, Grid.REGION_SIZE - 1);
                if (edgeTile != null && grid.atlas[edgeTile.id].isVertical)
                {
                    OnSet(bx + x, by + Grid.REGION_SIZE - 1, edgeTile);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Gets the tile at the specified coordinates and the containing region.
        /// </summary>
        /// <param name="x">The x tile coordinate.</param>
        /// <param name="y">The y tile coordinate.</param>
        public Tile Get(int x, int y, out FiniteGrid region)
        {
            region = GetContainingRegion(x, y);

            return(region != null?region.Get(x - region.regionX *_regionSize, y - region.regionY *_regionSize) : null);
        }