private bool Equals(DetailPrototype other)
        {
            if (ReferenceEquals(other, null))
            {
                return(false);
            }

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

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

            bool equals = m_Prototype == other.m_Prototype &&
                          m_PrototypeTexture == other.m_PrototypeTexture &&
                          m_HealthyColor == other.m_HealthyColor &&
                          m_DryColor == other.m_DryColor &&
                          m_MinWidth == other.m_MinWidth &&
                          m_MaxWidth == other.m_MaxWidth &&
                          m_MinHeight == other.m_MinHeight &&
                          m_MaxHeight == other.m_MaxHeight &&
                          m_NoiseSpread == other.m_NoiseSpread &&
                          m_BendFactor == other.m_BendFactor &&
                          m_RenderMode == other.m_RenderMode &&
                          m_UsePrototypeMesh == other.m_UsePrototypeMesh;

            return(equals);
        }
        private bool Equals(DetailPrototype other)
        {
            if (ReferenceEquals(other, null))
            {
                return(false);
            }

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

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

            return(m_Prototype == other.m_Prototype &&
                   m_PrototypeTexture == other.m_PrototypeTexture &&
                   m_HealthyColor == other.m_HealthyColor &&
                   m_DryColor == other.m_DryColor &&
                   m_MinWidth == other.m_MinWidth &&
                   m_MaxWidth == other.m_MaxWidth &&
                   m_MinHeight == other.m_MinHeight &&
                   m_MaxHeight == other.m_MaxHeight &&
                   m_NoiseSeed == other.m_NoiseSeed &&
                   m_NoiseSpread == other.m_NoiseSpread &&
                   m_HoleEdgePadding == other.m_HoleEdgePadding &&
                   m_RenderMode == other.m_RenderMode &&
                   m_UsePrototypeMesh == other.m_UsePrototypeMesh &&
                   m_UseInstancing == other.m_UseInstancing);
        }
 private void DoApply()
 {
   if ((UnityEngine.Object) this.terrainData == (UnityEngine.Object) null)
     return;
   DetailPrototype[] detailPrototypeArray1 = this.m_Terrain.terrainData.detailPrototypes;
   if (this.m_PrototypeIndex == -1)
   {
     DetailPrototype[] detailPrototypeArray2 = new DetailPrototype[detailPrototypeArray1.Length + 1];
     Array.Copy((Array) detailPrototypeArray1, 0, (Array) detailPrototypeArray2, 0, detailPrototypeArray1.Length);
     this.m_PrototypeIndex = detailPrototypeArray1.Length;
     detailPrototypeArray1 = detailPrototypeArray2;
     detailPrototypeArray1[this.m_PrototypeIndex] = new DetailPrototype();
   }
   detailPrototypeArray1[this.m_PrototypeIndex].prototype = (GameObject) null;
   detailPrototypeArray1[this.m_PrototypeIndex].prototypeTexture = this.m_DetailTexture;
   detailPrototypeArray1[this.m_PrototypeIndex].minWidth = this.m_MinWidth;
   detailPrototypeArray1[this.m_PrototypeIndex].maxWidth = this.m_MaxWidth;
   detailPrototypeArray1[this.m_PrototypeIndex].minHeight = this.m_MinHeight;
   detailPrototypeArray1[this.m_PrototypeIndex].maxHeight = this.m_MaxHeight;
   detailPrototypeArray1[this.m_PrototypeIndex].noiseSpread = this.m_NoiseSpread;
   detailPrototypeArray1[this.m_PrototypeIndex].healthyColor = this.m_HealthyColor;
   detailPrototypeArray1[this.m_PrototypeIndex].dryColor = this.m_DryColor;
   detailPrototypeArray1[this.m_PrototypeIndex].renderMode = !this.m_Billboard ? DetailRenderMode.Grass : DetailRenderMode.GrassBillboard;
   detailPrototypeArray1[this.m_PrototypeIndex].usePrototypeMesh = false;
   this.m_Terrain.terrainData.detailPrototypes = detailPrototypeArray1;
   EditorUtility.SetDirty((UnityEngine.Object) this.m_Terrain);
 }
