Edit settings in Lighting window from editor script

In Unity 5 is it possible to edit the settings in the Lighting Window (Environment Lighting, General GI, Fog, etc…) from an editor script?

The reason I want to do this is to set different lighting options for PC and Mobile and to easily set the lighting for all my levels at once. I have looked in the Script Reference, Quality Settings, Unity Answers and Googled it but can’t find any way to have multiple lighting setups short of creating two scenes for each level and adjusting the settings on every scene. A lot of work with over thirty levels.

What is the recommended workflow for this?

Since you can do it with a runtime/game script (RenderSettings: Unity - Scripting API: RenderSettings)

I have to believe you can do it with Editor script, but don’t have any experience with it. Have you tried using RenderSettings… references?

Edit: @Phong glad you got that sorted out, I converted comment to Answer.

Hey! Here is a script you need!

Forum post here: http://forum.unity3d.com/threads/access-lighting-window-properties-in-script.328342/#post-2669345

using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;


public static class LightingSettingsHepler
{
    public static void SetIndirectResolution(float val)
    {
        SetFloat("m_LightmapEditorSettings.m_Resolution", val);
    }

    public static void SetAmbientOcclusion(float val)
    {
        SetFloat("m_LightmapEditorSettings.m_CompAOExponent", val);
    }

    public static void SetBakedGiEnabled(bool enabled)
    {
        SetBool("m_GISettings.m_EnableBakedLightmaps", enabled);
    }

    public static void SetFinalGatherEnabled(bool enabled)
    {
        SetBool("m_LightmapEditorSettings.m_FinalGather", enabled);
    }

    public static void SetFinalGatherRayCount(int val)
    {
        SetInt("m_LightmapEditorSettings.m_FinalGatherRayCount", val);
    }

    public static void SetFloat(string name, float val)
    {
        ChangeProperty(name, property => property.floatValue= val);
    }

    public static void SetInt(string name, int val)
    {
        ChangeProperty(name, property => property.intValue = val);
    }

    public static void SetBool(string name, bool val)
    {
        ChangeProperty(name, property => property.boolValue = val);
    }

    public static void ChangeProperty(string name, Action<SerializedProperty> changer)
    {
        var lightmapSettings = getLighmapSettings();
        var prop = lightmapSettings.FindProperty(name);
        if (prop != null)
        {
            changer(prop);
            lightmapSettings.ApplyModifiedProperties();
        }
        else Debug.LogError("lighmap property not found: " + name);
    }

    static SerializedObject getLighmapSettings()
    {
        var getLightmapSettingsMethod = typeof(LightmapEditorSettings).GetMethod("GetLightmapSettings", BindingFlags.Static | BindingFlags.NonPublic);
        var lightmapSettings = getLightmapSettingsMethod.Invoke(null, null) as Object;
        return new SerializedObject(lightmapSettings);
    }

    public static void Test()
    {
        SetBakedGiEnabled(true);
        SetIndirectResolution(1.337f);
        SetAmbientOcclusion(1.337f);
        SetFinalGatherEnabled(true);
        SetFinalGatherRayCount(1337);
    }
}

Thanks! :slight_smile: