In Unity 2018, how do you set the “Lightmap Parameters” dropdown in “Lightmapping Settings” via C# Script. It is not listed in the LightmapEditorSettings.
This feels a bit gross, but I just hacked it in using reflection.
Thanks to this thread and this repo.
private LightmapParameters m_defaultLightmapParameters;
private static SerializedObject GetLightmapSettings()
{
var getLightmapSettingsMethod = typeof(LightmapEditorSettings).GetMethod("GetLightmapSettings", BindingFlags.Static | BindingFlags.NonPublic);
var lightmapSettings = getLightmapSettingsMethod.Invoke(null, null) as UnityEngine.Object;
return new SerializedObject( lightmapSettings );
}
private void GetValue()
{
SerializedObject baseSettings = GetLightmapSettings();
SerializedProperty lightmapParameters = baseSettings.FindProperty( "m_LightmapEditorSettings.m_LightmapParameters" );
m_defaultLightmapParameters = lightmapParameters.objectReferenceValue as LightmapParameters;
}
private void SetValue()
{
SerializedObject baseSettings = GetLightmapSettings();
SerializedProperty lightmapParameters = baseSettings.FindProperty( "m_LightmapEditorSettings.m_LightmapParameters" );
lightmapParameters.objectReferenceValue = m_defaultLightmapParameters;
baseSettings.ApplyModifiedProperties();
}