Beispiel #1
0
 private void DoApply()
 {
     if (base.terrainData != null)
     {
         TreePrototype[] treePrototypes = base.m_Terrain.terrainData.treePrototypes;
         if (this.m_PrototypeIndex == -1)
         {
             TreePrototype[] prototypeArray2 = new TreePrototype[treePrototypes.Length + 1];
             for (int i = 0; i < treePrototypes.Length; i++)
             {
                 prototypeArray2[i] = treePrototypes[i];
             }
             prototypeArray2[treePrototypes.Length] = new TreePrototype();
             prototypeArray2[treePrototypes.Length].prefab = this.m_Tree;
             prototypeArray2[treePrototypes.Length].bendFactor = this.m_BendFactor;
             this.m_PrototypeIndex = treePrototypes.Length;
             base.m_Terrain.terrainData.treePrototypes = prototypeArray2;
             TreePainter.selectedTree = this.m_PrototypeIndex;
         }
         else
         {
             treePrototypes[this.m_PrototypeIndex].prefab = this.m_Tree;
             treePrototypes[this.m_PrototypeIndex].bendFactor = this.m_BendFactor;
             base.m_Terrain.terrainData.treePrototypes = treePrototypes;
         }
         base.m_Terrain.Flush();
         EditorUtility.SetDirty(base.m_Terrain);
     }
 }
 private void DoApply()
 {
   if ((Object) this.terrainData == (Object) null)
     return;
   TreePrototype[] treePrototypes = this.m_Terrain.terrainData.treePrototypes;
   if (this.m_PrototypeIndex == -1)
   {
     TreePrototype[] treePrototypeArray = new TreePrototype[treePrototypes.Length + 1];
     for (int index = 0; index < treePrototypes.Length; ++index)
       treePrototypeArray[index] = treePrototypes[index];
     treePrototypeArray[treePrototypes.Length] = new TreePrototype();
     treePrototypeArray[treePrototypes.Length].prefab = this.m_Tree;
     treePrototypeArray[treePrototypes.Length].bendFactor = this.m_BendFactor;
     this.m_PrototypeIndex = treePrototypes.Length;
     this.m_Terrain.terrainData.treePrototypes = treePrototypeArray;
     TreePainter.selectedTree = this.m_PrototypeIndex;
   }
   else
   {
     treePrototypes[this.m_PrototypeIndex].prefab = this.m_Tree;
     treePrototypes[this.m_PrototypeIndex].bendFactor = this.m_BendFactor;
     this.m_Terrain.terrainData.treePrototypes = treePrototypes;
   }
   this.m_Terrain.Flush();
   EditorUtility.SetDirty((Object) this.m_Terrain);
 }
Beispiel #3
0
        private bool Equals(TreePrototype other)
        {
            bool flag = other == null;
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                bool flag2 = other == this;
                if (flag2)
                {
                    result = true;
                }
                else
                {
                    bool flag3 = base.GetType() != other.GetType();
                    if (flag3)
                    {
                        result = false;
                    }
                    else
                    {
                        bool flag4 = this.prefab == other.prefab && this.bendFactor == other.bendFactor && this.navMeshLod == other.navMeshLod;
                        result = flag4;
                    }
                }
            }
            return(result);
        }
		private void DoApply()
		{
			if (base.terrainData == null)
			{
				return;
			}
			TreePrototype[] treePrototypes = this.m_Terrain.terrainData.treePrototypes;
			if (this.m_PrototypeIndex == -1)
			{
				TreePrototype[] array = new TreePrototype[treePrototypes.Length + 1];
				for (int i = 0; i < treePrototypes.Length; i++)
				{
					array[i] = treePrototypes[i];
				}
				array[treePrototypes.Length] = new TreePrototype();
				array[treePrototypes.Length].prefab = this.m_Tree;
				array[treePrototypes.Length].bendFactor = this.m_BendFactor;
				this.m_PrototypeIndex = treePrototypes.Length;
				this.m_Terrain.terrainData.treePrototypes = array;
			}
			else
			{
				treePrototypes[this.m_PrototypeIndex].prefab = this.m_Tree;
				treePrototypes[this.m_PrototypeIndex].bendFactor = this.m_BendFactor;
				this.m_Terrain.terrainData.treePrototypes = treePrototypes;
			}
			this.m_Terrain.Flush();
			EditorUtility.SetDirty(this.m_Terrain);
		}
Beispiel #5
0
 public static void ClearTrees()
 {
     Terrain t = Terrain.activeTerrain;
     TerrainData td = t.terrainData;
     TreePrototype[] treeprototypes = new TreePrototype[0];
     td.treePrototypes = treeprototypes;
     
 }
        private bool Equals(TreePrototype other)
        {
            if (ReferenceEquals(other, null))
            {
                return(false);
            }

            if (ReferenceEquals(other, this))
            {
                return(true);
            }

            if (GetType() != other.GetType())
            {
                return(false);
            }

            bool equals = prefab == other.prefab &&
                          bendFactor == other.bendFactor;

            return(equals);
        }
Beispiel #7
0
        /// <summary>
        /// Read the data into the specified value.
        /// </summary>
        /// <param name="value">Value.</param>
        /// <param name="reader">Reader.</param>
        public override void ReadInto(object value, ISaveGameReader reader)
        {
            UnityEngine.TreePrototype treePrototype = (UnityEngine.TreePrototype)value;
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "prefab":
                    if (treePrototype.prefab == null)
                    {
                        treePrototype.prefab = reader.ReadProperty <UnityEngine.GameObject> ();
                    }
                    else
                    {
                        reader.ReadIntoProperty <UnityEngine.GameObject> (treePrototype.prefab);
                    }
                    break;

                case "bendFactor":
                    treePrototype.bendFactor = reader.ReadProperty <System.Single> ();
                    break;
                }
            }
        }
Beispiel #8
0
    private static void GenerateTrees()
    {
        Terrain t = Terrain.activeTerrain;
        TerrainData td = t.terrainData;

        TreePrototype[] treeprototypes = new TreePrototype[] { new TreePrototype() { prefab = (GameObject)Resources.Load("BigTree") }, new TreePrototype() { prefab = (GameObject)Resources.Load("Tree") } };

        td.treePrototypes = treeprototypes;

        //float[, ,] splatmaps = td.GetAlphamaps(0, 0, td.alphamapWidth, td.alphamapHeight);
        td.treeInstances = new TreeInstance[0];

        List<Vector3> treePos = new List<Vector3>();

        float[,] noisemap = new float[td.alphamapWidth, td.alphamapHeight];
        Generator noise_tree = new Max(
            new PinkNoise((int)UnityEngine.Random.Range(0, int.MaxValue)) { Frequency = 0.01f, OctaveCount = 6, Persistence = 0.66f, Lacunarity = 0.1f },
            new PinkNoise((int)UnityEngine.Random.Range(0, int.MaxValue)) { Frequency = 0.015f, OctaveCount = 2, Persistence = 0.66f, Lacunarity = 0.2f });
        for (int ny = 0; ny < noisemap.GetLength(1); ny++)
        {
            for (int nx = 0; nx < noisemap.GetLength(0); nx++)
            {
                noisemap[nx, ny] = noise_tree.GetValue(nx, ny, 0);
            }
        }
        if (maxSteepness == 0) { maxSteepness = 70.0f; }
        if (waterLevel == 0) { waterLevel = 0.0f; }
        float x = 0.0f;
        while (x < td.alphamapWidth)
        {
            float y = 0.0f;
            while (y < td.alphamapHeight)
            {
                float height = td.GetHeight((int)x, (int)y);
                float heightScaled = height / td.size.y;
                float xScaled = (x + Random.Range(-1f, 1f)) / td.alphamapWidth;
                float yScaled = (y + Random.Range(-1f, 1f)) / td.alphamapHeight;
                float steepness = td.GetSteepness(xScaled, yScaled);

                if (Random.Range(0f, 1f) > 1f - noisemap[(int)x, (int)y] * 2f && steepness < maxSteepness && height > waterLevel)
                {
                    treePos.Add(new Vector3(xScaled, heightScaled, yScaled));
                }

                y++;
            }
            x++;
        }

        TreeInstance[] treeInstances = new TreeInstance[treePos.Count];

        for (int ii = 0; ii < treeInstances.Length; ii++)
        {
            treeInstances[ii].position = treePos[ii];
            treeInstances[ii].prototypeIndex = Random.Range(0, treeprototypes.Length);
            treeInstances[ii].color = Color.white;//new Color(Random.Range(200, 255), Random.Range(200, 255), Random.Range(200, 255));
            treeInstances[ii].lightmapColor = Color.white;
            treeInstances[ii].heightScale = 1.0f + Random.Range(-0.25f, 0.5f);
            treeInstances[ii].widthScale = 1.0f + Random.Range(-0.5f, 0.25f);
        }
        td.treeInstances = treeInstances;
    }
Beispiel #9
0
 /// <summary>
 /// Read the data using the reader.
 /// </summary>
 /// <param name="reader">Reader.</param>
 public override object Read(ISaveGameReader reader)
 {
     UnityEngine.TreePrototype treePrototype = new UnityEngine.TreePrototype();
     ReadInto(treePrototype, reader);
     return(treePrototype);
 }