Esempio n. 4
0
        private bool Equals(DetailPrototype 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.m_Prototype == other.m_Prototype && this.m_PrototypeTexture == other.m_PrototypeTexture && this.m_HealthyColor == other.m_HealthyColor && this.m_DryColor == other.m_DryColor && this.m_MinWidth == other.m_MinWidth && this.m_MaxWidth == other.m_MaxWidth && this.m_MinHeight == other.m_MinHeight && this.m_MaxHeight == other.m_MaxHeight && this.m_NoiseSpread == other.m_NoiseSpread && this.m_HoleEdgePadding == other.m_HoleEdgePadding && this.m_RenderMode == other.m_RenderMode && this.m_UsePrototypeMesh == other.m_UsePrototypeMesh;
                        result = flag4;
                    }
                }
            }
            return(result);
        }
		internal void InitializeDefaults(Terrain terrain, int index)
		{
			this.m_Terrain = terrain;
			this.m_PrototypeIndex = index;
			DetailPrototype detailPrototype;
			if (this.m_PrototypeIndex == -1)
			{
				detailPrototype = new DetailPrototype();
				detailPrototype.renderMode = DetailRenderMode.GrassBillboard;
			}
			else
			{
				detailPrototype = this.m_Terrain.terrainData.detailPrototypes[this.m_PrototypeIndex];
			}
			this.m_DetailTexture = detailPrototype.prototypeTexture;
			this.m_MinWidth = detailPrototype.minWidth;
			this.m_MaxWidth = detailPrototype.maxWidth;
			this.m_MinHeight = detailPrototype.minHeight;
			this.m_MaxHeight = detailPrototype.maxHeight;
			this.m_NoiseSpread = detailPrototype.noiseSpread;
			this.m_HealthyColor = detailPrototype.healthyColor;
			this.m_DryColor = detailPrototype.dryColor;
			this.m_Billboard = (detailPrototype.renderMode == DetailRenderMode.GrassBillboard);
			this.OnWizardUpdate();
		}
		private void DoApply()
		{
			if (base.terrainData == null)
			{
				return;
			}
			DetailPrototype[] array = this.m_Terrain.terrainData.detailPrototypes;
			if (this.m_PrototypeIndex == -1)
			{
				DetailPrototype[] array2 = new DetailPrototype[array.Length + 1];
				Array.Copy(array, 0, array2, 0, array.Length);
				this.m_PrototypeIndex = array.Length;
				array = array2;
				array[this.m_PrototypeIndex] = new DetailPrototype();
			}
			array[this.m_PrototypeIndex].prototype = null;
			array[this.m_PrototypeIndex].prototypeTexture = this.m_DetailTexture;
			array[this.m_PrototypeIndex].minWidth = this.m_MinWidth;
			array[this.m_PrototypeIndex].maxWidth = this.m_MaxWidth;
			array[this.m_PrototypeIndex].minHeight = this.m_MinHeight;
			array[this.m_PrototypeIndex].maxHeight = this.m_MaxHeight;
			array[this.m_PrototypeIndex].noiseSpread = this.m_NoiseSpread;
			array[this.m_PrototypeIndex].healthyColor = this.m_HealthyColor;
			array[this.m_PrototypeIndex].dryColor = this.m_DryColor;
			array[this.m_PrototypeIndex].renderMode = ((!this.m_Billboard) ? DetailRenderMode.Grass : DetailRenderMode.GrassBillboard);
			array[this.m_PrototypeIndex].usePrototypeMesh = false;
			this.m_Terrain.terrainData.detailPrototypes = array;
			EditorUtility.SetDirty(this.m_Terrain);
		}
Esempio n. 7
0
	public Color dryColor = new Color(0.5f, 0.4f, 0.2f); // brownish
	/// <summary>
	/// Create a DetailPrototype from the tree properties
	/// </summary>
	/// <returns>
	/// A <see cref="DetailPrototype"/>
	/// </returns>
	public DetailPrototype ToDetailPrototype()
	{
		DetailPrototype dp = new DetailPrototype();
		dp.prototypeTexture = prototypeTexture;
		dp.minWidth = minWidth;
		dp.maxWidth = maxWidth;
		dp.minHeight = minHeight;
		dp.maxHeight = maxHeight;
		dp.noiseSpread = noiseSpread;
		dp.healthyColor = healthyColor;
		dp.dryColor = dryColor;
		dp.renderMode = DetailRenderMode.GrassBillboard;
		return dp;
	}
Esempio n. 8
0
 public DetailPrototype(DetailPrototype other)
 {
     this.m_Prototype        = other.m_Prototype;
     this.m_PrototypeTexture = other.m_PrototypeTexture;
     this.m_HealthyColor     = other.m_HealthyColor;
     this.m_DryColor         = other.m_DryColor;
     this.m_MinWidth         = other.m_MinWidth;
     this.m_MaxWidth         = other.m_MaxWidth;
     this.m_MinHeight        = other.m_MinHeight;
     this.m_MaxHeight        = other.m_MaxHeight;
     this.m_NoiseSpread      = other.m_NoiseSpread;
     this.m_HoleEdgePadding  = other.m_HoleEdgePadding;
     this.m_RenderMode       = other.m_RenderMode;
     this.m_UsePrototypeMesh = other.m_UsePrototypeMesh;
 }
 public DetailPrototype(DetailPrototype other)
 {
     m_Prototype        = other.m_Prototype;
     m_PrototypeTexture = other.m_PrototypeTexture;
     m_HealthyColor     = other.m_HealthyColor;
     m_DryColor         = other.m_DryColor;
     m_MinWidth         = other.m_MinWidth;
     m_MaxWidth         = other.m_MaxWidth;
     m_MinHeight        = other.m_MinHeight;
     m_MaxHeight        = other.m_MaxHeight;
     m_NoiseSpread      = other.m_NoiseSpread;
     m_BendFactor       = other.m_BendFactor;
     m_RenderMode       = other.m_RenderMode;
     m_UsePrototypeMesh = other.m_UsePrototypeMesh;
 }
 /// <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.DetailPrototype detailPrototype = (UnityEngine.DetailPrototype)value;
     writer.WriteProperty("prototype", detailPrototype.prototype);
     writer.WriteProperty("prototypeTexture", detailPrototype.prototypeTexture);
     writer.WriteProperty("minWidth", detailPrototype.minWidth);
     writer.WriteProperty("maxWidth", detailPrototype.maxWidth);
     writer.WriteProperty("minHeight", detailPrototype.minHeight);
     writer.WriteProperty("maxHeight", detailPrototype.maxHeight);
     writer.WriteProperty("noiseSpread", detailPrototype.noiseSpread);
     writer.WriteProperty("bendFactor", detailPrototype.bendFactor);
     writer.WriteProperty("healthyColor", detailPrototype.healthyColor);
     writer.WriteProperty("dryColor", detailPrototype.dryColor);
     writer.WriteProperty("renderMode", detailPrototype.renderMode);
     writer.WriteProperty("usePrototypeMesh", detailPrototype.usePrototypeMesh);
 }
 public DetailPrototype(DetailPrototype other)
 {
     m_Prototype        = other.m_Prototype;
     m_PrototypeTexture = other.m_PrototypeTexture;
     m_HealthyColor     = other.m_HealthyColor;
     m_DryColor         = other.m_DryColor;
     m_MinWidth         = other.m_MinWidth;
     m_MaxWidth         = other.m_MaxWidth;
     m_MinHeight        = other.m_MinHeight;
     m_MaxHeight        = other.m_MaxHeight;
     m_NoiseSeed        = other.m_NoiseSeed;
     m_NoiseSpread      = other.m_NoiseSpread;
     m_HoleEdgePadding  = other.m_HoleEdgePadding;
     m_RenderMode       = other.m_RenderMode;
     m_UsePrototypeMesh = other.m_UsePrototypeMesh;
     m_UseInstancing    = other.m_UseInstancing;
 }
