public GridSector GetRandomGridSector() { RAKTerrain[] terrain = world.masterTerrain.getTerrain(); int index = Random.Range(0, terrain.Length); RAKTerrain chosenTerrain = terrain[index]; GridSector[] sectorsInTerrain = chosenTerrain.GetGridElements(); index = Random.Range(0, sectorsInTerrain.Length); return(sectorsInTerrain[index]); }
public GridSector GetCurrentGridSector(Transform transform) { RAKTerrain closestTerrain = world.masterTerrain.GetClosestTerrainToPoint(transform.position); GridSector[] sectors = closestTerrain.GetGridElements(); float closestDist = Mathf.Infinity; int indexOfClosest = -1; for (int count = 0; count < sectors.Length; count++) { float currentDistance = Vector3.Distance(transform.position, sectors[count].GetSectorPosition); if (currentDistance < closestDist) { closestDist = currentDistance; indexOfClosest = count; } } return(sectors[indexOfClosest]); }
public static GridSector[] GetPiecesOfTerrainCreatureCanSee(Creature requester, float distance, RAKTerrain terrain) { List <GridSector> elementsWithinRange = new List <GridSector>(); GridSector[] elements = terrain.GetGridElements(); foreach (GridSector element in elements) { if (Vector3.Distance(requester.transform.position, element.GetSectorPosition) <= distance) { elementsWithinRange.Add(element); } } if (terrain.neighbors == null) { return(elementsWithinRange.ToArray()); } for (int count = 0; count < terrain.neighbors.Length; count++) { Terrain neighbor = terrain.neighbors[count]; if (neighbor == null) { continue; } RAKTerrain neighborTerrain = neighbor.gameObject.GetComponent <RAKTerrain>(); GridSector[] sectors = neighborTerrain.GetGridElements(); foreach (GridSector element in elements) { if (Vector3.Distance(requester.transform.position, element.GetSectorPosition) <= distance) { elementsWithinRange.Add(element); } } } return(elementsWithinRange.ToArray()); }