Exemple #1
0
    public bool IsValidGridPos()
    {
        foreach (Transform child in transform)
        {
            Vector2 v = BoxGrid.RoundVec2(child.position);

            // Not inside Border?
            if (!BoxGrid.InsideBorder(v))
            {
                return(false);
            }

            // Block in grid cell (and not part of same group)?
            if (BoxGrid.grid[(int)v.x, (int)v.y] != null &&
                BoxGrid.grid[(int)v.x, (int)v.y].parent != transform)
            {
                return(false);
            }
        }
        return(true);
    }
Exemple #2
0
    public void UpdateGrid()
    {
        // Remove old children from grid
        for (int y = 0; y < BoxGrid.h; ++y)
        {
            for (int x = 0; x < BoxGrid.w; ++x)
            {
                if (BoxGrid.grid[x, y] != null)
                {
                    if (BoxGrid.grid[x, y].parent == transform)
                    {
                        BoxGrid.grid[x, y] = null;
                    }
                }
            }
        }

        // Add new children to grid
        foreach (Transform child in transform)
        {
            Vector2 v = BoxGrid.RoundVec2(child.position);
            BoxGrid.grid[(int)v.x, (int)v.y] = child;
        }
    }