Esempio n. 12
0
 public DetailPrototype(DetailPrototype other)
 {
     m_Prototype           = other.m_Prototype;
     m_PrototypeTexture    = other.m_PrototypeTexture;
     m_HealthyColor        = other.m_HealthyColor;
     m_DryColor            = other.m_DryColor;
     m_MinWidth            = other.m_MinWidth;
     m_MaxWidth            = other.m_MaxWidth;
     m_MinHeight           = other.m_MinHeight;
     m_MaxHeight           = other.m_MaxHeight;
     m_NoiseSeed           = other.m_NoiseSeed;
     m_NoiseSpread         = other.m_NoiseSpread;
     m_Density             = other.m_Density;
     m_HoleEdgePadding     = other.m_HoleEdgePadding;
     m_RenderMode          = other.m_RenderMode;
     m_UsePrototypeMesh    = other.m_UsePrototypeMesh;
     m_UseInstancing       = other.m_UseInstancing;
     m_AlignToGround       = other.m_AlignToGround;
     m_PositionOrderliness = other.m_PositionOrderliness;
 }
Esempio n. 13
0
	/// <summary>
	/// Clone TerrainData object
	/// </summary>
	/// <param name="source">
	/// A <see cref="TerrainData"/>
	/// </param>
	/// <param name="detailResolutionPerPatch">
	/// A <see cref="System.Int32"/>
	/// </param>
	/// <returns>
	/// A <see cref="TerrainData"/>
	/// </returns>
	public static TerrainData Clone(TerrainData source, int detailResolutionPerPatch)
	{
		TerrainData dest = new TerrainData();
		dest.alphamapResolution = source.alphamapResolution;
		dest.baseMapResolution = source.baseMapResolution;
		dest.SetDetailResolution(source.detailResolution, detailResolutionPerPatch);
		DetailPrototype[] dp = new DetailPrototype[source.detailPrototypes.Length];
		for (int i=0; i<dp.Length; i++) dp[i] = new DetailPrototype();
		dest.detailPrototypes = dp;
		for (int i=0; i<dp.Length; i++)
		{
			dest.detailPrototypes[i].bendFactor =			source.detailPrototypes[i].bendFactor;
			dest.detailPrototypes[i].dryColor =			source.detailPrototypes[i].dryColor;
			dest.detailPrototypes[i].healthyColor =		source.detailPrototypes[i].healthyColor;
			dest.detailPrototypes[i].maxHeight =			source.detailPrototypes[i].maxHeight;
			dest.detailPrototypes[i].maxWidth =			source.detailPrototypes[i].maxWidth;
			dest.detailPrototypes[i].minHeight =			source.detailPrototypes[i].minHeight;
			dest.detailPrototypes[i].minWidth =			source.detailPrototypes[i].minWidth;
			dest.detailPrototypes[i].noiseSpread =			source.detailPrototypes[i].noiseSpread;
			dest.detailPrototypes[i].prototype =			source.detailPrototypes[i].prototype;
			dest.detailPrototypes[i].prototypeTexture =	source.detailPrototypes[i].prototypeTexture;
			dest.detailPrototypes[i].renderMode =			source.detailPrototypes[i].renderMode;
			dest.detailPrototypes[i].usePrototypeMesh =	source.detailPrototypes[i].usePrototypeMesh;
			dest.SetDetailLayer(0,0,i,source.GetDetailLayer(0,0,source.detailWidth,source.detailHeight,i));
		}
		dest.RefreshPrototypes();
		dest.heightmapResolution = source.heightmapResolution;
		dest.SetHeights(0,0,source.GetHeights(0,0,source.heightmapWidth,source.heightmapHeight));
		dest.hideFlags = source.hideFlags;
		dest.name = source.name+" (Clone)";
		dest.size = source.size;
		dest.splatPrototypes = source.splatPrototypes;
		dest.treeInstances = source.treeInstances;
		dest.treePrototypes = source.treePrototypes;
		dest.wavingGrassAmount = source.wavingGrassAmount;
		dest.wavingGrassSpeed = source.wavingGrassSpeed;
		dest.wavingGrassStrength = source.wavingGrassStrength;
		dest.wavingGrassTint = source.wavingGrassTint;
		return dest;
	}
        internal void InitializeDefaults(Terrain terrain, int index)
        {
            DetailPrototype prototype;
            base.m_Terrain = terrain;
            this.m_PrototypeIndex = index;
            if (this.m_PrototypeIndex == -1)
            {
                prototype = new DetailPrototype();
            }
            else
            {
                prototype = base.m_Terrain.terrainData.detailPrototypes[this.m_PrototypeIndex];
            }
            this.m_Detail = prototype.prototype;
            this.m_NoiseSpread = prototype.noiseSpread;
            this.m_MinWidth = prototype.minWidth;
            this.m_MaxWidth = prototype.maxWidth;
            this.m_MinHeight = prototype.minHeight;
            this.m_MaxHeight = prototype.maxHeight;
            this.m_HealthyColor = prototype.healthyColor;
            this.m_DryColor = prototype.dryColor;
            switch (prototype.renderMode)
            {
                case DetailRenderMode.GrassBillboard:
                    Debug.LogError("Detail meshes can't be rendered as billboards");
                    this.m_RenderMode = DetailMeshRenderMode.Grass;
                    break;

                case DetailRenderMode.Grass:
                    this.m_RenderMode = DetailMeshRenderMode.Grass;
                    break;

                case DetailRenderMode.VertexLit:
                    this.m_RenderMode = DetailMeshRenderMode.VertexLit;
                    break;
            }
            this.OnWizardUpdate();
        }
 private void DoApply()
 {
     if (base.terrainData != null)
     {
         DetailPrototype[] detailPrototypes = base.m_Terrain.terrainData.detailPrototypes;
         if (this.m_PrototypeIndex == -1)
         {
             DetailPrototype[] destinationArray = new DetailPrototype[detailPrototypes.Length + 1];
             Array.Copy(detailPrototypes, 0, destinationArray, 0, detailPrototypes.Length);
             this.m_PrototypeIndex = detailPrototypes.Length;
             detailPrototypes = destinationArray;
             detailPrototypes[this.m_PrototypeIndex] = new DetailPrototype();
         }
         detailPrototypes[this.m_PrototypeIndex].renderMode = DetailRenderMode.VertexLit;
         detailPrototypes[this.m_PrototypeIndex].usePrototypeMesh = true;
         detailPrototypes[this.m_PrototypeIndex].prototype = this.m_Detail;
         detailPrototypes[this.m_PrototypeIndex].prototypeTexture = null;
         detailPrototypes[this.m_PrototypeIndex].noiseSpread = this.m_NoiseSpread;
         detailPrototypes[this.m_PrototypeIndex].minWidth = this.m_MinWidth;
         detailPrototypes[this.m_PrototypeIndex].maxWidth = this.m_MaxWidth;
         detailPrototypes[this.m_PrototypeIndex].minHeight = this.m_MinHeight;
         detailPrototypes[this.m_PrototypeIndex].maxHeight = this.m_MaxHeight;
         detailPrototypes[this.m_PrototypeIndex].healthyColor = this.m_HealthyColor;
         detailPrototypes[this.m_PrototypeIndex].dryColor = this.m_DryColor;
         if (this.m_RenderMode == DetailMeshRenderMode.Grass)
         {
             detailPrototypes[this.m_PrototypeIndex].renderMode = DetailRenderMode.Grass;
         }
         else
         {
             detailPrototypes[this.m_PrototypeIndex].renderMode = DetailRenderMode.VertexLit;
         }
         base.m_Terrain.terrainData.detailPrototypes = detailPrototypes;
         EditorUtility.SetDirty(base.m_Terrain);
     }
 }
