Ejemplo n.º 1
0
        public override void OnSet(int x, int y, Tile tile)
        {
            PositionRegionRenderer renderer = GetContainingRegionRenderer(x, y);
            GridTriangle           triangle = triangles.Get(x, y) as GridTriangle;

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

            _OnSet(triangle, renderer, x, y, tile);

            renderer.mesh.ApplyUV();
            ApplyRenderers();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Determines whether there is a tileGO at the specified position.
 /// </summary>
 /// <param name="x">The x tile coordinate.</param>
 /// <param name="y">The y tile coordinate.</param>
 public bool HasTileGO(int x, int y)
 {
     return(componentGrid.Get(x, y) != null);
 }
Ejemplo n.º 3
0
        public override void OnSet(int x, int y, Tile tile)
        {
            // clear previous
            ClearTile(x, y);

            TileInfo info = grid.atlas [tile.id];

            // add new
            if (info.shape != TileShape.EMPTY)
            {
                GridColliderPart wrapper = null;

                // HORIZONTAL GROWTH
                if (info.shape != TileShape.LEFT_ONEWAY && info.shape != TileShape.RIGHT_ONEWAY)
                {
                    bool expanded = false;

                    GridColliderPart left = components.Get(x - 1, y) as GridColliderPart;
                    if (left != null && left.Compatible(info) && !left.isVertical && !info.isVertical)
                    {
                        left.SetSize(left.width + 1, 1);
                        wrapper = left;

                        components.Set(x, y, left);

                        expanded = true;
                    }

                    GridColliderPart right = components.Get(x + 1, y) as GridColliderPart;
                    if (right != null && right.Compatible(info) && !right.isVertical && !info.isVertical)
                    {
                        if (!expanded)
                        {
                            right.bottomLeftX -= 1;
                            right.SetSize(right.width + 1, 1);
                            wrapper = right;

                            components.Set(x, y, right);

                            wrapper.ResetSizeAndPosition(grid);
                            return;
                        }
                        else
                        {
                            left.SetSize(left.width + right.width, 1);

                            for (int i = right.bottomLeftX; i < right.bottomLeftX + right.width; i++)
                            {
                                components.Set(i, y, left);
                            }

                            if (Application.isPlaying)
                            {
                                Destroy(right.gameObject);
                            }
                            else
                            {
                                DestroyImmediate(right.gameObject);
                            }

                            wrapper.ResetSizeAndPosition(grid);
                            return;
                        }
                    }

                    if (expanded)
                    {
                        wrapper.ResetSizeAndPosition(grid);
                        return;
                    }
                }

                // VERTICAL GROWTH
                if (info.shape != TileShape.FULL && info.shape != TileShape.UP_ONEWAY && info.shape != TileShape.DOWN_ONEWAY)
                {
                    bool expanded = false;

                    GridColliderPart down = components.Get(x, y - 1) as GridColliderPart;
                    if (down != null && down.Compatible(info) && down.isVertical && info.isVertical)
                    {
                        down.SetSize(1, down.height + 1);
                        wrapper = down;

                        components.Set(x, y, down);

                        expanded = true;
                    }

                    GridColliderPart up = components.Get(x, y + 1) as GridColliderPart;

                    if (up != null && up.Compatible(info) && up.isVertical && info.isVertical)
                    {
                        if (!expanded)
                        {
                            up.bottomLeftY -= 1;
                            up.SetSize(1, up.height + 1);
                            wrapper = up;

                            components.Set(x, y, up);

                            wrapper.ResetSizeAndPosition(grid);
                            return;
                        }
                        else
                        {
                            down.SetSize(1, down.height + up.height);

                            for (int i = up.bottomLeftY; i < up.bottomLeftY + up.width; i++)
                            {
                                components.Set(i, y, down);
                            }

                            if (Application.isPlaying)
                            {
                                Destroy(up.gameObject);
                            }
                            else
                            {
                                DestroyImmediate(up.gameObject);
                            }

                            wrapper.ResetSizeAndPosition(grid);
                            return;
                        }
                    }

                    if (expanded)
                    {
                        wrapper.ResetSizeAndPosition(grid);
                        return;
                    }
                }

                // NO EXPANSE, CREATE NEW
                wrapper = GridColliderPart.CreateColliderPart(containerGO, grid, info, x, y, 1, 1);
                components.Set(x, y, wrapper);

                wrapper.ResetSizeAndPosition(grid);
            }
        }