Beispiel #10
0
    private void CreateLand()
    {
        #region Preparations

        var mapData = Data.Battle["gamebody"]["map_info"]["types"];
        var worldSize = realMapSize * Settings.DimensionScaleFactor;
        var resolution = Mathf.RoundToInt(Mathf.Sqrt(realMapSize.x * realMapSize.y) * Settings.Terrain.Smoothness);
        var terrainData = new TerrainData { heightmapResolution = Mathf.ClosestPowerOfTwo(resolution) + 1, size = new Vector3(worldSize.y, Settings.Map.HeightOfLevel[2], worldSize.x), alphamapResolution = resolution, baseMapResolution = resolution };

        #endregion

        #region Set Heights

        float landArea = 0;
        var heights = new float[terrainData.heightmapHeight, terrainData.heightmapWidth];
        var mapRect = new Rect(0, 0, Data.MapSize.x, Data.MapSize.y);
        for (int bumpNum = Mathf.RoundToInt(realMapSize.x * realMapSize.y / 10), i = 0; i < bumpNum; ++i)
        {
            var sigmaX = Random.Range(0.8f, 2) * terrainData.heightmapHeight / realMapSize.x;
            var sigmaY = Random.Range(0.8f, 2) * terrainData.heightmapWidth / realMapSize.y;
            var muX = Random.Range(0, terrainData.heightmapHeight);
            var muY = Random.Range(0, terrainData.heightmapWidth);
            var h = Random.Range(-0.6f, 0.4f);
            for (var x = Mathf.Max(-muX, -Mathf.RoundToInt(sigmaX * 3)); x < Mathf.Min(terrainData.heightmapHeight - muX, Mathf.RoundToInt(sigmaX * 3)); ++x)
                for (var y = Mathf.Max(-muY, -Mathf.RoundToInt(sigmaY * 3)); y < Mathf.Min(terrainData.heightmapWidth - muY, Mathf.RoundToInt(sigmaY * 3)); ++y)
                    heights[muX + x, muY + y] += h * Mathf.Exp(-Mathf.Pow(x / sigmaX, 2) - Mathf.Pow(y / sigmaY, 2));
        }
        var threshold = Settings.Map.HeightOfLevel[0] / Settings.Map.HeightOfLevel[2] * 0.8f;
        for (var x = 0; x < terrainData.heightmapHeight; ++x)
            for (var y = 0; y < terrainData.heightmapWidth; ++y)
            {
                if ((heights[x, y] += threshold / 2) > threshold)
                    heights[x, y] = threshold;
                var i = (float)x / (terrainData.heightmapHeight - 1) * realMapSize.x - Settings.Map.MapSizeOffset.top;
                var j = (1 - (float)y / (terrainData.heightmapWidth - 1)) * realMapSize.y - Settings.Map.MapSizeOffset.left;
                int i0 = Mathf.FloorToInt(i), j0 = Mathf.FloorToInt(j);
                float ul = 0, ur = 0, br = 0, bl = 0, di = i - i0, dj = j - j0;
                if (mapRect.Contains(new Vector2(i0, j0)))
                    ul = mapData[i0][j0].n;
                if (mapRect.Contains(new Vector2(i0, j0 + 1)))
                    ur = mapData[i0][j0 + 1].n;
                if (mapRect.Contains(new Vector2(i0 + 1, j0 + 1)))
                    br = mapData[i0 + 1][j0 + 1].n;
                if (mapRect.Contains(new Vector2(i0 + 1, j0)))
                    bl = mapData[i0 + 1][j0].n;
                var height = (1 - di) * (1 - dj) * ul + (1 - di) * dj * ur + di * (1 - dj) * bl + di * dj * br;
                if (Math.Abs(height) < Mathf.Epsilon)
                    continue;
                heights[x, y] = Mathf.Max(heights[x, y], height = Mathf.Sign(height - 0.5f) * Mathf.Pow(Mathf.Abs(height * 2 - 1), 0.25f) / 2 + 0.5f);
                landArea += height;
            }
        terrainData.SetHeights(0, 0, heights);
        landArea *= realMapSize.x * realMapSize.y / (terrainData.heightmapHeight * terrainData.heightmapWidth);

        #endregion

        #region Paint Texture

        var splatPrototypes = new SplatPrototype[splatTextures.Length];
        for (var i = 0; i < splatPrototypes.Length; i++)
        {
            var splatPrototype = new SplatPrototype { texture = splatTextures[i], tileSize = Vector2.one * Settings.DimensionScaleFactor * 4 };
            splatPrototypes[i] = splatPrototype;
        }
        terrainData.splatPrototypes = splatPrototypes;
        var alphamapResolution = terrainData.alphamapResolution;
        var alphamaps = new float[alphamapResolution, alphamapResolution, splatPrototypes.Length];
        for (var i = 0; i < alphamapResolution; i++)
            for (var j = 0; j < alphamapResolution; j++)
            {
                var height = heights[Mathf.RoundToInt((float)i / (alphamapResolution - 1) * (terrainData.heightmapHeight - 1)), Mathf.RoundToInt((float)j / (alphamapResolution - 1) * (terrainData.heightmapWidth - 1))];
                alphamaps[i, j, 0] = height;
                alphamaps[i, j, 1] = 1 - height;
            }
        terrainData.SetAlphamaps(0, 0, alphamaps);

        #endregion

        #region Place Trees

        var treePrototypes = new TreePrototype[treePrefabs.Length];
        for (var i = 0; i < treePrototypes.Length; i++)
        {
            var treePrototype = new TreePrototype { prefab = treePrefabs[i], bendFactor = 1 };
            treePrototypes[i] = treePrototype;
        }
        terrainData.treePrototypes = treePrototypes;
        var treeInstances = new TreeInstance[Mathf.RoundToInt(landArea * Settings.Terrain.Tree.Density)];
        var range = new Vector4(Settings.Map.MapSizeOffset.right / realMapSize.y, 1 - Settings.Map.MapSizeOffset.left / realMapSize.y, Settings.Map.MapSizeOffset.top / realMapSize.x, 1 - Settings.Map.MapSizeOffset.bottom / realMapSize.x);
        for (var i = 0; i < treeInstances.Length; i++)
        {
            var treeScale = Random.Range(0.08f, 0.16f) * Settings.DimensionScaleFactor;
            Vector3 treePosition;
            do
                treePosition = new Vector3(Random.Range(range.x, range.y), 0, Random.Range(range.z, range.w));
            while ((treePosition.y = heights[Mathf.RoundToInt(treePosition.z * (terrainData.heightmapHeight - 1)), Mathf.RoundToInt(treePosition.x * (terrainData.heightmapWidth - 1))]) < Mathf.Lerp(Settings.Map.HeightOfLevel[1] / Settings.Map.HeightOfLevel[2], 1, 0.6f) || Methods.Coordinates.IsOccupied(Methods.Coordinates.InternalToExternal(Vector3.Scale(treePosition, new Vector3(worldSize.y, 0, worldSize.x)))));
            var treeInstance = new TreeInstance { prototypeIndex = Random.Range(0, treePrototypes.Length), position = treePosition + Vector3.up * Settings.Terrain.Tree.VerticalPositionOffset * treeScale, color = new Color(0, 0.8f, 0, 1), lightmapColor = new Color(1, 1, 1, 1), heightScale = treeScale, widthScale = treeScale };
            treeInstances[i] = treeInstance;
        }
        terrainData.treeInstances = treeInstances;

        #endregion

        #region Paint Details

        var detailPrototypes = new DetailPrototype[detailTextures.Length];
        for (var i = 0; i < detailPrototypes.Length; i++)
        {
            var detailPrototype = new DetailPrototype { prototypeTexture = detailTextures[i], minWidth = Settings.Terrain.Detail.MinDimension, minHeight = Settings.Terrain.Detail.MinDimension, maxWidth = Settings.Terrain.Detail.MaxDimension, maxHeight = Settings.Terrain.Detail.MaxDimension, renderMode = DetailRenderMode.GrassBillboard };
            detailPrototypes[i] = detailPrototype;
        }
        terrainData.detailPrototypes = detailPrototypes;
        terrainData.SetDetailResolution(resolution, Mathf.Clamp(resolution, 8, 128));
        var detailLayers = new int[detailPrototypes.Length][,];
        for (var i = 0; i < detailPrototypes.Length; i++)
            detailLayers[i] = new int[terrainData.detailResolution, terrainData.detailResolution];
        for (var i = 0; i < terrainData.detailResolution; i++)
            for (var j = 0; j < terrainData.detailResolution; j++)
            {
                var layer = Random.Range(0, detailPrototypes.Length);
                var height = heights[Mathf.RoundToInt((float)i / (terrainData.detailResolution - 1) * (terrainData.heightmapHeight - 1)), Mathf.RoundToInt((float)j / (terrainData.detailResolution - 1) * (terrainData.heightmapWidth - 1))];
                if (height > Mathf.Lerp(Settings.Map.HeightOfLevel[1] / Settings.Map.HeightOfLevel[2], 1, 0.4f))
                    detailLayers[layer][i, j] = 1;
            }
        for (var i = 0; i < detailPrototypes.Length; i++)
            terrainData.SetDetailLayer(0, 0, i, detailLayers[i]);
        terrainData.wavingGrassAmount = Settings.Terrain.Detail.Waving.Amount;
        terrainData.wavingGrassSpeed = Settings.Terrain.Detail.Waving.Speed;
        terrainData.wavingGrassStrength = Settings.Terrain.Detail.Waving.Strength;

        #endregion

        #region Final Settings

        var terrain = Terrain.CreateTerrainGameObject(terrainData).GetComponent<Terrain>();
        terrain.treeBillboardDistance = Settings.Terrain.Tree.BillboardDistance;
        terrain.detailObjectDistance = Settings.Terrain.Detail.MaxVisibleDistance;
        terrain.detailObjectDensity = Settings.Terrain.Detail.Density;

        #endregion
    }
 public TreePrototype(TreePrototype other)
 {
     prefab     = other.prefab;
     bendFactor = other.bendFactor;
     navMeshLod = other.navMeshLod;
 }
 TreePrototype[] SetupTrees()
 {
     TreePrototype[] Trees = new TreePrototype[3];
     Trees[0] = new TreePrototype();
     Trees[0].prefab = TreeObj[0];
     Trees[1] = new TreePrototype();
     Trees[1].prefab = TreeObj[1];
     Trees[2] = new TreePrototype();
     Trees[2].prefab = TreeObj[2];
     return Trees;
 }
 TreePrototype BlueprintToTreePrototype(TreeBlueprint blueprint)
 {
     TreePrototype prototype = new TreePrototype();
     prototype.prefab = blueprint.prefab;
     prototype.bendFactor = blueprint.bendFactor;
     return prototype;
 }
        /// <summary>
        /// Create splatmaps, trees and detail prototypes
        /// </summary>
        private void CreatePrototypes()
        {
            //Create splatmap prototypes
            var splats = new List<SplatPrototype>();
            foreach (var tex in _terrainSettings.SplatMaps)
            {
                //make sure the texture is valid
                if (tex == null) continue;

                var splat = new SplatPrototype()
                {
                    texture = tex.Texture,
                    tileSize = new Vector2(tex.TileSize, tex.TileSize)
                };

                splats.Add(splat);
            }

            //store it
            _splatPrototypes = splats.ToArray();

            //create tree prototypes
            var trees = new List<TreePrototype>();
            foreach (var prefab in _terrainSettings.Trees)
            {
                if (prefab == null) continue;

                var treeProto = new TreePrototype
                {
                    prefab = prefab
                };
                trees.Add(treeProto);
            }
            _treePrototypes = trees.ToArray();

            //Sort the detail list based on type ( textures  < prefabs)
            var detailPrefabs = _terrainSettings.Details;
            detailPrefabs = detailPrefabs.SortByType();
            //create detail prototypes textures
            var details = new List<DetailPrototype>();
            foreach (var d in detailPrefabs)
            {
                if (d == null) continue;

                var detail = new DetailPrototype
                {
                    healthyColor = Color.white,
                    dryColor = Color.white,
                    maxHeight = 0.8f,
                    maxWidth = 1.0f
                };

                //set correct data based on type
                switch (d.Type)
                {
                    case DetailType.Texture:
                        {
                            detail.renderMode = DetailRenderMode.GrassBillboard;
                            detail.prototypeTexture = (Texture2D)d.Detail;
                            _grassLayers++;
                            break;
                        }
                    case DetailType.GameObject:
                        {
                            detail.renderMode = DetailRenderMode.VertexLit;
                            detail.prototype = (GameObject)d.Detail;
                            detail.usePrototypeMesh = true;
                            _meshLayers++;
                            break;
                        }
                }

                //Add the detail
                details.Add(detail);
            }

            _detailPrototypes = details.ToArray();

            //notify user of any missed prototypes
            if (_splatPrototypes.Length < 1)
            {
                Debug.LogWarning("Unable to generate terrain textures\nPlease specify textures to use for the terrain.");
            }

            if (_treePrototypes.Length == 0)
            {
                Debug.LogWarning("Unable to generate trees\nPlease specify prefabs to use for trees.");
            }

            if (_detailPrototypes.Length == 0)
            {
                Debug.LogWarning("Unable to generate details\nPlease specify prefabs to use for details.");
            }
        }
