@@ -16,13 +16,15 @@ public static class TerrainManager
1616 public static float [ , , ] BiomeArray { get ; private set ; }
1717
1818 /// <summary>The Topology layers, and textures of the map. [31][Res, Res, Textures(2)]</summary>
19- public static float [ ] [ , , ] TopologyArray { get ; private set ; }
19+ public static float [ ] [ , , ] TopologyArray { get ; private set ; } = new float [ TerrainTopology . COUNT ] [ , , ] ;
2020
2121 /// <summary>The Terrain layers used by the terrain for paint operations</summary>
22- private static TerrainLayer [ ] groundTextures = null , biomeTextures = null , miscTextures = null ;
22+ public static TerrainLayer [ ] GroundTextures { get ; private set ; } = null ;
23+ public static TerrainLayer [ ] BiomeTextures { get ; private set ; } = null ;
24+ public static TerrainLayer [ ] MiscTextures { get ; private set ; } = null ;
2325
2426 /// <summary>The current slopearray of the terrain.</summary>
25- private static float [ , ] SlopeArray ;
27+ public static float [ , ] SlopeArray { get ; private set ; }
2628
2729 /// <summary>The LandLayer currently being displayed on the terrain.</summary>
2830 public static LandLayers LandLayer { get ; private set ; }
@@ -31,14 +33,14 @@ public static class TerrainManager
3133 public static TerrainTopology . Enum TopologyLayer { get ; private set ; }
3234
3335 /// <summary>The previously selected topology layer. Used to save the Topology layer before displaying the new one.</summary>
34- private static int lastTopologyLayer = 0 ;
36+ public static int lastTopologyLayer { get ; private set ; } = 0 ;
3537
3638 /// <summary>The terrain pieces in the scene.</summary>
3739 public static Terrain land , water ;
3840
3941 public static bool LayerSet { get ; private set ; }
4042
41- private static Coroutines Coroutine ;
43+ private static Coroutines Coroutine = new Coroutines ( ) ;
4244
4345 [ InitializeOnLoadMethod ]
4446 private static void Init ( )
@@ -52,8 +54,6 @@ private static void ProjectLoaded()
5254 {
5355 EditorApplication . update -= ProjectLoaded ;
5456 SetTerrainReferences ( ) ;
55- TopologyArray = new float [ TerrainTopology . COUNT ] [ , , ] ;
56- Coroutine = new Coroutines ( ) ;
5757 }
5858
5959 public static Vector3 GetTerrainSize ( )
@@ -85,17 +85,13 @@ public static float GetSplatSize()
8585 public static float [ , ] GetSlopes ( )
8686 {
8787 if ( SlopeArray != null )
88- {
8988 return SlopeArray ;
90- }
89+
9190 SlopeArray = new float [ GetHeightMapResolution ( ) , GetHeightMapResolution ( ) ] ;
9291 for ( int i = 0 ; i < land . terrainData . alphamapHeight ; i ++ )
93- {
9492 for ( int j = 0 ; j < land . terrainData . alphamapHeight ; j ++ )
95- {
9693 SlopeArray [ j , i ] = land . terrainData . GetSteepness ( ( float ) i / ( float ) land . terrainData . alphamapHeight , ( float ) j / ( float ) land . terrainData . alphamapHeight ) ;
97- }
98- }
94+
9995 return SlopeArray ;
10096 }
10197
@@ -109,9 +105,7 @@ public static void SetTerrainReferences()
109105 private static void HeightmapChanged ( Terrain terrain , RectInt heightRegion , bool synched )
110106 {
111107 if ( terrain == land )
112- {
113108 SlopeArray = null ;
114- }
115109 }
116110
117111 /// <summary>Callback for whenever the alphamap is updated.</summary>
@@ -125,11 +119,11 @@ private static void TextureChanged(Terrain terrain, string textureName, RectInt
125119 /// <param name="topology">The Topology layer to change to.</param>
126120 public static void ChangeLandLayer ( LandLayers layer , int topology = 0 )
127121 {
128- if ( layer != LandLayers . Alpha && layer != LandLayer )
129- {
122+ if ( layer == LandLayers . Alpha )
123+ return ;
124+ if ( layer == LandLayer )
130125 SaveLayer ( lastTopologyLayer ) ;
131- SetLayer ( layer , topology ) ;
132- }
126+ SetLayer ( layer , topology ) ;
133127 }
134128
135129 /// <summary>Returns the SplatMap at the selected LandLayer.</summary>
@@ -221,9 +215,9 @@ public static void SaveLayer(int topologyLayer = 0)
221215
222216 private static void GetTextures ( )
223217 {
224- groundTextures = GetGroundTextures ( ) ;
225- biomeTextures = GetBiomeTextures ( ) ;
226- miscTextures = GetMiscTextures ( ) ;
218+ GroundTextures = GetGroundTextures ( ) ;
219+ BiomeTextures = GetBiomeTextures ( ) ;
220+ MiscTextures = GetMiscTextures ( ) ;
227221 AssetDatabase . SaveAssets ( ) ;
228222 }
229223
@@ -283,24 +277,24 @@ public IEnumerator SetLayer(LandLayers layer, int topology = 0)
283277
284278 private IEnumerator SetLayerCoroutine ( LandLayers layer , int topology = 0 )
285279 {
286- if ( groundTextures == null || biomeTextures == null || miscTextures == null )
280+ if ( GroundTextures == null || BiomeTextures == null || MiscTextures == null )
287281 GetTextures ( ) ;
288282
289283 switch ( layer )
290284 {
291285 case LandLayers . Ground :
292- land . terrainData . terrainLayers = groundTextures ;
286+ land . terrainData . terrainLayers = GroundTextures ;
293287 land . terrainData . SetAlphamaps ( 0 , 0 , GroundArray ) ;
294288 LandLayer = layer ;
295289 break ;
296290 case LandLayers . Biome :
297- land . terrainData . terrainLayers = biomeTextures ;
291+ land . terrainData . terrainLayers = BiomeTextures ;
298292 land . terrainData . SetAlphamaps ( 0 , 0 , BiomeArray ) ;
299293 LandLayer = layer ;
300294 break ;
301295 case LandLayers . Topology :
302296 lastTopologyLayer = topology ;
303- land . terrainData . terrainLayers = miscTextures ;
297+ land . terrainData . terrainLayers = MiscTextures ;
304298 land . terrainData . SetAlphamaps ( 0 , 0 , TopologyArray [ topology ] ) ;
305299 LandLayer = layer ;
306300 break ;
0 commit comments