Esempio n. 16
0
    public static void GenerateGrass()
    {
        Terrain t = Terrain.activeTerrain;
        TerrainData td = t.terrainData;

        if (grassDensity == 0)
        {
            grassDensity = 5;
        }

        DetailPrototype[] detailPrototypes = new DetailPrototype[2];

        detailPrototypes[0] = new DetailPrototype() { prototypeTexture = Resources.Load("Grass") as Texture2D };
        detailPrototypes[1] = new DetailPrototype() { prototypeTexture = Resources.Load("Grass2") as Texture2D };

        td.detailPrototypes = detailPrototypes;

        for (int i = 0; i < td.detailPrototypes.Length; i++)
        {
            int[,] detailLayer = td.GetDetailLayer(0, 0, td.detailWidth, td.detailHeight, i);

            float x = 0.0f;
            while (x < td.detailWidth)
            {
                float y = 0.0f;
                while (y < td.detailHeight)
                {
                    detailLayer[(int)x, (int)y] = 10;
                    y++;
                }
                x++;
            }

            td.SetDetailLayer(0, 0, i, detailLayer);
        }   
    }
Esempio n. 17
0
	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;

		
	}
	/**
	 * Initialise les détails du Terrain.
	 */
	void InitDetails(){
		DetailPrototype[] detailProto = new DetailPrototype[0]; 
		tData.detailPrototypes = detailProto;
	}
Esempio n. 19
0
 internal static extern bool ValidateDetailPrototype([NotNull("ArgumentNullException")] DetailPrototype prototype, out string errorMessage);
