Skip to content

Commit

Permalink
✨ feat(static-profile): Terrain overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
esnya committed Apr 7, 2022
1 parent 8881642 commit ef51e0a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Assets/EsnyaUnityTools/Scripts/StaticProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public enum ColliderModification
public bool overrideAnchor;
public Transform anchor;

[Header("Terrain Grouping ID")]
public bool overrideTerrainGroupingId;
public int terrainGroupingId;

[Header("Terrain Material")]
public bool overrideTerrainMaterialTemplate;
public Material terrainMaterialTemplate;

private void Reset()
{
gameObject.tag = "EditorOnly";
Expand Down Expand Up @@ -151,6 +159,30 @@ public void Apply()
}
}
}

var terrains = transform.parent.GetComponentsInChildren<Terrain>(true).ToArray();
if (overrideLightmapSettings)
{
var serializedObject = new SerializedObject(terrains);
serializedObject.FindProperty("m_ScaleInLightmap").floatValue = lightmapScaleOffset;
if (lightmapParameters) serializedObject.FindProperty("m_LightmapParameters").objectReferenceValue = lightmapParameters;
serializedObject.ApplyModifiedProperties();
}

foreach (var terrain in terrains)
{
if (overrideTerrainGroupingId)
{
Undo.RecordObject(terrain, "Override Terrain");
terrain.groupingID = terrainGroupingId;
}

if (overrideTerrainMaterialTemplate)
{
Undo.RecordObject(terrain, "Override Terrain");
terrain.materialTemplate = terrainMaterialTemplate;
}
}
}
#endif
}
Expand Down

0 comments on commit ef51e0a

Please sign in to comment.