RealWorldTerrainAdjustEdgesPhase.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* INFINITY CODE 2013-2019 */
  2. /* http://www.infinity-code.com */
  3. namespace InfinityCode.RealWorldTerrain.Phases
  4. {
  5. public class RealWorldTerrainAdjustEdgesPhase : RealWorldTerrainPhase
  6. {
  7. public override string title
  8. {
  9. get { return "Adjust Edges..."; }
  10. }
  11. public override void Enter()
  12. {
  13. RealWorldTerrainItem[,] items = terrains;
  14. for (int x = 0; x < prefs.terrainCount.x - 1; x++)
  15. {
  16. for (int y = 0; y < prefs.terrainCount.y; y++)
  17. {
  18. float[,] heights1 = items[x, y].terrainData.GetHeights(prefs.heightmapResolution - 1, 0, 1, prefs.heightmapResolution);
  19. float[,] heights2 = items[x + 1, y].terrainData.GetHeights(0, 0, 1, prefs.heightmapResolution);
  20. for (int i = 0; i < prefs.heightmapResolution; i++) heights1[i, 0] = (heights1[i, 0] + heights2[i, 0]) / 2;
  21. items[x, y].terrainData.SetHeights(prefs.heightmapResolution - 1, 0, heights1);
  22. items[x + 1, y].terrainData.SetHeights(0, 0, heights1);
  23. }
  24. }
  25. for (int y = 0; y < prefs.terrainCount.y - 1; y++)
  26. {
  27. for (int x = 0; x < prefs.terrainCount.x; x++)
  28. {
  29. float[,] heights1 = items[x, y].terrainData.GetHeights(0, prefs.heightmapResolution - 1, prefs.heightmapResolution, 1);
  30. float[,] heights2 = items[x, y + 1].terrainData.GetHeights(0, 0, prefs.heightmapResolution, 1);
  31. for (int i = 0; i < prefs.heightmapResolution; i++) heights1[0, i] = (heights1[0, i] + heights2[0, i]) / 2;
  32. items[x, y].terrainData.SetHeights(0, prefs.heightmapResolution - 1, heights1);
  33. items[x, y + 1].terrainData.SetHeights(0, 0, heights1);
  34. }
  35. }
  36. Complete();
  37. }
  38. }
  39. }