Ejemplo n.º 1
0
    //вернёт ооффсеты не нулевые в квадрате startPos endPos
    public BufferItem GetCollidersInRect(Vector2 startPos, Vector2 endPos, bool includingAll = false)
    {
        //List<Vector2Int> rezPos = new List<Vector2Int>();
        Buffer.NextBuffer();

        Vector2Int p0 = GetMapPos(startPos);
        Vector2Int p1 = GetMapPos(endPos);

        int minX = p0.x <= p1.x ? p0.x : p1.x;
        int minY = p0.y <= p1.y ? p0.y : p1.y;

        int maxX = p0.x >= p1.x ? p0.x : p1.x;
        int maxY = p0.y >= p1.y ? p0.y : p1.y;

        for (int x = minX; x <= maxX; x++)
        {
            for (int y = minY; y <= maxY; y++)
            {
                if (includingAll)
                {
                    Buffer.Add(new Vector2Int(x, y));
                }
                else
                {
                    if (!Map[x, y].IsEmpty())
                    {
                        Buffer.Add(new Vector2Int(x, y));
                    }
                }
            }
        }

        return(Buffer.GetCurrent);
    }