Exemplo n.º 1
0
    /// <summary>
    /// Creates the terrain.
    /// </summary>
    public void     CreateTerrain()
    {
        Data = new TerrainData();

        Data.heightmapResolution = Setting.HeightmapResolution;
        Data.alphamapResolution  = Setting.AlphamapResolution;
        Data.SetHeights(0, 0, Heightmap);

        ApplyTextures(Data);

        Data.size = new Vector3(Setting.Length, Setting.Height, Setting.Length);
        GameObject newTerrainGameObject = Terrain.CreateTerrainGameObject(Data);

        newTerrainGameObject.transform.position = new Vector3(Position.X * Setting.Length, 0, Position.Z * Setting.Length);

        // create a new terrain chunk
        TerrainChunk = newTerrainGameObject.GetComponent <Terrain>();
        TerrainChunk.heightmapPixelError  = 8;
        TerrainChunk.materialType         = UnityEngine.Terrain.MaterialType.Custom;
        TerrainChunk.materialTemplate     = Setting.TerrainMaterial;
        TerrainChunk.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
        TerrainChunk.Flush();

        ApplyTrees(Data);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Updates the neighbors.
    /// </summary>
    public void UpdateNeighbors()
    {
        if (TerrainChunk != null)
        {
            var xDown = Neighborhood.XDown == null ? null : Neighborhood.XDown.TerrainChunk;
            var xUp   = Neighborhood.XUp == null ? null : Neighborhood.XUp.TerrainChunk;
            var zDown = Neighborhood.ZDown == null ? null : Neighborhood.ZDown.TerrainChunk;
            var zUp   = Neighborhood.ZUp == null ? null : Neighborhood.ZUp.TerrainChunk;

            TerrainChunk.SetNeighbors(xDown, zUp, xUp, zDown);
            TerrainChunk.Flush();
        }
    }
Exemplo n.º 3
0
    public void ReplaceTree()
    {
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, 10.0f))
        {
            List <TreeInstance> allTrees = new List <TreeInstance>(TerrainChunk.terrainData.treeInstances);
            for (int i = 0; i < allTrees.Count; i++)
            {
                allTrees.RemoveAt(i);
            }

            TerrainChunk.terrainData.treeInstances = allTrees.ToArray();

            float[,] heights = TerrainChunk.terrainData.GetHeights(0, 0, 0, 0);
            TerrainChunk.terrainData.SetHeights(0, 0, heights);

            TerrainChunk.Flush();
        }
    }