Esempio n. 20
0
        public bool Validate()
        {
            string text;

            return(DetailPrototype.ValidateDetailPrototype(this, out text));
        }
Esempio n. 21
0
	public void AddNewDetailLayer(){
		if ( currentTerrainInstance != null ){
			DetailPrototype[] details = currentTerrainInstance.terrainData.detailPrototypes;
			DetailPrototype[] newDetails = new DetailPrototype[details.Length+1];
			for ( int i = 0; i < details.Length; i++ ){
				newDetails[i] = details[i];
			}
			newDetails[newDetails.Length-1] = new DetailPrototype();
			currentTerrainInstance.terrainData.detailPrototypes = newDetails;
			int[,] newDetailmap = new int[currentTerrainInstance.terrainData.detailWidth, currentTerrainInstance.terrainData.detailHeight];
			for ( int i = 0; i < currentTerrainInstance.terrainData.detailWidth; i++ ){
				for ( int j = 0; j < currentTerrainInstance.terrainData.detailHeight; j++ ){	
					newDetailmap[i,j] = 0;
				}
			}
			currentTerrainInstance.terrainData.SetDetailLayer( 0, 0, newDetails.Length-1, newDetailmap );
			
			if ( m_CurrentDetailLayerSet.Count < newDetails.Length ){
				DetailLayer newLayer = new DetailLayer();
				List<string> bundleList = new List<string>(m_LoadedVegetation.Keys);
				if ( bundleList.Count > 0 ){
					List<string> imageList = new List<string>(m_LoadedVegetation[bundleList[0]].Keys);
					newLayer.path = bundleList[0] + "/" + imageList[0];
					newLayer.image = m_LoadedVegetation[bundleList[0]][imageList[0]];
				}
				m_CurrentDetailLayerSet.Add ( newLayer );	
			}
		} else {
			DetailLayer newLayer = new DetailLayer();
			List<string> bundleList = new List<string>(m_LoadedVegetation.Keys);
			if ( bundleList.Count > 0 ){
				List<string> imageList = new List<string>(m_LoadedVegetation[bundleList[0]].Keys);
				newLayer.path = bundleList[0] + "/" + imageList[0];
				newLayer.image = m_LoadedVegetation[bundleList[0]][imageList[0]];
			}
			m_CurrentDetailLayerSet.Add ( newLayer );
		}
	}
 /// <summary>
 /// Read the data using the reader.
 /// </summary>
 /// <param name="reader">Reader.</param>
 public override object Read(ISaveGameReader reader)
 {
     UnityEngine.DetailPrototype detailPrototype = new UnityEngine.DetailPrototype();
     ReadInto(detailPrototype, reader);
     return(detailPrototype);
 }
Esempio n. 23
0
 private void CancelPrototypeEditor()
 {
     m_detailContainer = null;
     m_detailAddMenu = EditWindow.None;
 }
Esempio n. 24
0
 private void CostomizeButtonsEditor()
 {
     EditorGUILayout.BeginHorizontal();
     FlexibleSpace(5);
     if (GUILayout.Button(new GUIContent("add", "Add new detail")))
     {
         m_detailContainer = DefaultPrototype;
         m_detailAddMenu = EditWindow.Add;
     }
     int canEdit = -1;
     for (int i = 0; i < component.TerrainData.detailPrototypes.Length; i++) { if (component.Foliages.IsSelected(i)) { canEdit++; } }
     GUI.enabled = canEdit == 0;
     if (GUILayout.Button(new GUIContent("edit", "Edit current selected detail")))
     {
         for (int i = 0; i < component.TerrainData.detailPrototypes.Length; i++)
         {
             if (component.Foliages.IsSelected(i))
             {
                 m_detailContainer = component.TerrainData.detailPrototypes[i];
                 break;
             }
         }
         m_detailAddMenu = EditWindow.Edit;
     }
     GUI.enabled = canEdit >= 0;
     if (GUILayout.Button(new GUIContent("remove", "remove current selected " + (canEdit > 0 ? "textures" : "texture"))))
     {
         m_detailAddMenu = EditWindow.Remove;
     }
     GUI.enabled = true;
     EditorGUILayout.EndHorizontal();
 }
Esempio n. 25
0
 DetailPrototype[] SetupGrass()
 {
     DetailPrototype[] Grass = new DetailPrototype[3];
     Grass[0] = new DetailPrototype();
     Grass[0].prototypeTexture = GrassTex;
     Grass[1] = new DetailPrototype();
     Grass[1].prototypeTexture = GrassTex;
     Grass[2] = new DetailPrototype();
     Grass[2].prototypeTexture = GrassTex;
     return Grass;
 }
 extern internal static bool ValidateDetailPrototype([NotNull] DetailPrototype prototype, out string errorMessage);
Esempio n. 27
0
 public static void ClearGrass()
 {
     Terrain t = Terrain.activeTerrain;
     TerrainData td = t.terrainData;
     DetailPrototype[] detailPrototypes = new DetailPrototype[0];
     td.detailPrototypes = detailPrototypes;
 }
	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);
		}

	}
