private void Init() { Spawner = FindObjectOfType <Spawner>(); UIView = FindObjectOfType <UIView>(); UnitController = new UnitController(); InputController = new InputController(); BoundsController = new BoundsController(GetComponent <Collider>().bounds); }
private static bool IsValid( Vector2 candidate, List <GameObject> terrainGoList, Vector2 sampleRegionSize, float cellSize, float radius, List <Vector2> points, int[,] grid) { foreach (var terrain in terrainGoList) { var bounds = terrain.GetComponent <Collider>().bounds; var outOfTerrain = new BoundsController(bounds).IsOutOfBounds(candidate + Variables.CoordinatesOffset, radius); if (!outOfTerrain) { return(false); } } if (candidate.x >= 0 && candidate.x < sampleRegionSize.x && candidate.y >= 0 && candidate.y < sampleRegionSize.y) { var cellX = (int)(candidate.x / cellSize); var cellY = (int)(candidate.y / cellSize); var searchStartX = Mathf.Max(0, cellX - 2); var searchEndX = Mathf.Min(cellX + 2, grid.GetLength(0) - 1); var searchStartY = Mathf.Max(0, cellY - 2); var searchEndY = Mathf.Min(cellY + 2, grid.GetLength(1) - 1); for (var x = searchStartX; x <= searchEndX; x++) { for (var y = searchStartY; y <= searchEndY; y++) { var pointIndex = grid[x, y] - 1; if (pointIndex != -1) { var sqrDst = (candidate - points[pointIndex]).sqrMagnitude; if (sqrDst < radius * radius) { return(false); } } } } return(true); } return(false); }