From ef51e0ad08a1c87c8e237850fba0a7ad16361ab0 Mon Sep 17 00:00:00 2001 From: esnya Date: Fri, 8 Apr 2022 02:18:05 +0900 Subject: [PATCH] :sparkles: feat(static-profile): Terrain overrides --- .../EsnyaUnityTools/Scripts/StaticProfile.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Assets/EsnyaUnityTools/Scripts/StaticProfile.cs b/Assets/EsnyaUnityTools/Scripts/StaticProfile.cs index 879b15b..b026ae5 100644 --- a/Assets/EsnyaUnityTools/Scripts/StaticProfile.cs +++ b/Assets/EsnyaUnityTools/Scripts/StaticProfile.cs @@ -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"; @@ -151,6 +159,30 @@ public void Apply() } } } + + var terrains = transform.parent.GetComponentsInChildren(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 }