Esempio n. 29
0
	public void DeleteDetailLayer( int id ){
		DetailPrototype[] details = currentTerrainInstance.terrainData.detailPrototypes;
		
		if ( currentTerrainInstance != null && details.Length > id ){
			DetailPrototype[] newDetails = new DetailPrototype[details.Length-1];
			int count = 0;
			for ( int i = 0; i < details.Length; i++ ){
				if ( i != id ){	
					newDetails[count] = details[i];
					count++;
				}
			}
			currentTerrainInstance.terrainData.detailPrototypes = newDetails;
		}
		
		m_CurrentDetailLayerSet.RemoveAt( id );
	}
Esempio n. 30
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;
        //**************************************************************
    }
        /// <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.DetailPrototype detailPrototype = (UnityEngine.DetailPrototype)value;
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "prototype":
                    if (detailPrototype.prototype == null)
                    {
                        detailPrototype.prototype = reader.ReadProperty <UnityEngine.GameObject> ();
                    }
                    else
                    {
                        reader.ReadIntoProperty <UnityEngine.GameObject> (detailPrototype.prototype);
                    }
                    break;

                case "prototypeTexture":
                    if (detailPrototype.prototypeTexture == null)
                    {
                        detailPrototype.prototypeTexture = reader.ReadProperty <UnityEngine.Texture2D> ();
                    }
                    else
                    {
                        reader.ReadIntoProperty <UnityEngine.Texture2D> (detailPrototype.prototypeTexture);
                    }
                    break;

                case "minWidth":
                    detailPrototype.minWidth = reader.ReadProperty <System.Single> ();
                    break;

                case "maxWidth":
                    detailPrototype.maxWidth = reader.ReadProperty <System.Single> ();
                    break;

                case "minHeight":
                    detailPrototype.minHeight = reader.ReadProperty <System.Single> ();
                    break;

                case "maxHeight":
                    detailPrototype.maxHeight = reader.ReadProperty <System.Single> ();
                    break;

                case "noiseSpread":
                    detailPrototype.noiseSpread = reader.ReadProperty <System.Single> ();
                    break;

                case "bendFactor":
                    detailPrototype.bendFactor = reader.ReadProperty <System.Single> ();
                    break;

                case "healthyColor":
                    detailPrototype.healthyColor = reader.ReadProperty <UnityEngine.Color> ();
                    break;

                case "dryColor":
                    detailPrototype.dryColor = reader.ReadProperty <UnityEngine.Color> ();
                    break;

                case "renderMode":
                    detailPrototype.renderMode = reader.ReadProperty <UnityEngine.DetailRenderMode> ();
                    break;

                case "usePrototypeMesh":
                    detailPrototype.usePrototypeMesh = reader.ReadProperty <System.Boolean> ();
                    break;
                }
            }
        }
Esempio n. 32
0
 private void ReplaceSplatMap(DetailPrototype p, int index)
 {
     DetailPrototype[] newPototypes = component.TerrainData.detailPrototypes;
     newPototypes[index] = p;
     component.TerrainData.detailPrototypes = newPototypes;
 }
Esempio n. 33
0
	public void ResetTerrainPrefab(){
		if ( currentTerrainInstance != null ){
			TerrainData data = currentTerrainInstance.terrainData;
			float[,] heights = data.GetHeights(0,0,data.heightmapWidth, data.heightmapHeight);
			float[,,] alphas = data.GetAlphamaps(0, 0, data.alphamapWidth, data.alphamapHeight);
			
			for ( int layerID = 0; layerID < data.detailPrototypes.Length; layerID++ ){
				int[,] details = data.GetDetailLayer(0 ,0, data.detailWidth, data.detailHeight, layerID );
				for ( int i = 0; i < data.detailWidth; i++ ){
					for ( int j = 0; j < data.detailHeight; j++ ){	
						details[i,j] = 0;
					}
				}
				data.SetDetailLayer( 0, 0, layerID, details );
			}
			
			// this process somehow fixes the broken-ness of the terrain.
			DetailPrototype[] newDetails = new DetailPrototype[1];
			newDetails[0] = new DetailPrototype();
			data.detailPrototypes = newDetails;
			data.detailPrototypes = new DetailPrototype[0];
			
			m_CurrentDetailLayerSet.Clear ();
			
			for (int i = 0; i < data.heightmapWidth; i++ ){
				for (int j = 0; j < data.heightmapHeight; j++ ){
					heights[i,j] = 0.5f;
				}
			}
			
			for (int i = 0; i < data.alphamapHeight; i++ ){
				for ( int j = 0; j < data.alphamapWidth; j++ ){
					alphas[i,j,0] = 1f;
					for (int k = 1; k < 4; k++ ){
						alphas[i,j,k] = 0f;
						
					}	
				}
			}
			
			data.SetHeights(0,0,heights);
			data.SetAlphamaps(0,0,alphas);
			
			// set the density and draw distance for the vegetation.
			SetVegetationDensity( m_VegetationDensity );
			SetVegetationDrawDistance( m_VegetationDrawDistance );
		}
		
		m_TerrainExtensionOffset = 0.0f;
		if ( m_TerrainExtensionPrefab != null ){
			SetTerrainPosition( new Vector3(-currentTerrainInstance.terrainData.size.x/2,m_CurrentHeightmapHeightScale,-currentTerrainInstance.terrainData.size.z/2) );
		}
	}
