public override AreaSettings[] ProduceAreaSettings(Graph <AreaData> areaDataGraph, IEnumerable <Vector2[]> clearPolygons, Vector2[] borderPolygon) { AreaSettings forest = new ForestSettings(areaDataGraph, clearPolygons, borderPolygon, Trees, TreeDistance, AngleTolerance, SegmentType.ToString()) { ArenaTriggerPrefab = this.ArenaTriggerPrefab, FogGatePrefab = this.FogGatePrefab }; return(new[] { forest }); }
public static List <Vector2> AddTrees(Forest mainForest, ForestSettings settings, MeshSettings meshSettings, Vector2 coord, HeightMap heightMap, Transform parent) { int width = heightMap.values.GetLength(0); int height = heightMap.values.GetLength(1); List <Vector2> treeKeys = new List <Vector2>(); float[][,] values = new float[settings.forestElements.Length][, ]; for (int i = 0; i < settings.forestElements.Length; i++) { values[i] = Noise.GenerateNoiseMap(width, height, settings.forestElements[i].noiseSettings, coord); } for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { for (int i = 0; i < settings.forestElements.Length; i++) { Vector3 newPosition = new Vector3((coord.x + x - height / 2) * meshSettings.meshScale, heightMap.values[x, y] - settings.forestElements[i].yOffset, (coord.y - y + (height / 2)) * meshSettings.meshScale); float perlin = values[i][x, y]; if (heightMap.values[x, y] > settings.forestElements[i].minHeight && heightMap.values[x, y] < settings.forestElements[i].maxHeight && CanPlantTree(mainForest, new Vector2(newPosition.x, newPosition.z), settings.forestElements[i].separation, meshSettings.meshScale) && perlin < settings.forestElements[i].perlinRatio && Random.value < settings.forestElements[i].densityRatio) { Vector3 treeRotation = Vector3.zero; treeRotation.y = Random.Range(-180, 180); Vector3 scale = Vector3.one * Random.Range(0.5f, 1.5f); Vector2 forestElementKey = new Vector2(newPosition.x, newPosition.z); ForestElement newForestElement = new ForestElement(); newForestElement.element = Instantiate(settings.forestElements[i].prefab, parent); newForestElement.Initialize(newPosition, treeRotation, scale); mainForest.trees.Add(forestElementKey, newForestElement); treeKeys.Add(forestElementKey); } } } } return(treeKeys); }
public TerrainChunk(Vector2 coord, HeightMapSettings heightMapSettings, MeshSettings meshSettings, Forest forest, ForestSettings forestSettings, LODInfo[] detailLevels, int colliderLODIndex, Transform parent, Transform viewer, Material material) { this.coord = coord; _detailLevels = detailLevels; _colliderLODIndex = colliderLODIndex; _heightMapSettings = heightMapSettings; _meshSettings = meshSettings; _forestSettings = forestSettings; _viewer = viewer; _forest = forest; _sampleCentre = coord * meshSettings.meshWorldSize / meshSettings.meshScale; Vector2 position = coord * meshSettings.meshWorldSize; _bounds = new Bounds(position, Vector2.one * meshSettings.meshWorldSize); _meshObject = new GameObject("TerrainChunk"); _meshObject.transform.position = new Vector3(position.x, 0, position.y); _meshObject.transform.parent = parent; _meshRenderer = _meshObject.AddComponent <MeshRenderer>(); _meshRenderer.material = material; _meshFilter = _meshObject.AddComponent <MeshFilter>(); _meshCollider = _meshObject.AddComponent <MeshCollider>(); setVisible(false); _lodMeshes = new LODMesh[detailLevels.Length]; for (int i = 0; i < detailLevels.Length; i++) { _lodMeshes[i] = new LODMesh(_detailLevels[i].lod); _lodMeshes[i].updateCallback += Update; if (i == colliderLODIndex) { _lodMeshes[i].updateCallback += UpdateCollisionMesh; } } _maxViewDistance = _detailLevels[detailLevels.Length - 1].visibleDstThreshold; }