Пример #1
0
    bool isValidGridPos()
    {
        foreach (Transform child in transform)
        {
            Vector2 v = PlayGrid.roundVec2(child.position);

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

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

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