Esempio n. 34
0
        DetailPrototype GetDetail(string dir, Grass grass)
        {
            DetailPrototype detail = new DetailPrototype();
            if (grass==null) return detail;

            detail.maxHeight = grass.maxHeight;
            detail.minHeight = grass.minHeight;
            detail.minWidth = Config.GrassWidth;
            detail.maxWidth = Config.GrassWidth;
            detail.prototypeTexture = Util.Storage.LoadTextureFromResources(dir + grass.file);
            detail.noiseSpread = 0.1f;
            detail.dryColor = grass.dry;
            detail.healthyColor = grass.healthy;
            detail.renderMode = DetailRenderMode.GrassBillboard;
            return detail;
        }
Esempio n. 35
0
 public bool Validate(out string errorMessage)
 {
     return(DetailPrototype.ValidateDetailPrototype(this, out errorMessage));
 }
Esempio n. 36
0
        DetailPrototype[] GetDetails()
        {
            grasses = WorldConfig.GetDetailsList(global.map);

            if (grasses.Length==0) return new DetailPrototype[0];

            string dir = Util.File.ObjectsStorageDir(global.map);

            DetailPrototype[] array = new DetailPrototype[grasses.Length];
            for (int i = 0; i<grasses.Length; ++i) {
                array[i] = GetDetail(dir, grasses[i]);
            }
            return array;
        }
	/**
	 * Ajoute les détails sur le Terrain.
	 */
	void AddDetails(){
		//Check if grass is necessary
		float percentage = ((float)GroundManager.NB_GRASSHILL / (float)(tData.alphamapHeight * tData.alphamapWidth));
		if(percentage < season.seasons[season.CurrentSeason].details.grassProbability){
			return;
		}

		tData.SetDetailResolution(Details.DETAIL_RESOLUTION,Details.DETAIL_PER_PATCH);
		
		// Ajout d'herbe au Terrain
		DetailPrototype[] detailProto = new DetailPrototype[season.seasons[season.CurrentSeason].details.grassTextures.Length/* + season.seasons[season.CurrentSeason].details.bushsMeshes.Length*/]; 

		int tmp = 0;

		for(int i = 0 ; i < season.seasons[season.CurrentSeason].details.grassTextures.Length ; i++){
			detailProto[i] = new DetailPrototype(); 
			detailProto[i].renderMode = DetailRenderMode.GrassBillboard;
			detailProto[i].prototypeTexture = season.seasons[season.CurrentSeason].details.grassTextures[i];
			detailProto[i].minWidth = season.seasons[season.CurrentSeason].details.minWidth;
			detailProto[i].maxWidth = season.seasons[season.CurrentSeason].details.maxWidth;
			detailProto[i].minHeight = season.seasons[season.CurrentSeason].details.minHeight;
			detailProto[i].maxHeight = season.seasons[season.CurrentSeason].details.maxHeight;
			detailProto[i].noiseSpread = season.seasons[season.CurrentSeason].details.noiseSpread;
			detailProto[i].dryColor = season.seasons[season.CurrentSeason].details.dryColor;
			detailProto[i].healthyColor = season.seasons[season.CurrentSeason].details.healthyColor;
			detailProto[i].usePrototypeMesh = false;
			detailProto[i].bendFactor = 1f;

			tmp = i;
		}

		tmp++;


		//3D MODELS
		/*int j = 0;
		for(int i = tmp ; i < tmp + season.seasons[season.CurrentSeason].details.bushsMeshes.Length ; i++){
			detailProto[i] = new DetailPrototype(); 
			detailProto[i].renderMode = DetailRenderMode.Grass;
			detailProto[i].prototype = season.seasons[season.CurrentSeason].details.bushsMeshes[j++];
			detailProto[i].minWidth = season.seasons[season.CurrentSeason].details.minWidth;
			detailProto[i].maxWidth = season.seasons[season.CurrentSeason].details.maxWidth;
			detailProto[i].minHeight = season.seasons[season.CurrentSeason].details.minHeight;
			detailProto[i].maxHeight = season.seasons[season.CurrentSeason].details.maxHeight;
			detailProto[i].noiseSpread = season.seasons[season.CurrentSeason].details.noiseSpread;
			detailProto[i].dryColor = season.seasons[season.CurrentSeason].details.dryColor;
			detailProto[i].healthyColor = season.seasons[season.CurrentSeason].details.healthyColor;
			detailProto[i].usePrototypeMesh = true;
			detailProto[i].bendFactor = 1f;
		}*/

		tData.detailPrototypes = detailProto;

		for(int layer = 0 ; layer < season.seasons[season.CurrentSeason].details.grassTextures.Length/* + season.seasons[season.CurrentSeason].details.bushsMeshes.Length*/ ; layer++){

			//A REMETTRE diviser par 10 si 3d models
			int nbDetails = Mathf.FloorToInt((Random.Range(season.seasons[season.CurrentSeason].details.minGrass, season.seasons[season.CurrentSeason].details.maxGrass) / 5f) * GroundManager.NB_GRASSHILL);

			int[,] detail = new int[Details.DETAIL_RESOLUTION, Details.DETAIL_RESOLUTION];
			for(int i = 0 ; i < nbDetails ; i++){

				int randomX = 0;
				int randomZ = 0;
				int index = 0;

				do{
					randomX = Random.Range(0, hMap.width);
					randomZ = Random.Range(0, hMap.height);
					
					index++;
				}while((tData.GetHeight (randomZ,randomX) < season.seasons[season.CurrentSeason].textures[Texture.GRASSHILL].minHeight || tData.GetHeight (randomZ,randomX) > season.seasons[season.CurrentSeason].textures[Texture.GRASSHILL].maxHeight) && index < 1000);

				if(index >= 1000){
					detail[randomX,randomZ] = 0;
				}else{
					detail[randomX,randomZ] = 1;
				}
			}

			tData.SetDetailLayer(0, 0, layer, detail);
		}

	}
