public void GetTerrainAtWorldPosition_test() { TerrainData terrainData = new TerrainData { size = new Vector3(512, 512, 512) }; Terrain terrain = Terrain.CreateTerrainGameObject(terrainData).GetComponent <Terrain>(); terrain.transform.position = Vector3.zero; Assert.That(TerrainScanner.GetTerrainAtWorldPosition(new Vector3(256, 0, 256), out Terrain terrain1), Is.True); Assert.That(TerrainScanner.GetTerrainAtWorldPosition(new Vector3(0, 0, 0), out Terrain terrain2), Is.True); Assert.That(TerrainScanner.GetTerrainAtWorldPosition(new Vector3(-1, 0, 0), out Terrain terrain3), Is.False); Assert.That(TerrainScanner.GetTerrainAtWorldPosition(new Vector3(0, 0, -1), out Terrain terrain4), Is.False); Assert.That(TerrainScanner.GetTerrainAtWorldPosition(new Vector3(513, 0, 0), out Terrain terrain5), Is.False); Assert.That(TerrainScanner.GetTerrainAtWorldPosition(new Vector3(0, 0, 513), out Terrain terrain6), Is.False); Assert.That(TerrainScanner.GetTerrainAtWorldPosition(new Vector3(513, 0, 513), out Terrain terrain7), Is.False); Assert.That(terrain1.Equals(terrain2), Is.True); }
private void Awake() { _boxCollider = GetComponent <BoxCollider>(); _boxCollider.size = new Vector3Int(_influenceRadius, _influenceRadius, _influenceRadius); _boxCollider.center = new Vector3Int(0, _influenceRadius >> 1, 0); _boxCollider.isTrigger = true; if (TerrainScanner.GetTerrainAtWorldPosition(transform.position, out Terrain terrain)) { if (TerrainScanner.GetTerrainMap(terrain, transform.position, InfluenceRadius, InfluenceRadius, out Map map)) { Map = map; } } else { throw new UnityException("The ZoneBehaviour has to be located unto a terrain."); } }