Esempio n. 1
0
    private Vector3Int GetOffset(Template template)
    {
        var size = template.boundingBox.size;

        switch (template.strategy)
        {
        case Template.PlacementStrategy.Castle:
            return(new Vector3Int(-size.x / 2, -size.y / 2, 0));

        case Template.PlacementStrategy.Graveyard:
            Vector2Int placementDimensions = usableMapDimensions - size;
            Vector3Int rawPos = RandomPositionOnPerimeter(placementDimensions);
            return(rawPos + bottomLeftCorner.To3D());

        default:
            Vector3Int pos;
            RectInt    usedSpace;
            do
            {
                pos = new Vector3Int(
                    Random.Range(bottomLeftCorner.x, upperRightCorner.x - size.x),
                    Random.Range(bottomLeftCorner.y, upperRightCorner.y - size.y),
                    0
                    );
                usedSpace = new RectInt(pos.x, pos.y, size.x, size.y);
            } while (usedSpaces.AnyOverlap(usedSpace));

            return(pos);
        }
    }