Beispiel #1
0
 bool IsValidGridPos()
 {
     foreach (Transform child in transform)
     {
         Vector2 v = GridBehavior.RoundVec2(child.position);
         //not inside border ?
         if (!GridBehavior.InsideBorder(v))
         {
             return(false);
         }
         //Block in grid cell (and not part of the same group) ?
         if (GridBehavior.grid[(int)v.x, (int)v.y] != null &&
             GridBehavior.grid[(int)v.x, (int)v.y].parent != transform)
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #2
0
    void updateGrid()
    {
        // Remove old children from grid
        for (int y = 0; y < GridBehavior.h; ++y)
        {
            for (int x = 0; x < GridBehavior.w; ++x)
            {
                if (GridBehavior.grid[x, y] != null)
                {
                    if (GridBehavior.grid[x, y].parent == transform)
                    {
                        GridBehavior.grid[x, y] = null;
                    }
                }
            }
        }

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