Beispiel #15
0
 public TreePrototype(TreePrototype other)
 {
     this.prefab     = other.prefab;
     this.bendFactor = other.bendFactor;
     this.navMeshLod = other.navMeshLod;
 }
	// Use this for initialization
	void createTerrain () {

		TerrainData terrainData = new TerrainData();
		
		terrainData.heightmapResolution = m_heightMapSize;

		terrainData.size = new Vector3(m_terrainSize, m_terrainHeight, m_terrainSize);

		terrainData.alphamapResolution = m_alphaMapSize;


		//add random points
		
		for (int i=0; i< numPoints; i++) {
			
			points.Add(new Vector2(Random.Range(10,m_heightMapSize-10),Random.Range(10,m_heightMapSize-10)));
			
		}
		/*
		for (int i=0; i<20; i++)
			for (int j=0; j<20;j++)
				points.Add(new Vector2(m_terrainSize/20 * i, m_terrainSize/20*j));
				*/
		voronoi = new Voronoi (points, null, new Rect (0, 0, m_heightMapSize, m_heightMapSize));
		buildGraph (points, voronoi);
		
		
		
		
		
		m_groundNoise = new PerlinNoise(m_groundSeed);
		m_mountainNoise = new PerlinNoise(m_mountainSeed);
		m_treeNoise = new PerlinNoise(m_treeSeed);
		m_islandNoise = new PerlinNoise (m_islandSeed);
		
		
		htmap = new float[m_heightMapSize,m_heightMapSize];
		getCenter = new Center[m_heightMapSize,m_heightMapSize]; 
		
		m_terrain = new Terrain();

		
		for (int i= 0; i < m_splats.Length ; i++) {
			
			SplatPrototype splatPrototype = new SplatPrototype();
			splatPrototype.texture = m_splats[i];
			splatPrototype.tileSize = new Vector2 (2, 2);
			
			m_splatPrototypes.Add( splatPrototype);
			
		}
		
		for (int i= 0; i < m_trees.Length ; i++) {
			
			TreePrototype treePrototype = new TreePrototype();
			treePrototype.prefab = m_trees[i];
			
			
			m_treeProtoTypes.Add( treePrototype);
			
		}

		m_detailProtoTypes = new DetailPrototype[3];
		
		m_detailProtoTypes[0] = new DetailPrototype();
		m_detailProtoTypes[0].prototypeTexture = m_detail0;
		m_detailProtoTypes[0].renderMode = detailMode;
		m_detailProtoTypes[0].healthyColor = m_grassHealthyColor;
		m_detailProtoTypes[0].dryColor = m_grassDryColor;
		
		m_detailProtoTypes[1] = new DetailPrototype();
		m_detailProtoTypes[1].prototypeTexture = m_detail1;
		m_detailProtoTypes[1].renderMode = detailMode;
		m_detailProtoTypes[1].healthyColor = m_grassHealthyColor;
		m_detailProtoTypes[1].dryColor = m_grassDryColor;
		
		m_detailProtoTypes[2] = new DetailPrototype();
		m_detailProtoTypes[2].prototypeTexture = m_detail2;
		m_detailProtoTypes[2].renderMode = detailMode;
		m_detailProtoTypes[2].healthyColor = m_grassHealthyColor;
		m_detailProtoTypes[2].dryColor = m_grassDryColor;

		//terrainData.detailPrototypes = m_detailProtoTypes;

		
		terrainData.splatPrototypes = m_splatPrototypes.ToArray();
		terrainData.treePrototypes = m_treeProtoTypes.ToArray();
		terrainData.detailPrototypes = m_detailProtoTypes;
		m_terrain = Terrain.CreateTerrainGameObject(terrainData).GetComponent<Terrain>();

		m_terrain.tag = "ground";

		FillHeights(htmap); // ovde je terren

		terrainData.SetHeights(0, 0, htmap);
		
		//float ratio = (float)(m_heightMapSize-1)/m_terrainSize;
		

		foreach (Corner p in corners) {


			Vector2 coords = new Vector2(p.point.x*m_terrainSize/m_heightMapSize,p.point.y*m_terrainSize/m_heightMapSize);

			p.elevation = Terrain.activeTerrain.SampleHeight(new Vector3(coords.x,0.0f,coords.y));
			p.elevation/= m_terrainHeight;

			
			p.water = p.elevation < waterLimit; //* (heightMaximum - heightMinimum) + heightMinimum;
			
		}

//		foreach (Corner p in corners) {
//
//
//
//			int elevX = (int) (p.point.x);
//			int elevY = (int) (p.point.y);
//			
//			if (elevX == m_heightMapSize) elevX--;
//			if (elevY == m_heightMapSize) elevY--;
//			
//			p.elevation = htmap [elevX, elevY] ;
//			
//			p.water = htmap[elevX, elevY] < waterLimit; //* (heightMaximum - heightMinimum) + heightMinimum;
//			
//		} 
		
		
		//create water
		
		int size = (int) (m_terrainSize /2 * 1.41);
		float waterLevel = m_terrainHeight * waterLimit;
		GameObject water = (GameObject)Instantiate (waterTexture, new Vector3 (m_terrainSize /2, waterLevel, m_terrainSize /2), Quaternion.identity);
		Vector3 v = water.transform.localScale;
		water.transform.localScale = v + new Vector3 (size, 0, size);
		
		

		assignOceanCoastAndLand ();
		
//		foreach (Corner q in corners) {
//			if (q.ocean || q.coast) {
//				q.elevation = 0f;
//			}
//		}		
		
		for (int i=0; i <m_heightMapSize; i++)
			for (int j=0; j<m_heightMapSize; j++)
				getCenter [i, j] = centers [0];

		
		fillCenters2 ();
		

		
		assignPolygonElevations (htmap);
		
		
		
		call ();
		
		
		//		foreach (Center center in centers)
		//						center.elevation = (center.elevation - heightMinimum) / (heightMaximum - heightMinimum);
		
		assignBiomes ();

		

		//FillAlphaMapByHeights (terrainData,htmap);
		FillAlphaMapByBiomes (terrainData); // postavlja texture
		
		

		m_terrain.transform.position = new Vector3(0, 0, 0); 
		
		
		
		//disable this for better frame rate
		m_terrain.castShadows = false;

		



	}
    void Awake()
    {
        DontDestroyOnLoad(this);
        random = new System.Random(Seed);
        UnityEngine.Random.seed = DataBaseHandler.DataBase.Seed;

        Foliage.Add(Resources.Load<GameObject>("Foliage/Palm"));


        biomes.Add(new Arctic(Resources.Load<Texture2D>("Textures/Arctic_Diff"), Resources.Load<Texture2D>("Textures/Arctic_Norm"), BiomeTypes.Arctic,
            new GameObject[]
            {
                Resources.Load<GameObject>("Foliage/Arctic_Tree1"),
                Resources.Load<GameObject>("Foliage/Arctic_Tree2"),
                Resources.Load<GameObject>("Foliage/Arctic_Tree3"),
                Resources.Load<GameObject>("Foliage/Arctic_Tree4"),
                Resources.Load<GameObject>("Foliage/Arctic_Tree5"),
                Resources.Load<GameObject>("Foliage/Arctic_Tree6"),
                Resources.Load<GameObject>("Foliage/Arctic_Tree7"),
                Resources.Load<GameObject>("Foliage/Arctic_Tree8"),
            },
            new int[]
            {
                5,5,5,5,5,5,5,5,
            }));
        biomes.Add(new BorealForest(Resources.Load<Texture2D>("Textures/BorealForest_Diff"), Resources.Load<Texture2D>("Textures/BorealForest_Norm"), BiomeTypes.BorealForest, 
            new GameObject[]
            {
                Resources.Load<GameObject>("Foliage/BorealForest_Tree1"),
                Resources.Load<GameObject>("Foliage/BorealForest_Tree2"),
                Resources.Load<GameObject>("Foliage/BorealForest_Tree3"),
                Resources.Load<GameObject>("Foliage/BorealForest_Tree4"),
                Resources.Load<GameObject>("Foliage/BorealForest_Tree5"),
            },
            new int[]
            {
                100,100,100,100,100
            }));
        biomes.Add(new Desert(Resources.Load<Texture2D>("Textures/Desert_Diff"), Resources.Load<Texture2D>("Textures/Desert_Norm"), BiomeTypes.Desert,
            new GameObject[]
            {
                Resources.Load<GameObject>("Foliage/Desert_Tree1"),
                Resources.Load<GameObject>("Foliage/Desert_Tree2"),
                Resources.Load<GameObject>("Foliage/Desert_Tree3"),                
            },
            new int[]
            {
                20,20,50,
            }));
        biomes.Add(new Forest(Resources.Load<Texture2D>("Textures/Forest_Diff"), Resources.Load<Texture2D>("Textures/Forest_Norm"), BiomeTypes.Forest, 
            new GameObject[]
            {
                Resources.Load<GameObject>("Foliage/Forest_Tree1"),
                Resources.Load<GameObject>("Foliage/Forest_Tree2"),
                Resources.Load<GameObject>("Foliage/Forest_Tree3"),
                Resources.Load<GameObject>("Foliage/Forest_Tree4"),
                Resources.Load<GameObject>("Foliage/Forest_Tree5"),
                Resources.Load<GameObject>("Foliage/Forest_Tree6"),
                Resources.Load<GameObject>("Foliage/Forest_Tree7"),
                Resources.Load<GameObject>("Foliage/Forest_Tree8"),
                Resources.Load<GameObject>("Foliage/Forest_Tree9"),
                Resources.Load<GameObject>("Foliage/Forest_Tree10"),
                Resources.Load<GameObject>("Foliage/Forest_Tree11"),
                Resources.Load<GameObject>("Foliage/Forest_Tree12"),
                Resources.Load<GameObject>("Foliage/Forest_Tree13"),
                Resources.Load<GameObject>("Foliage/Forest_Tree14"),
                Resources.Load<GameObject>("Foliage/Forest_Tree15"),
                Resources.Load<GameObject>("Foliage/Forest_Tree16"),
                Resources.Load<GameObject>("Foliage/Forest_Tree17"),
                Resources.Load<GameObject>("Foliage/Forest_Tree18"),                
            },
            new int[]
            {
                50,50,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,
            }));
        biomes.Add(new Prairie(Resources.Load<Texture2D>("Textures/Prairie_Diff"), Resources.Load<Texture2D>("Textures/Prairie_Norm"), BiomeTypes.Prairie,            
            new GameObject[]
            {
                Resources.Load<GameObject>("Foliage/Prairie_Tree1"),
                Resources.Load<GameObject>("Foliage/Prairie_Tree2"),
                Resources.Load<GameObject>("Foliage/Prairie_Tree3"),
                Resources.Load<GameObject>("Foliage/Prairie_Tree4"),
                Resources.Load<GameObject>("Foliage/Prairie_Tree5"),
                Resources.Load<GameObject>("Foliage/Prairie_Tree6"),
                Resources.Load<GameObject>("Foliage/Prairie_Tree7"),
                Resources.Load<GameObject>("Foliage/Prairie_Tree8"),
                Resources.Load<GameObject>("Foliage/Prairie_Tree9"),
                Resources.Load<GameObject>("Foliage/Prairie_Tree10"),
                
            },
            new int[]
            {
                200,50,20,20,20,20,100,150,200,200,
            }));
        biomes.Add(new RainForest(Resources.Load<Texture2D>("Textures/RainForest_Diff"), Resources.Load<Texture2D>("Textures/RainForest_Norm"), BiomeTypes.RainForest,
            new GameObject[]
            {
                Resources.Load<GameObject>("Foliage/RainForest_Tree1"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree2"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree3"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree4"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree5"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree6"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree7"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree8"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree9"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree10"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree11"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree12"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree13"),
                Resources.Load<GameObject>("Foliage/RainForest_Tree14"),

            },
            new int[]
            {
                100, 100, 25, 25, 40, 40, 40, 25, 25, 100, 100, 100, 30, 40,
            }));
        biomes.Add(new Savanna(Resources.Load<Texture2D>("Textures/Savanna_Diff"), Resources.Load<Texture2D>("Textures/Savanna_Norm"), BiomeTypes.Savanna,             
            new GameObject[]
            {
                Resources.Load<GameObject>("Foliage/Savanna_Tree1"),
                Resources.Load<GameObject>("Foliage/Savanna_Tree2"),
                Resources.Load<GameObject>("Foliage/Savanna_Tree3"),
                Resources.Load<GameObject>("Foliage/Savanna_Tree4"),
                Resources.Load<GameObject>("Foliage/Savanna_Tree5"),
                Resources.Load<GameObject>("Foliage/Savanna_Tree6"),
                Resources.Load<GameObject>("Foliage/Savanna_Tree7"),
                Resources.Load<GameObject>("Foliage/Savanna_Tree8"),
            },
            new int[]
            {
                25,25,200,10,50,50,100,100,
            }));
        biomes.Add(new Taiga(Resources.Load<Texture2D>("Textures/Taiga_Diff"), Resources.Load<Texture2D>("Textures/Taiga_Norm"), BiomeTypes.Taiga,             
            new GameObject[]
            {
                Resources.Load<GameObject>("Foliage/Taiga_Tree1"),
                Resources.Load<GameObject>("Foliage/Taiga_Tree2"),
                Resources.Load<GameObject>("Foliage/Taiga_Tree3"),
                Resources.Load<GameObject>("Foliage/Taiga_Tree4"),
                Resources.Load<GameObject>("Foliage/Taiga_Tree5"),
                Resources.Load<GameObject>("Foliage/Taiga_Tree6"),
                Resources.Load<GameObject>("Foliage/Taiga_Tree7"),
                Resources.Load<GameObject>("Foliage/Taiga_Tree8"),
            },
            new int[]
            {
                100, 50, 100, 50, 25, 25, 50, 50,
            }));
        biomes.Add(new Tundra(Resources.Load<Texture2D>("Textures/Tundra_Diff"), Resources.Load<Texture2D>("Textures/Tundra_Norm"), BiomeTypes.Tundra,             
            new GameObject[]
            {
                Resources.Load<GameObject>("Foliage/Tundra_Tree1"),                
                Resources.Load<GameObject>("Foliage/Tundra_Tree2"),
                Resources.Load<GameObject>("Foliage/Tundra_Tree3"),
                Resources.Load<GameObject>("Foliage/Tundra_Tree4"),
                Resources.Load<GameObject>("Foliage/Tundra_Tree5"),
                Resources.Load<GameObject>("Foliage/Tundra_Tree6"),
                Resources.Load<GameObject>("Foliage/Tundra_Tree7"),
                Resources.Load<GameObject>("Foliage/Tundra_Tree8"),
                Resources.Load<GameObject>("Foliage/Tundra_Tree9"),
                Resources.Load<GameObject>("Foliage/Tundra_Tree10"),
            },
            new int[]
            {
                10,10,10,10,10,10,10,10,25,25,
            }));
        
        SplatsPrototypes = new SplatPrototype[biomes.Count];
        for (int i = 0; i < biomes.Count; i ++)
        {
            SplatPrototype sp = biomes[i].GetSplatPrototype();
            sp.tileSize = new Vector2(16, 16);
            SplatsPrototypes[i] = sp;
        }
        TreePrototypes = new TreePrototype[Foliage.Count];
        for (int i = 0; i < Foliage.Count; i++)
        {
            TreePrototype tp = new TreePrototype();
            tp.prefab = Foliage[i];
            TreePrototypes[i] = tp;
        }
    }
	//copying textures / details and tree prototypes
	void Terrains()
	{
		EditorUtils.Label("Terrains");
		
		EditorGUILayout.Separator();
		EditorGUILayout.BeginHorizontal();
		
		
		EditorGUILayout.PrefixLabel("Source terrain"); 
		sourceTerrain = EditorGUILayout.ObjectField(sourceTerrain, typeof(TerrainData), true) as TerrainData;
		EditorGUILayout.EndHorizontal();
		
		EditorGUILayout.Separator();
		EditorGUILayout.BeginHorizontal();
			
		EditorGUILayout.PrefixLabel("Target terrain"); 
		targetTerrain = EditorGUILayout.ObjectField(targetTerrain, typeof(TerrainData), true) as TerrainData;
		EditorGUILayout.EndHorizontal();
		
		EditorGUILayout.Separator();
		EditorGUILayout.BeginHorizontal();

        Undo.RegisterUndo(targetTerrain, "Copying trees, details and textures");
        if (GUILayout.Button("Copy trees / details / textures"))
        {
			if (targetTerrain == null || sourceTerrain == null)
				return;
            targetTerrain.detailPrototypes = sourceTerrain.detailPrototypes;
            targetTerrain.treePrototypes = sourceTerrain.treePrototypes;
            targetTerrain.splatPrototypes = sourceTerrain.splatPrototypes;
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Only trees"))
        {
			if (targetTerrain == null || sourceTerrain == null)
				return;
            targetTerrain.treePrototypes = sourceTerrain.treePrototypes;
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Only details"))
        {
			if (targetTerrain == null || sourceTerrain == null)
				return;
            targetTerrain.detailPrototypes = sourceTerrain.detailPrototypes;
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Only textures"))
        {
			if (targetTerrain == null || sourceTerrain == null)
				return;
            targetTerrain.splatPrototypes = sourceTerrain.splatPrototypes;
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Add trees"))
        {
			if (targetTerrain == null || sourceTerrain == null)
				return;
            TreePrototype[] newArray = new TreePrototype[targetTerrain.treePrototypes.Length + sourceTerrain.treePrototypes.Length];

            int currentIndex = 0;
            foreach (TreePrototype tp in targetTerrain.treePrototypes)
            {
                newArray[currentIndex] = tp;
                currentIndex++;
            }

            foreach (TreePrototype tp in sourceTerrain.treePrototypes)
            {
                newArray[currentIndex] = tp;
                currentIndex++;
            }
            targetTerrain.treePrototypes = newArray;
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Add details"))
        {
			if (targetTerrain == null || sourceTerrain == null)
				return;
            DetailPrototype[] newArray = new DetailPrototype[targetTerrain.detailPrototypes.Length + sourceTerrain.detailPrototypes.Length];

            int currentIndex = 0;
            foreach (DetailPrototype tp in targetTerrain.detailPrototypes)
            {
                newArray[currentIndex] = tp;
                currentIndex++;
            }

            foreach (DetailPrototype tp in sourceTerrain.detailPrototypes)
            {
                newArray[currentIndex] = tp;
                currentIndex++;
            }
            targetTerrain.detailPrototypes = newArray;
        }


        EditorGUILayout.EndHorizontal();
	}
    void Awake()
    {
        splat[0] = Resources.Load("Textures/" + "rock_2048") as Texture2D;
        splat[1] = Resources.Load("Textures/" + "forst_1024") as Texture2D;
        splat[2] = Resources.Load("Textures/" + "snow_512") as Texture2D;
        splat[3] = Resources.Load("Textures/" + "GoodDirt") as Texture2D;

        detailTexture[0] = Resources.Load("Details/SimpleGrass/" + "Grass") as Texture2D;
        detailTexture[1] = Resources.Load("Details/SimpleGrass/" + "WhiteFlowers") as Texture2D;

        trees[0] = Resources.Load("Trees/" + "Tree4Master") as GameObject;
        trees[1] = Resources.Load("Trees/" + "Tree5") as GameObject;
        trees[2] = Resources.Load("Trees/" + "Tree4Master") as GameObject;
        trees[3] = Resources.Load("Trees/" + "Bush1") as GameObject;

        Vector2[] splatTileSize = new Vector2[4] { new Vector2(Tile0, Tile0), new Vector2(Tile1, Tile1), new Vector2(Tile2, Tile2), new Vector2(Tile3, Tile3) };
        for (int i = 0; i < numOfSplatPrototypes; i++)
            m_splatPrototypes[i] = new SplatPrototype();

        for (int i = 0; i < numOfSplatPrototypes; i++)
        {
            m_splatPrototypes[i].texture = splat[i];
            m_splatPrototypes[i].tileOffset = Vector2.zero;
            m_splatPrototypes[i].tileSize = splatTileSize[i];
            m_splatPrototypes[i].texture.Apply(true);
        }

        for (int i = 0; i < numOfDetailPrototypes; i++)
        {
            m_detailProtoTypes[i] = new DetailPrototype();
            m_detailProtoTypes[i].prototypeTexture = detailTexture[i];
            m_detailProtoTypes[i].renderMode = detailMode;
            m_detailProtoTypes[i].healthyColor = m_grassHealthyColor;
            m_detailProtoTypes[i].dryColor = m_grassDryColor;
            m_detailProtoTypes[i].maxHeight = 0.5f;
            m_detailProtoTypes[i].maxWidth = 0.2f;
        }
        for (int i = 0; i < numOfTreePrototypes; i++)
        {
            m_treeProtoTypes[i] = new TreePrototype();
            m_treeProtoTypes[i].prefab = trees[i];
        }
        for (int i = 0; i < dim; i++)
        {
            for (int j = 0; j < dim; j++)
            {
                TerrainData terrainData = new TerrainData();

                terrainData.wavingGrassStrength = m_wavingGrassStrength;
                terrainData.wavingGrassAmount = m_wavingGrassAmount;
                terrainData.wavingGrassSpeed = m_wavingGrassSpeed;
                terrainData.wavingGrassTint = m_wavingGrassTint;
                terrainData.heightmapResolution = m_heightMapSize;
                terrainData.size = new Vector3(m_landScapeSize, m_terrainHeight, m_landScapeSize);
                terrainData.alphamapResolution = m_alphaMapSize;
                terrainData.splatPrototypes = m_splatPrototypes;
                terrainData.treePrototypes = m_treeProtoTypes;
                terrainData.SetDetailResolution(m_detailMapSize, m_detailResolutionPerPatch);
                terrainData.detailPrototypes = m_detailProtoTypes;

                m_terrainGrid[i, j] = Terrain.CreateTerrainGameObject(terrainData).GetComponent<Terrain>();
            }
        }

        for (int i = 0; i < dim; i++)
        {
            for (int j = 0; j < dim; j++)
            {
                m_terrainGrid[i, j].gameObject.AddComponent<TerrainScript>();
                m_terrainGrid[i, j].transform.parent = gameObject.transform;

                m_terrainGrid[i, j].transform.position = new Vector3(
                m_terrainGrid[1, 1].transform.position.x + (i - 1) * m_landScapeSize, m_terrainGrid[1, 1].transform.position.y,
                m_terrainGrid[1, 1].transform.position.z + (j - 1) * m_landScapeSize);

                m_terrainGrid[i, j].treeDistance = m_treeDistance;
                m_terrainGrid[i, j].treeBillboardDistance = m_treeBillboardDistance;
                m_terrainGrid[i, j].treeCrossFadeLength = m_treeCrossFadeLength;
                m_terrainGrid[i, j].treeMaximumFullLODCount = m_treeMaximumFullLODCount;

                m_terrainGrid[i, j].detailObjectDensity = m_detailObjectDensity;
                m_terrainGrid[i, j].detailObjectDistance = m_detailObjectDistance;

                m_terrainGrid[i, j].GetComponent<Collider>().enabled = false;
                m_terrainGrid[i, j].basemapDistance = 4000;
                m_terrainGrid[i, j].castShadows = false;

                PatchManager.AddTerrainInfo(curGlobalIndexX + i - 1, curGlobalIndexZ + j - 1, m_terrainGrid[i, j], m_terrainGrid[i, j].transform.position);
            }
        }
        PatchManager.MakePatches();

        int patchCount = PatchManager.patchQueue.Count;
        for(int i = 0; i < patchCount; i++)
            PatchManager.patchQueue.Dequeue().ExecutePatch();

        UpdateIndexes();
        UpdateTerrainNeighbors();

        StartCoroutine(FlushTerrain());
        terrainIsFlushed = true;

        m_terrainGrid[curCyclicIndexX, curCyclicIndexZ].GetComponent<Collider>().enabled = false;
        m_terrainGrid[curCyclicIndexX, curCyclicIndexZ].GetComponent<Collider>().enabled = true;
    }
    void generate()
    {
        width = (int)size.x;
        height = (int)size.y;
        length = (int)size.z;

        perlinCreateArrays(rand);
        for (int i = 0; i < CHUNKS * CHUNKS; i++)
        {
            heightMap[i] = new float[width, length];

        }

        int x = -(CHUNKS / 2);
        int y = -(CHUNKS / 2);

        for (int i = 0; i < CHUNKS * CHUNKS; i++)
        {
            heightMap[i] = generateVoronoi(heightMap[i], new Vector2(width - 1, length - 1), false);
        }

        for (int i = 0; i < CHUNKS; i++)
        {
            for (int j = 0; j < CHUNKS; j++)
            {
                whereIsTerrain[i, j] = new Vector3(x * (width - 1), 0, y * (length - 1));
                heightMap[i * CHUNKS + j] = k_perlin(heightMap[i * CHUNKS + j], width, length, 0.5f, 0, x * (width - 1), y * (length - 1), false);
                m_xOff += width;
                m_zOff += length;
                y++;
                if (i != 0)
                {
                    for (int k = 0; k < length - 1; k++)
                    {
                        heightMap[i * CHUNKS + j][0, k] = heightMap[(i - 1) * CHUNKS + j][length - 1, k];
                    }
                }
                if (j != 0)
                {
                    for (int k = 0; k < length - 1; k++)
                    {
                        heightMap[i * CHUNKS + j][k, 0] = heightMap[i * CHUNKS + (j - 1)][k, length - 1];
                    }
                }
            }
            y = -(CHUNKS / 2);
            x++;
        }

        float[, ,] singlePoint = new float[1, 1, test.Length];
        for (int row = 0; row < CHUNKS; row++)
        {
            for (int col = 0; col < CHUNKS; col++)
            {
                tData[col * CHUNKS + row] = new TerrainData();
                tData[col * CHUNKS + row].heightmapResolution = width;
                tData[col * CHUNKS + row].alphamapResolution = ALPHA_TILE_SIZE;
                tData[col * CHUNKS + row].SetDetailResolution(ALPHA_TILE_SIZE, 16);
                tData[col * CHUNKS + row].baseMapResolution = width - 1 + 1;
                tData[col * CHUNKS + row].SetHeights(0, 0, heightMap[col * CHUNKS + row]);
                tData[col * CHUNKS + row].size = new Vector3(width - 1, height, length - 1);
                tData[col * CHUNKS + row].splatPrototypes = test;
                tData[col * CHUNKS + row].detailPrototypes = setDetails(tData[col * CHUNKS + row]);
                tData[col * CHUNKS + row].SetDetailLayer(0, 0, 0, getDetailLayers(tData[col * CHUNKS + row]));

                TreePrototype[] _treeprotos = new TreePrototype[_treeInstance.Length];
                for (int i = 0; i < _treeInstance.Length; i++)
                {
                    _treeprotos[i] = new TreePrototype();
                    _treeprotos[i].prefab = _treeInstance[i];
                    _treeprotos[i].bendFactor = 1f;
                    _treeprotos[i].prefab.renderer.material.color = Color.white;
                }

                tData[col * CHUNKS + row].treePrototypes = _treeprotos;

                for (int i = 0; i < ALPHA_TILE_SIZE; i++)
                {
                    for (int j = 0; j < ALPHA_TILE_SIZE; j++)
                    {
                        //Texture INDEX.
                        //0 GoodDIrt
                        //1 Grass
                        //2 Grass&Pock
                        //3 Cliff
                        //4 snow1
                        //5 snow2
                        //6 snow3
                        //...end..
                        var CurrentHeight = heightMap[col * CHUNKS + row][i * width / ALPHA_TILE_SIZE, j * length / ALPHA_TILE_SIZE];
                        var blendFactor = (float)rand.NextDouble();
                        #region TEXTURING
                        if (CurrentHeight < 0.2f && CurrentHeight > 0.0f)
                        {
                            singlePoint[0, 0, 0] = blendFactor / 2f;
                            singlePoint[0, 0, 1] = blendFactor / 2f;
                            singlePoint[0, 0, 2] = 1f - blendFactor;
                            singlePoint[0, 0, 3] = 0f;
                            singlePoint[0, 0, 4] = 0f;
                            singlePoint[0, 0, 5] = 0f;
                            singlePoint[0, 0, 6] = 0f;
                        }
                        else
                            if (CurrentHeight < 0.3)
                            {
                                singlePoint[0, 0, 0] = 0f;
                                singlePoint[0, 0, 1] = 0f;
                                singlePoint[0, 0, 2] = 1f;
                                singlePoint[0, 0, 3] = 0f;
                                singlePoint[0, 0, 4] = 0f;
                                singlePoint[0, 0, 5] = 0f;
                                singlePoint[0, 0, 6] = 0f;
                            }
                            else
                                if (CurrentHeight < 0.6)
                                {
                                    singlePoint[0, 0, 0] = 0f;
                                    singlePoint[0, 0, 1] = blendFactor;
                                    singlePoint[0, 0, 2] = 0f;
                                    singlePoint[0, 0, 3] = 1f - blendFactor;
                                    singlePoint[0, 0, 4] = 0f;
                                    singlePoint[0, 0, 5] = 0f;
                                    singlePoint[0, 0, 6] = 0f;
                                }
                                else
                                    if (CurrentHeight < 0.8)
                                    {
                                        singlePoint[0, 0, 0] = 0f;
                                        singlePoint[0, 0, 1] = 0f;
                                        singlePoint[0, 0, 2] = 0f;
                                        singlePoint[0, 0, 3] = 0.1f + blendFactor;
                                        singlePoint[0, 0, 4] = 1f;
                                        singlePoint[0, 0, 5] = 0f;
                                        singlePoint[0, 0, 6] = 0f;
                                    }
                                    else
                                    {
                                        singlePoint[0, 0, 0] = 0f;
                                        singlePoint[0, 0, 1] = 0f;
                                        singlePoint[0, 0, 2] = 0f;
                                        singlePoint[0, 0, 3] = 0f;
                                        singlePoint[0, 0, 4] = 0f;
                                        singlePoint[0, 0, 5] = 0f;
                                        singlePoint[0, 0, 6] = 1f;
                                    }
                        tData[col * CHUNKS + row].SetAlphamaps(j, i, singlePoint);
                        #endregion
                    }
                }
                terrain[row, col] = Terrain.CreateTerrainGameObject(tData[col * CHUNKS + row]);
                terrain[row, col].transform.position = whereIsTerrain[row, col] - new Vector3(2.87f * row, 0, 2.87f * col);
                terrain[row, col].name = (++terrno).ToString();
                terrain[row, col].GetComponent<Terrain>().Flush();
                terrain[row, col].GetComponent<Terrain>().terrainData.RefreshPrototypes();
            }
        }
    }
 extern internal static bool ValidateTreePrototype([NotNull] TreePrototype prototype, out string errorMessage);
Beispiel #22
0
    private void LoadTrees(string xvalue, string yvalue, TerrainData tdata)
    {
        if (_trees.Count > 0)
        {
            System.Collections.Generic.List<TreeInstance> treelist = new System.Collections.Generic.List<TreeInstance>();
            TreePrototype[] prototypes = new TreePrototype[_trees.Count];

            for (int k = 0; k < _trees.Count; k++)
            {
                TreeMapInfo2 tree = _trees[k];
                // Load splatmap file
                string treefile = string.Format(tree.Filemask, xvalue, yvalue);
                string[] treefiles = System.IO.Directory.GetFiles(_imagesPath, treefile + ".*");
                System.Uri uri = new System.Uri(treefiles[0]);
                WWW imageloader = new WWW(uri.AbsoluteUri);
                treefiles = null;

                while (!imageloader.isDone)
                {
                }

                Color[] imagecolors = imageloader.texture.GetPixels();
                int imagewidth = imageloader.texture.width;
                imageloader.Dispose();

                // Create Tree Prototype
                TreePrototype tp = new TreePrototype();
                tp.prefab = tree.Prefab;
                tp.bendFactor = tree.BendFactor;
                prototypes[k] = tp;

                float treefactor = 0;

                for (int u = 0; u < _heightmapsize.x; u++)
                {
                    for (int v = 0; v < _heightmapsize.y; v++)
                    {
                        //if (imagecolors[(((imagewidth - 1) - v) * imagewidth) + u].grayscale >= 0.035)
                        //{
                        // Get treemap resolution / terrain size bias
                        float xbias = _terrainsize.x/imagewidth;
                        float ybias = _terrainsize.z/imagewidth;

                        // Calculate Tree Position
                        float terrainheight = tdata.size.y;
                        float terrainwidth = tdata.size.x;

                        Vector3 treeposition = new Vector3();
                        treeposition.x = (v*xbias)/terrainwidth;
                        treeposition.y = tdata.GetHeight(v, u)/terrainheight;
                        treeposition.z = (u*ybias)/terrainwidth;

                        TreeInstance ti = new TreeInstance();
                        ti.prototypeIndex = k;
                        ti.position = treeposition;
                        ti.lightmapColor = new Color(1, 1, 1);
                        ti.heightScale = (tree.HeightScale/100) +
                                         UnityEngine.Random.Range(-(tree.HeightVariation/100),
                                                                  (tree.HeightVariation/100));
                        ti.widthScale = (tree.WidthScale/100) +
                                        UnityEngine.Random.Range(-(tree.WidthVariation/100), (tree.WidthVariation/100));
                        ti.color = new Color(1, 1, 1);

                        float treestoplace = imagecolors[((imagewidth - 1) - u)*imagewidth + v].r*tree.MaxDensity;
                        treefactor += treestoplace;
                        if (treefactor > (1.0f + UnityEngine.Random.Range(-0.2f, 0.2f)))
                        {
                            treelist.Add(ti);
                            treefactor = 0;
                        }
                    }
                }
            }
            tdata.treePrototypes = prototypes;
            tdata.treeInstances = treelist.ToArray();
            prototypes = null;
            treelist.RemoveRange(0, treelist.Count);
            treelist = null;
            System.GC.Collect(0);

        }
    }
Beispiel #23
0
    void Start()
    {
        noise = new PerlinNoise ();
        noise.baseOctave = noiseBaseOctave;
        noise.weights = noiseWeights;
        noise.Init ();

        chunkResolution = (int)Math.Pow (2, chunkExponent) + 1;
        chunkWidth = chunkResolution * chunkScale;

        chunks = new Hashtable ();
        heightmapQueue = Queue.Synchronized (new Queue ());

        reverseThermalEroder = new ThermalTerrainErosion ();
        reverseThermalEroder.talus = this.reverseErosionTalus;
        reverseThermalEroder.strength = this.reverseErosionStrength;
        reverseThermalEroder.reverse = true;
        reverseThermalEroder.reverseTalusCutoff = this.reverseErosionReverseTalusCutoff;
        reverseThermalEroder.iterations = this.reverseErosionIterations;

        hydraulicEroder = new HydraulicTerrainErosion ();
        hydraulicEroder.rainfallAmount = hydraulicErosionRainfallAmount; // kr
        hydraulicEroder.evaporationRatio = hydraulicErosionEvaporationRatio; // ke
        hydraulicEroder.sedimentCapacity = hydraulicErosionSedimentCapacity; // kc
        hydraulicEroder.soilSolubility = hydraulicErosionSoilSolubility; // ks
        hydraulicEroder.rainAltitude = hydraulicErosionRainAltitude;
        hydraulicEroder.rainFalloff = hydraulicErosionRainFalloff;
        hydraulicEroder.iterations = hydraulicErosionIterations;

        thermalEroder = new ThermalTerrainErosion ();
        thermalEroder.talus = this.thermalErosionTalus;
        thermalEroder.strength = this.thermalErosionStrength;
        thermalEroder.reverse = false;
        thermalEroder.iterations = this.thermalErosionIterations;

        texturer = new Texturer();
        texturer.Init();
        texturer.slopeValue = slopeValue;
        texturer.mountainPeekStart = mountainPeekStart;
        texturer.mountainPeekHeight = mountainPeekHeight;
        texturer.waterHeight = waterHeight;
        texturer.shoreHeight = shoreHeight;
        splats = new SplatPrototype[diffuses.Length];

        texturer.treeHeightFactor = treeHeightFactor;
        texturer.treeStrength = treeStrength;
        treeProto = new TreePrototype[treePrefab.Length];
        for (var i = 0; i < treePrefab.Length; i++) {
            treeProto[i] = new TreePrototype();
            treeProto[i].bendFactor = 0;
            treeProto[i].prefab = treePrefab[i];
        }

        grassPlacer = new GrassPlacement();
        grassPlacer.grassType = grassType;
        grassPlacer.texturesToAffect = texturesToAffect;

        for (var i = 0; i < diffuses.Length; i++) {
            splats[i] = new SplatPrototype();
            splats[i].texture = diffuses[i];
            splats[i].normalMap = normals[i];
            splats[i].tileSize = new Vector2(5, 5);
        }
        grassProto = new DetailPrototype[1];
        grassProto[0] = new DetailPrototype();
        grassProto[0].prototypeTexture = grass;
        grassProto[0].bendFactor = 0.1f;
        grassProto[0].dryColor = new Color(0.804f, 0.737f, 0.102f, 1.000f);
        grassProto[0].healthyColor = new Color(0.263f, 0.976f, 0.165f, 1.000f);
        grassProto[0].maxHeight = 0.5f;
        grassProto[0].minHeight = 0.2f;
        grassProto[0].maxWidth = 1f;
        grassProto[0].minWidth = 0.5f;
        grassProto[0].noiseSpread = 0.1f;
        grassProto[0].prototype = null;
        grassProto[0].renderMode = DetailRenderMode.GrassBillboard;
        grassProto[0].usePrototypeMesh = false;

        ensureChunk(new ChunkCoord(0, 0), false);
        ensureChunk(new ChunkCoord(-1, -1), true);
        ensureChunk(new ChunkCoord(0, -1), true);
        ensureChunk(new ChunkCoord(-1, 0), true);
    }
Beispiel #24
0
    void FillTreeInstances()
    {
        terrain.treeDistance = m_treeDistance;
        terrain.treeBillboardDistance = m_treeBillboardDistance;
        terrain.treeCrossFadeLength = m_treeCrossFadeLength;
        terrain.treeMaximumFullLODCount = m_treeMaximumFullLODCount;

        m_treeProtoTypes = new TreePrototype[2];

        m_treeProtoTypes[0] = new TreePrototype();
        m_treeProtoTypes [0].prefab = m_tree0;

        m_treeProtoTypes [1] = new TreePrototype ();
        m_treeProtoTypes[1].prefab = m_tree1;

        terrain.terrainData.treePrototypes = m_treeProtoTypes;

        PerlinNoise m_treeNoise = new PerlinNoise(Random.Range(0,100));

        //ArrayList instances = new ArrayList();

        for(int x = 0; x < m_terrainSize; x += m_treeSpacing)
        {
            for (int z = 0; z < m_terrainSize; z += m_treeSpacing)
            {

                float unit = 1.0f / (m_terrainSize - 1);

                float offsetX = Random.value * unit * m_treeSpacing;
                float offsetZ = Random.value * unit * m_treeSpacing;

                float normX = x * unit + offsetX;
                float normZ = z * unit + offsetZ;

                // Get the steepness value at the normalized coordinate.
                float angle = terrain.terrainData.GetSteepness(normX, normZ);

                // Steepness is given as an angle, 0..90 degrees. Divide
                // by 90 to get an alpha blending value in the range 0..1.
                float frac = angle / 90.0f;

                if(frac < 0.45f) //make sure tree are not on steep slopes
                {
                    float worldPosX = x;
                    float worldPosZ = z;

                    float noise = m_treeNoise.FractalNoise2D(worldPosX, worldPosZ, 3, m_treeFrq, 1.0f);
                    float ht = terrain.terrainData.GetInterpolatedHeight(normX, normZ);

                    if(noise > 0.0f && ht < m_terrainHeight*0.4f)
                    {

                        TreeInstance temp = new TreeInstance();
                        temp.position = new Vector3(normX,ht,normZ);
                        temp.prototypeIndex = Random.Range (0, 2);
                        temp.widthScale = 1f;
                        temp.heightScale = 1f;
                        temp.color = Color.white;
                        temp.lightmapColor = Color.white;

                        terrain.AddTreeInstance(temp);
                    }
                }

            }
        }

        //terrain.terrainData.treeInstances = (TreeInstance[])instances.ToArray(typeof(TreeInstance));
        terrain.terrainData.SetHeights(0, 0, new float[,] { { } });
        terrain.Flush ();
    }
Beispiel #25
0
    TreePrototype[] treeArray; // Vector de árboles para el mapa.

    #endregion Fields

    #region Methods

    void CreateProtoTypes()
    {
        //Creador de los prototypes, tanto para los splat ( texturas ) como los árboles y los adornos extra

        //ZONA TEXTURAS
        splatArray = new SplatPrototype[4]; // Array de texturas
        //Primera textura, replicar incrementando por cada textura
        splatArray[0] = new SplatPrototype();
        splatArray[0].texture = Textura0;
        splatArray[0].tileSize = new Vector2(pesosplat0, pesosplat0);
        //Fin primera textura
        splatArray[1] = new SplatPrototype();
        splatArray[1].texture = Textura1;
        splatArray[1].tileSize = new Vector2(pesosplat1, pesosplat1);

        splatArray[2] = new SplatPrototype();
        splatArray[2].texture = Textura2;
        splatArray[2].tileSize = new Vector2(pesosplat2, pesosplat2);

        splatArray[3] = new SplatPrototype();
        splatArray[3].texture = Textura3;
        splatArray[3].tileSize = new Vector2(pesosplat3, pesosplat3);
        //******************************

        //ZONA ÁRBOLES
        treeArray = new TreePrototype[3];

        treeArray[0] = new TreePrototype();
        treeArray[0].prefab = Arbol1;

        treeArray[1] = new TreePrototype();
        treeArray[1].prefab = Arbol2;

        treeArray[2] = new TreePrototype();
        treeArray[2].prefab = Arbol3;
        //*************************************************

        //ZONA HIERBA
        detailArray = new DetailPrototype[3];

        detailArray[0] = new DetailPrototype();
        detailArray[0].prototypeTexture = detalle1;
        detailArray[0].renderMode = EstiloDeDetallado;
        detailArray[0].healthyColor = color_hierba;
        detailArray[0].dryColor = color_hierba2;

        detailArray[1] = new DetailPrototype();
        detailArray[1].prototypeTexture = detalle2;
        detailArray[1].renderMode = EstiloDeDetallado;
        detailArray[1].healthyColor = color_hierba;
        detailArray[1].dryColor = color_hierba2;

        detailArray[2] = new DetailPrototype();
        detailArray[2].prototypeTexture = detalle3;
        detailArray[2].renderMode = EstiloDeDetallado;
        detailArray[2].healthyColor = color_hierba;
        detailArray[2].dryColor = color_hierba2;
        //**************************************************************
    }
	void CreateProtoTypes()
	{
		//Ive hard coded 2 splat prototypes, 3 tree prototypes and 3 detail prototypes.
		//This is a little inflexible way to do it but it made the code simpler and can easly be modified 
		
		m_splatPrototypes = new SplatPrototype[2];
		
		m_splatPrototypes[0] = new SplatPrototype();
		m_splatPrototypes[0].texture = m_splat0;
		m_splatPrototypes[0].tileSize = new Vector2(m_splatTileSize0, m_splatTileSize0);
		
		m_splatPrototypes[1] = new SplatPrototype();
		m_splatPrototypes[1].texture = m_splat1;
		m_splatPrototypes[1].tileSize = new Vector2(m_splatTileSize1, m_splatTileSize1);
		
		m_treeProtoTypes = new TreePrototype[3];
		
		m_treeProtoTypes[0] = new TreePrototype();
		m_treeProtoTypes[0].prefab = m_tree0;
		
		m_treeProtoTypes[1] = new TreePrototype();
		m_treeProtoTypes[1].prefab = m_tree1;
		
		m_treeProtoTypes[2] = new TreePrototype();
		m_treeProtoTypes[2].prefab = m_tree2;
		
		m_detailProtoTypes = new DetailPrototype[3];

		m_detailProtoTypes[0] = new DetailPrototype();
		m_detailProtoTypes[0].prototypeTexture = m_detail0;
		m_detailProtoTypes[0].renderMode = detailMode;
		m_detailProtoTypes[0].healthyColor = m_grassHealthyColor;
		m_detailProtoTypes[0].dryColor = m_grassDryColor;
		
		m_detailProtoTypes[1] = new DetailPrototype();
		m_detailProtoTypes[1].prototypeTexture = m_detail1;
		m_detailProtoTypes[1].renderMode = detailMode;
		m_detailProtoTypes[1].healthyColor = m_grassHealthyColor;
		m_detailProtoTypes[1].dryColor = m_grassDryColor;
		
		m_detailProtoTypes[2] = new DetailPrototype();
		m_detailProtoTypes[2].prototypeTexture = m_detail2;
		m_detailProtoTypes[2].renderMode = detailMode;
		m_detailProtoTypes[2].healthyColor = m_grassHealthyColor;
		m_detailProtoTypes[2].dryColor = m_grassDryColor;

		
	}
	private void fillPrototypes(){
		
		for (int i= 0; i < textures.Length ; i++) {
			
			SplatPrototype splatPrototype = new SplatPrototype();
			splatPrototype.texture = textures[i];
			splatPrototype.tileSize = new Vector2 (2, 2);
			
			texturePrototypes.Add( splatPrototype);
			
		}

		for (int i= 0; i < trees.Length ; i++) {
			
			TreePrototype treePrototype = new TreePrototype();
			treePrototype.prefab = trees[i];
			
			treePrototypes.Add( treePrototype);
			
		}

		for (int i=0; i< details.Length; i++) {
		
			DetailPrototype detailPrototype = new DetailPrototype();
			detailPrototype.prototypeTexture = details[i];
			detailPrototype.renderMode = detailMode;
			detailPrototype.healthyColor = m_grassHealthyColor;
			detailPrototype.dryColor = m_grassDryColor;

			detailPrototypes.Add (detailPrototype);
		}

	}
 public bool treeDataCreated()
 {
     int noOfTreePrefabs = treePrefabs.Length;
     treePrototypes = new TreePrototype[noOfTreePrefabs];
     for (int i=0; i<noOfTreePrefabs; i++) {
         treePrototypes[i] = new TreePrototype();
         treePrototypes[i].prefab = treePrefabs[i];
     }
     return true;
 }
 public TreePrototype(TreePrototype other)
 {
     prefab     = other.prefab;
     bendFactor = other.bendFactor;
 }
	/**
	 * Ajoute les arbres sur le Terrain.
	 */
	void AddTrees(){
		//Check if tree is necessary
		float percentage = ((float)GroundManager.NB_GRASSHILL / (float)(tData.alphamapHeight * tData.alphamapWidth));
		//Debug.Log("Pourcentage texture herbe : " + percentage);
		//Debug.Log("Nb textures herbes : " + GroundManager.NB_GRASSHILL);
		if(percentage < season.seasons[season.CurrentSeason].trees.treeProbability){
			return;
		}
		
		// Ajout des arbres au Terrain
		TreePrototype[] treesProto = new TreePrototype[season.seasons[season.CurrentSeason].trees.treesGamobject.Length]; 
		
		for(int i = 0 ; i < season.seasons[season.CurrentSeason].trees.treesGamobject.Length ; i++){
			treesProto[i] = new TreePrototype(); 
			treesProto[i].prefab = season.seasons[season.CurrentSeason].trees.treesGamobject[i];
		}

		tData.treePrototypes = treesProto;

		int nbTrees = Mathf.FloorToInt((Random.Range(season.seasons[season.CurrentSeason].trees.minTree, season.seasons[season.CurrentSeason].trees.maxTree) / 100f) * GroundManager.NB_GRASSHILL);
		//Debug.Log("NBTREES : " + nbTrees);

		treeInstances = new TreeInstance[nbTrees];

		for(int i = 0 ; i < nbTrees ; i++){

			int xPos = 0;
			int zPos = 0;
			int index = 0;
			do{
				xPos = Random.Range(0, hMap.width);
				zPos = Random.Range(0, hMap.height);

				index++;
			}while((tData.GetHeight (zPos,xPos) < season.seasons[season.CurrentSeason].textures[Texture.GRASSHILL].minHeight || tData.GetHeight (zPos,xPos) > season.seasons[season.CurrentSeason].textures[Texture.GRASSHILL].maxHeight) && index < 1000);

			if(index >= 1000){
				i--;
				continue;
			}

			float yPos = tData.GetHeight (zPos,xPos);
			Vector3 position = new Vector3(zPos, yPos, xPos); 

			position = new Vector3(position.x / hMap.width, position.y / tData.size.y, position.z / hMap.height);

			treeInstances[i].position = position;
			treeInstances[i].widthScale = 0;
			treeInstances[i].heightScale = 0;
			treeInstances[i].color = Color.white;
			treeInstances[i].lightmapColor = Color.white;
			treeInstances[i].prototypeIndex = Random.Range(0, season.seasons[season.CurrentSeason].trees.treesGamobject.Length);
		}

		tData.treeInstances = treeInstances;

		StartCoroutine(GrowTrees());
	}
Beispiel #31
0
    /// <summary>
    /// Prototypes are used by Unity internally.
    /// This method must be called explicitly prior to generation, if any related variables changed.
    /// </summary>
    public void CreateProtoTypes()
    {
        m_splatPrototypes = new SplatPrototype[m_splatMapSettings.Length];

        for (var i = 0; i < m_splatMapSettings.Length; ++i) {
            m_splatPrototypes[i] = new SplatPrototype{
                texture = m_splatMapSettings[i].texture,
                tileSize = m_splatMapSettings[i].tileSize,
                tileOffset = m_splatMapSettings[i].tileOffset
            };
        }

        if (m_treeObjects == null) {
            m_treeObjects = new GameObject[0];
        }
        m_treeProtoTypes = new TreePrototype[m_treeObjects.Length];

        for (var i = 0; i < m_treeObjects.Length; ++i) {
            m_treeProtoTypes[i] = new TreePrototype();
            m_treeProtoTypes[i].prefab = m_treeObjects[i];
        }

        m_detailProtoTypes = new DetailPrototype[m_detailTextures.Length];

        for (var i = 0; i < m_detailTextures.Length; ++i) {
            m_detailProtoTypes[i] = new DetailPrototype();
            m_detailProtoTypes[i].prototypeTexture = m_detailTextures[i];
            m_detailProtoTypes[i].renderMode = m_detailMode;
            m_detailProtoTypes[i].healthyColor = m_grassHealthyColor;
            m_detailProtoTypes[i].dryColor = m_grassDryColor;
        }
    }
Beispiel #32
0
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.TreePrototype treePrototype = (UnityEngine.TreePrototype)value;
     writer.WriteProperty("prefab", treePrototype.prefab);
     writer.WriteProperty("bendFactor", treePrototype.bendFactor);
 }