Beispiel #1
0
 public void erodeAllTerrain(TerrainToolkit.ErosionProgressDelegate erosionProgressDelegate)
 {
     int num;
     this.erosionMode = TerrainToolkit.ErosionMode.Filter;
     this.convertIntVarsToEnums();
     Terrain component = (Terrain)base.GetComponent(typeof(Terrain));
     if (component == null)
     {
         return;
     }
     try
     {
         TerrainData terrainDatum = component.terrainData;
         int num1 = terrainDatum.heightmapWidth;
         int num2 = terrainDatum.heightmapHeight;
         float[,] heights = terrainDatum.GetHeights(0, 0, num1, num2);
         switch (this.erosionType)
         {
             case TerrainToolkit.ErosionType.Thermal:
             {
                 num = this.thermalIterations;
                 heights = this.fastErosion(heights, new Vector2((float)num1, (float)num2), num, erosionProgressDelegate);
                 break;
             }
             case TerrainToolkit.ErosionType.Hydraulic:
             {
                 num = this.hydraulicIterations;
                 switch (this.hydraulicType)
                 {
                     case TerrainToolkit.HydraulicType.Fast:
                     {
                         heights = this.fastErosion(heights, new Vector2((float)num1, (float)num2), num, erosionProgressDelegate);
                         break;
                     }
                     case TerrainToolkit.HydraulicType.Full:
                     {
                         heights = this.fullHydraulicErosion(heights, new Vector2((float)num1, (float)num2), num, erosionProgressDelegate);
                         break;
                     }
                     case TerrainToolkit.HydraulicType.Velocity:
                     {
                         heights = this.velocityHydraulicErosion(heights, new Vector2((float)num1, (float)num2), num, erosionProgressDelegate);
                         break;
                     }
                 }
                 break;
             }
             case TerrainToolkit.ErosionType.Tidal:
             {
                 Vector3 vector3 = terrainDatum.size;
                 if (this.tidalSeaLevel < base.transform.position.y || this.tidalSeaLevel > base.transform.position.y + vector3.y)
                 {
                     Debug.LogError("Sea level does not intersect terrain object. Erosion operation failed.");
                 }
                 else
                 {
                     num = this.tidalIterations;
                     heights = this.fastErosion(heights, new Vector2((float)num1, (float)num2), num, erosionProgressDelegate);
                 }
                 break;
             }
             case TerrainToolkit.ErosionType.Wind:
             {
                 num = this.windIterations;
                 heights = this.windErosion(heights, new Vector2((float)num1, (float)num2), num, erosionProgressDelegate);
                 break;
             }
             default:
             {
                 return;
             }
         }
         terrainDatum.SetHeights(0, 0, heights);
     }
     catch (Exception exception)
     {
         Debug.LogError(string.Concat("An error occurred: ", exception));
     }
 }
Beispiel #2
0
 private void erodeTerrainWithBrush()
 {
     this.erosionMode = TerrainToolkit.ErosionMode.Brush;
     Terrain component = (Terrain)base.GetComponent(typeof(Terrain));
     if (component == null)
     {
         return;
     }
     int num = 0;
     int num1 = 0;
     try
     {
         TerrainData terrainDatum = component.terrainData;
         int num2 = terrainDatum.heightmapWidth;
         int num3 = terrainDatum.heightmapHeight;
         Vector3 vector3 = terrainDatum.size;
         int length = (int)Mathf.Floor((float)num2 / vector3.x * this.brushSize);
         int length1 = (int)Mathf.Floor((float)num3 / vector3.z * this.brushSize);
         Vector3 vector31 = base.transform.InverseTransformPoint(this.brushPosition);
         num = (int)Mathf.Round(vector31.x / vector3.x * (float)num2 - (float)(length / 2));
         num1 = (int)Mathf.Round(vector31.z / vector3.z * (float)num3 - (float)(length1 / 2));
         if (num < 0)
         {
             length = length + num;
             num = 0;
         }
         if (num1 < 0)
         {
             length1 = length1 + num1;
             num1 = 0;
         }
         if (num + length > num2)
         {
             length = num2 - num;
         }
         if (num1 + length1 > num3)
         {
             length1 = num3 - num1;
         }
         float[,] heights = terrainDatum.GetHeights(num, num1, length, length1);
         length = heights.GetLength(1);
         length1 = heights.GetLength(0);
         float[,] singleArray = (float[,])heights.Clone();
         TerrainToolkit.ErosionProgressDelegate erosionProgressDelegate = new TerrainToolkit.ErosionProgressDelegate(this.dummyErosionProgress);
         singleArray = this.fastErosion(singleArray, new Vector2((float)length, (float)length1), 1, erosionProgressDelegate);
         float single = (float)length / 2f;
         for (int i = 0; i < length; i++)
         {
             for (int j = 0; j < length1; j++)
             {
                 float single1 = heights[j, i];
                 float single2 = singleArray[j, i];
                 float single3 = Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(single, single));
                 float single4 = 1f - (single3 - (single - single * this.brushSoftness)) / (single * this.brushSoftness);
                 if (single4 < 0f)
                 {
                     single4 = 0f;
                 }
                 else if (single4 > 1f)
                 {
                     single4 = 1f;
                 }
                 single4 = single4 * this.brushOpacity;
                 float single5 = single2 * single4 + single1 * (1f - single4);
                 heights[j, i] = single5;
             }
         }
         terrainDatum.SetHeights(num, num1, heights);
     }
     catch (Exception exception)
     {
         Debug.LogError(string.Concat("A brush error occurred: ", exception));
     }
 }