Пример #1
0
        private Color GetColor(float height)
        {
            if (terrainTable == null)
            {
                return(Color.white);
            }

            var terrainType = terrainTable.GetTerrainType(height);

            if (!useColorGradient)
            {
                return(terrainType.ColorGradient.Evaluate(0));
            }

            var t = Mathf.InverseLerp(terrainType.Floor, terrainType.Threshold, height);

            return(terrainType.ColorGradient.Evaluate(t));
        }
        public override void DisplayMap(WorldMapData worldMapData)
        {
            if (!enabled)
            {
                return;
            }
            var heightMap = worldMapData.GetLayer <HeightMapLayerData>().heightMap;

            if (terrainTable == null)
            {
                var meshData = TerrainMeshUtility.GenerateMesh(heightMap, worldMapData.width, worldMapData.height, heightScale, levelOfDetail);
                _meshFilter.mesh = meshData.CreateMesh();
            }
            else
            {
                var meshData = TerrainMeshUtility.GenerateMesh(heightMap, worldMapData.width, worldMapData.height, levelOfDetail,
                                                               x =>
                {
                    var terrainType = terrainTable.GetTerrainType(x);
                    if (smooth)
                    {
                        var t = Mathf.InverseLerp(terrainType.Floor, terrainType.Threshold, x);
                        return(Mathf.Lerp(terrainType.MinElevation, terrainType.MaxElevation, t) * heightScale);
                    }
                    return(terrainTable.GetTerrainType(x).MinElevation *heightScale);
                },
                                                               x =>
                {
                    var terrainType = terrainTable.GetTerrainType(x);
                    if (!useColorGradient)
                    {
                        return(terrainType.ColorGradient.Evaluate(0));
                    }
                    var t = Mathf.InverseLerp(terrainType.Floor, terrainType.Threshold, x);
                    return(terrainType.ColorGradient.Evaluate(t));
                });
                _meshFilter.mesh = meshData.CreateMesh();
            }
        }