-
-
Save todorok1/a6a953444cd9d9b7c9c74a177dc4e15d to your computer and use it in GitHub Desktop.
TerrainのHeightMapを生成するスクリプト(エディタ拡張のクラス)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <Summary> | |
/// 設定に応じてTerrainのHeightMapを生成します。 | |
/// </Summary> | |
void GenerateTerrainOnEditor(TerrainGenerator generator) | |
{ | |
// Terrainの解像度を取得します。 | |
int terrainSizeX = generator.terrainData.heightmapResolution; | |
int terrainSizeZ = generator.terrainData.heightmapResolution; | |
// Terrainにセットするハイトマップを作成します。 | |
float[,] newHeightMap = new float[terrainSizeX, terrainSizeZ]; | |
for (int z = 0; z < terrainSizeZ; z++) | |
{ | |
for (int x = 0; x < terrainSizeX; x++) | |
{ | |
// パーリンノイズの座標を指定して値を取得します。 | |
float xValue = (generator.xOrigin + x) * generator.scale; | |
float yValue = (generator.yOrigin + z) * generator.scale; | |
float perlinValue = GetMultiplePerlinNoise(xValue, yValue, terrainSizeX, terrainSizeZ, generator); | |
float height = generator.heightMultiply * perlinValue; | |
// HeightMapに値をセットします。 | |
newHeightMap[x, z] = height; | |
} | |
} | |
// 生成したHeightMapをセットします。 | |
generator.terrainData.SetHeights(0, 0, newHeightMap); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment