public override void OnInspectorGUI() { DrawDefaultInspector(); TerrainBuilder myScript = (TerrainBuilder)target; if (GUILayout.Button("Build Object")) { myScript.BuildTerrain(); } }
/*private void OnDrawGizmos() { * Gizmos.color = Color.green; * Gizmos.DrawWireCube(instanceBound.center, instanceBound.size); * }*/ public void BuildTerrainTool() { terrainBuilder = new TerrainBuilder(heightMap, terrainHeight, terrainMat); GameObject terrain = GameObject.Find("terrain"); if (terrain) { DestroyImmediate(terrain); } terrainBuilder.BuildTerrain(transform); }
void Awake() { //GenMathData(); sizeBuffer = new ComputeBuffer(6, sizeof(float)); float[] sizeBufferData = new float[6]; sizeBuffer.SetData(sizeBufferData); Shader.SetGlobalBuffer("sizeBuffer", sizeBuffer); //地形 terrainBuilder = new TerrainBuilder(heightMap, terrainHeight, terrainMat); GameObject terrain = GameObject.Find("terrain"); if (!terrain) { terrainBuilder.BuildTerrain(transform); } //视锥体 frustumCalc = new FrustumCalculation(calcShader, terrainBuilder); //草叶 grassGen = new GrassGenerator(grassDensityMap, grassAmountPerTile, pregenerateGrassAmount, grassMaterial, TerrainBuilder.PATCH_SIZE); grassMesh = grassGen.generateGrassTile(); grassGen.PregenerateGrassInfo(); //terrain data buffer Texture terrainTex = terrainBuilder.GetTerrainHeightTexture(); Texture densityTex = grassGen.GetTerrainDensityTexture(); Shader.SetGlobalTexture("terrainHeightTex", terrainTex); frustumCalc.SetTextureFromGlobal("terrainHeightTex"); grassMaterial.SetTexture("terrainDensityTex", densityTex); Shader.SetGlobalFloat("terrainHeight", terrainHeight); frustumCalc.SetFloat("terrainHeight", terrainHeight); grassMaterial.SetInt("grassAmountPerTile", grassAmountPerTile); grassMaterial.SetInt("pregenerateGrassAmount", pregenerateGrassAmount); argsBuffer = new ComputeBuffer(1, sizeof(uint) * 5, ComputeBufferType.IndirectArguments); counterBuffer = new ComputeBuffer(1, sizeof(uint), ComputeBufferType.Counter); SetShadowTexture(); }