Ejemplo n.º 1
0
    public bool IsAreaValid(Vector2Int vTopLeft, int areaWidth, int areaHeight, ref int AreaId)
    {
        int nOrigin = 0;

        int nCells = areaWidth * areaHeight;

        for (int i = 0; i < areaHeight; ++i)
        {
            int cellX = vTopLeft.x + i;
            for (int j = 0; j < areaWidth; ++j)
            {
                int cellY = vTopLeft.y + j;

                Cell cell = m_aGridView[cellX, cellY].GetComponent <Cell>();

                // A cell in given area already belong to an area
                if (cell.IsInArea())
                {
                    return(false);
                }

                if (cell.IsAreaOrigin())
                {
                    // More than one origin cell in area
                    if (++nOrigin != 1)
                    {
                        return(false);
                    }

                    // Too much/not enough cells in area based on origin cell value
                    if (cell.GetAreaOriginValue() != nCells)
                    {
                        return(false);
                    }

                    AreaId = m_aGridModel.GetAreaId(cellX, cellY);
                }
            }
        }

        return(nOrigin != 0);
    }