Last active
May 6, 2024 03:04
-
-
Save st4rdog/40fc14a8a256c2376ba121bca33d7571 to your computer and use it in GitHub Desktop.
Unity Terrain - Tint TerrainLayers. Gets TerrainLayers assets used on selected terrain and applies tint/color.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEngine; | |
// https://gist.github.com/st4rdog/40fc14a8a256c2376ba121bca33d7571 | |
// Gets TerrainLayers assets used on selected terrain and applies tint/color. | |
// TerrainLayer color can be changed in Debug inspector view. | |
public class TerrainColorTint : MonoBehaviour | |
{ | |
public List<Terrain> Terrains = new(); | |
public List<Color> TargetColors = new(); | |
void OnValidate() | |
{ | |
if (Terrains == null || Terrains.Count == 0) return; | |
var layersCount = Terrains[0].terrainData.terrainLayers.Length; | |
// Init with current colours | |
{ | |
if (TargetColors.Count != layersCount) | |
{ | |
TargetColors.Clear(); | |
for (int i = 0; i < layersCount; i++) | |
{ | |
TargetColors.Add(Terrains[0].terrainData.terrainLayers[i].diffuseRemapMax); | |
} | |
} | |
} | |
// Apply | |
{ | |
for (int i = 0; i < Terrains.Count; i++) | |
{ | |
var terrain = Terrains[i]; | |
if (terrain == null) return; | |
for (int j = 0; j < layersCount; j++) | |
{ | |
terrain.terrainData.terrainLayers[j].diffuseRemapMax = TargetColors[j]; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment