using System;
using UnityEngine;
namespace Framework.Terrain {
/// Terrain data import settings
[RequireComponent(typeof(UnityEngine.Terrain))]
public class TerrainImportSettings : MonoBehaviour {
/// Texture to use for controlled height map re-imports
[Tooltip("Texture from which the height map will be read.")]
public Texture2D HeightMapTexture;
/// Height of the terrain at its lowest point
[Tooltip("Absolute height level of the terrain at its lowest point.")]
public float MinHeight = 0.0f;
/// Height of the terrain at its highest point
[Tooltip("Absolute height level of the terrain at its highest point.")]
public float MaxHeight = 100.0f;
/// Texture to import up to four splat layers from
[Tooltip("Texture from which up to four splat layers will be imported.")]
public Texture2D SplatMapTexture;
/// Texture to import up to four additional splat layers from
[Tooltip("Texture from which up to four additional splat layers will be imported.")]
public Texture2D SecondarySplatMapTexture;
/// Which color channel to map to each splat layer index
[Tooltip("Color channels to map to each of the splat weight layers.")]
public int[] SplatColorIndices;
/// Resizes the splat layer index array to the specified size
/// Number of splat layer indices that are required
///
/// Tries to preserves the contents of the splat layer indices.
///
public void ResizeSplatColorIndices(int layerCount) {
if(this.SplatColorIndices == null) {
this.SplatColorIndices = new int[layerCount];
for(int index = 0; index < layerCount; ++index) {
this.SplatColorIndices[index] = (index + 1);
}
} else {
int existingLayerCount = this.SplatColorIndices.Length;
if(existingLayerCount != layerCount) {
int[] newLayerIndices = new int[layerCount];
Array.Copy(
this.SplatColorIndices, newLayerIndices,
Math.Min(layerCount, existingLayerCount)
);
for(int index = existingLayerCount; index < layerCount; ++index) {
newLayerIndices[index] = (index + 1);
}
this.SplatColorIndices = newLayerIndices;
}
}
}
///
/// Whether the current splat layer indices reference the primary splat map texture
///
public bool ReferencesPrimarySplatMapTexture {
get {
if(this.SplatColorIndices != null) {
int splatLayerIndexCount = this.SplatColorIndices.Length;
for(int index = 0; index < splatLayerIndexCount; ++index) {
int splatLayerIndex = this.SplatColorIndices[index];
if((splatLayerIndex >= 1) && (splatLayerIndex <= 4)) {
return true;
}
}
}
return false;
}
}
///
/// Whether the current splat layer indices reference the secondary splat map texture
///
public bool ReferencesSecondarySplatMapTexture {
get {
if(this.SplatColorIndices != null) {
int splatLayerIndexCount = this.SplatColorIndices.Length;
for(int index = 0; index < splatLayerIndexCount; ++index) {
int splatLayerIndex = this.SplatColorIndices[index];
if((splatLayerIndex >= 5) && (splatLayerIndex <= 8)) {
return true;
}
}
}
return false;
}
}
}
} // namespace Framework.Terrain