Esempio n. 38
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);
    }
 public bool detailsDataCreated()
 {
     Details[] details = GameObject.FindObjectsOfType<Details> ();
     detailPrototypes = new DetailPrototype[details.Length];
     for (int i=0; i<details.Length; i++) {
         detailPrototypes [i] = new DetailPrototype ();
         detailPrototypes [i].prototypeTexture = details[i].detailTexture;
         detailPrototypes [i].renderMode = details[i].renderMode;
         detailPrototypes[i].dryColor = details[i].dryColor;
         detailPrototypes[i].healthyColor = details[i].healthyColor;
     }
     return true;
 }
Esempio n. 40
0
    void FillDetailMap()
    {
        m_detailProtoTypes = new DetailPrototype[0];

        terrain.terrainData.detailPrototypes = m_detailProtoTypes;

        m_detailProtoTypes = new DetailPrototype[3];

        float minHeight = 0.2f;
        float maxHeight = 0.8f;
        float minWidth = 0.2f;
        float maxWidth = 0.8f;

        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 [0].minHeight = minHeight;
        m_detailProtoTypes [0].maxHeight = maxHeight;
        m_detailProtoTypes [0].minWidth = minWidth;
        m_detailProtoTypes [0].maxWidth = maxWidth;

        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 [1].minHeight = minHeight;
        m_detailProtoTypes [1].maxHeight = maxHeight;
        m_detailProtoTypes [1].minWidth = minWidth;
        m_detailProtoTypes [1].maxWidth = maxWidth;

        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;
        m_detailProtoTypes [2].minHeight = minHeight;
        m_detailProtoTypes [2].maxHeight = maxHeight;
        m_detailProtoTypes [2].minWidth = minWidth;
        m_detailProtoTypes [2].maxWidth = maxWidth;

        terrain.terrainData.detailPrototypes = m_detailProtoTypes;

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

        //each layer is drawn separately so if you have a lot of layers your draw calls will increase
        int[,] detailMap0 = new int[512,512];
        int[,] detailMap1 = new int[512,512];
        int[,] detailMap2 = new int[512,512];

        float ratio = (float)m_terrainSize/(float)512;

        for(int x = 0; x < 512; x++)
        {
            for (int z = 0; z < 512; z++)
            {
                detailMap0[z,x] = 0;
                detailMap1[z,x] = 0;
                detailMap2[z,x] = 0;

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

                float normX = x * unit;
                float normZ = z * unit;

                // 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.3f)
                {
                    float worldPosX = (x+(512-1))*ratio;
                    float worldPosZ = (z+(512-1))*ratio;

                    float noise = m_detailNoise.FractalNoise2D(worldPosX, worldPosZ, 3, m_detailFrq, 1.0f);

                    if(noise > 0.0f)
                    {
                        float rnd = Random.value;
                        if(rnd < 0.33)
                            detailMap0[z,x] = 1;
                        else if(rnd < 0.66f)
                            detailMap1[z,x] = 1;
                        else
                            detailMap2[z,x] = 1;
                    }
                }

            }
        }

        terrain.terrainData.wavingGrassStrength = m_wavingGrassStrength;
        terrain.terrainData.wavingGrassAmount = m_wavingGrassAmount;
        terrain.terrainData.wavingGrassSpeed = m_wavingGrassSpeed;
        terrain.terrainData.wavingGrassTint = m_wavingGrassTint;
        terrain.detailObjectDensity = m_detailObjectDensity;
        terrain.detailObjectDistance = m_detailObjectDistance;
        terrain.terrainData.SetDetailResolution(512, m_detailResolutionPerPatch);

        terrain.terrainData.SetDetailLayer(0,0,0,detailMap0);
        terrain.terrainData.SetDetailLayer(0,0,1,detailMap1);
        terrain.terrainData.SetDetailLayer(0,0,2,detailMap2);
    }
Esempio n. 41
0
 private void RemoveSplatMap(int index)
 {
     DetailPrototype[] newPototypes = new DetailPrototype[component.TerrainData.detailPrototypes.Length - 1];
     for (int i = 0, j = 0; i < component.TerrainData.detailPrototypes.Length; i++)
     {
         if (i == index) { continue; }
         newPototypes[j] = component.TerrainData.detailPrototypes[i];
         j++;
     }
     component.TerrainData.detailPrototypes = newPototypes;
 }
    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;
    }
Esempio n. 43
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;
        }
    }
Esempio n. 44
0
 private void AddSplatMap(DetailPrototype p)
 {
     DetailPrototype[] newPototypes = new DetailPrototype[component.TerrainData.detailPrototypes.Length + 1];
     for (int i = 0; i < component.TerrainData.detailPrototypes.Length; i++) { newPototypes[i] = component.TerrainData.detailPrototypes[i]; }
     newPototypes[newPototypes.Length - 1] = p;
     component.TerrainData.detailPrototypes = newPototypes;
 }