示例#1
0
 public override void OnHideRegion(int regionX, int regionY)
 {
     ClearRegionRenderer(regionX, regionY);
     triangles.ClearRegion(regionX, regionY);
 }
示例#2
0
        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);
            }
        }