public static void DrawGUI()
        {
            if (!ConfigGUI())
            {
                return;
            }
            SerializedObject   serializedConfig       = getSerializedConfig();
            SerializedProperty giEnvironment          = serializedConfig.FindProperty("config.environmentSettings.giEnvironment");
            SerializedProperty giEnvironmentIntensity = serializedConfig.FindProperty("config.environmentSettings.giEnvironmentIntensity");
            SerializedProperty iblImageFile           = serializedConfig.FindProperty("config.environmentSettings.iblImageFile");
            SerializedProperty iblSwapYZ         = serializedConfig.FindProperty("config.environmentSettings.iblSwapYZ");
            SerializedProperty iblTurnDome       = serializedConfig.FindProperty("config.environmentSettings.iblTurnDome");
            SerializedProperty iblGIEnvBlur      = serializedConfig.FindProperty("config.environmentSettings.iblGIEnvBlur");
            SerializedProperty iblEmitLight      = serializedConfig.FindProperty("config.environmentSettings.iblEmitLight");
            SerializedProperty iblSamples        = serializedConfig.FindProperty("config.environmentSettings.iblSamples");
            SerializedProperty iblIntensity      = serializedConfig.FindProperty("config.environmentSettings.iblIntensity");
            SerializedProperty iblEmitDiffuse    = serializedConfig.FindProperty("config.environmentSettings.iblEmitDiffuse");
            SerializedProperty iblEmitSpecular   = serializedConfig.FindProperty("config.environmentSettings.iblEmitSpecular");
            SerializedProperty iblSpecularBoost  = serializedConfig.FindProperty("config.environmentSettings.iblSpecularBoost");
            SerializedProperty iblShadows        = serializedConfig.FindProperty("config.environmentSettings.iblShadows");
            SerializedProperty iblBandingVsNoise = serializedConfig.FindProperty("config.environmentSettings.iblBandingVsNoise");

            EditorGUILayout.PropertyField(giEnvironment, new GUIContent("Environment Type", ""), GUILayout.Width(300));
            EditorGUI.BeginDisabledGroup(sc.config.environmentSettings.giEnvironment == mset.ILConfig.EnvironmentSettings.Environment.None);
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(giEnvironmentIntensity, new GUIContent("Intensity", ""), GUILayout.Width(300));

            if (sc.config.environmentSettings.giEnvironment == mset.ILConfig.EnvironmentSettings.Environment.SkyLight)
            {
                // FIXME add undo
                LMColorPicker("Sky Light Color", ref sc.config.environmentSettings.skyLightColor, "It is often a good idea to keep the color below 1.0 in intensity to avoid boosting by gamma correction. Boost the intensity instead with the giEnvironmentIntensity setting.");
            }
            else if (sc.config.environmentSettings.giEnvironment == mset.ILConfig.EnvironmentSettings.Environment.IBL)
            {
                GUILayout.Label("IBL Image", EditorStyles.boldLabel);
                EditorGUILayout.PrefixLabel(new GUIContent("Image Path", ""));
                GUILayout.BeginHorizontal(); {
                    EditorGUILayout.PropertyField(iblImageFile, new GUIContent("", "The absolute image file path to use for IBL. Accepts hdr or OpenEXR format. The file should be long-lat. Use giEnvironmentIntensity to boost the intensity of the image."));
                    GUILayout.Space(10);
                } GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                {
                    //GUILayout.FlexibleSpace();
                    GUILayout.Space(10);
                    if (!string.IsNullOrEmpty(sc.config.environmentSettings.iblImageFile))
                    {
                        if (GUILayout.Button("Reveal", GUILayout.Width(55)))
                        {
                            EditorUtility.OpenWithDefaultApp(Path.GetDirectoryName(sc.config.environmentSettings.iblImageFile));
                        }
                        if (GUILayout.Button("Edit", GUILayout.Width(55)))
                        {
                            EditorUtility.OpenWithDefaultApp(sc.config.environmentSettings.iblImageFile);
                        }
                    }
                    if (GUILayout.Button("Open...", GUILayout.Width(60)))
                    {
                        string file = EditorUtility.OpenFilePanel("Select EXR or HDR file", "", "");
                        string ext  = Path.GetExtension(file);
                        if (!string.IsNullOrEmpty(file))
                        {
                            if (ext == ".exr" || ext == ".hdr")
                            {
                                sc.config.environmentSettings.iblImageFile = file;
                                iblImageFile.stringValue = file;
                                GUI.changed = true;
                                SaveConfig();
                            }
                            else
                            {
                                Debug.LogError("IBL image files must use the extension .exr or .hdr");
                            }
                        }
                    }
                }
                GUILayout.EndHorizontal();
                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(iblGIEnvBlur,
                                              new GUIContent("Image Blur", "Pre-blur the environment image for Global Illumination calculations. Can help to reduce noise and flicker in images rendered with Final Gather. May increase render time as it is blurred at render time. It is always cheaper to pre-blur the image itself in an external application before loading it into Beast."),
                                              GUILayout.Width(300)
                                              );

                EditorGUILayout.Space();
                EditorGUILayout.PropertyField(iblSwapYZ, new GUIContent("Dome Swap Y/Z", "Swap the Up Axis. Default value is false, meaning that Y is up."));
                EditorGUILayout.Slider(iblTurnDome,
                                       0, 360,
                                       new GUIContent("Dome Rotation", "The sphere that the image is projected on can be rotated around the up axis. The amount of rotation is given in degrees."),
                                       GUILayout.Width(300)
                                       );
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(10);
                    if (GUILayout.Button(new GUIContent("Align to Active Sky", "Matches Dome Rotation to the active Skyshop Sky. Note: Skyshop at 0 degrees is Beast at 90."), GUILayout.Width(135)))
                    {
                        float           theta = 90;
                        mset.SkyManager mgr   = mset.SkyManager.Get();
                        if (mgr && mgr.GlobalSky)
                        {
                            theta += mgr.GlobalSky.transform.rotation.eulerAngles.y;
                        }
                        iblTurnDome.floatValue = Mathf.Repeat(theta, 360f);
                        GUI.changed            = true;
                    }
                }
                GUILayout.EndHorizontal();

                EditorGUILayout.Space();
                GUILayout.Label("IBL Light", EditorStyles.boldLabel);
                EditorGUILayout.PropertyField(
                    iblEmitLight,
                    new GUIContent("Emit Light", "Turns on the expensive IBL implementation. This will generate a number of(iblSamples) directional lights from the image."),
                    GUILayout.Width(300)
                    );
                if (sc.config.environmentSettings.iblEmitLight)
                {
                    EditorGUILayout.HelpBox("The scene will be lit by a number of directional lights with colors sampled from the IBL image. Very expensive.", MessageType.None);
                }
                else
                {
                    EditorGUILayout.HelpBox("The scene will be lit with Global Illumination using the IBL image as a simple environment.", MessageType.None);
                }

                EditorGUI.BeginDisabledGroup(!sc.config.environmentSettings.iblEmitLight);
                {
                    EditorGUILayout.PropertyField(iblSamples, new GUIContent("Samples", "The number of samples to be taken from the image. This will affect how soft the shadows will be, as well as the general lighting. The higher number of samples, the better the shadows and lighting."), GUILayout.Width(300));
                    EditorGUILayout.PropertyField(iblIntensity, new GUIContent("IBL Intensity", "Sets the intensity of the lighting."), GUILayout.Width(300));
                    EditorGUILayout.PropertyField(iblEmitDiffuse, new GUIContent("Diffuse", "To remove diffuse lighting from IBL, set this to false. To get the diffuse lighting Final Gather could be used instead."), GUILayout.Width(300));
                    EditorGUILayout.PropertyField(iblEmitSpecular, new GUIContent("Specular", "To remove specular highlights from IBL, set this to false."), GUILayout.Width(300));
                    EditorGUI.indentLevel++;
                    {
                        if (!sc.config.environmentSettings.iblEmitSpecular)
                        {
                            GUI.enabled = false;
                        }
                        EditorGUILayout.PropertyField(iblSpecularBoost, new GUIContent("Specular Boost", "Further tweak the intensity by boosting the specular component."), GUILayout.Width(300));
                        if (sc.config.environmentSettings.iblEmitLight)
                        {
                            GUI.enabled = true;
                        }
                    }
                    EditorGUI.indentLevel--;
                    EditorGUILayout.PropertyField(iblShadows, new GUIContent("Shadows", "Controls whether shadows should be created from IBL when this is used."), GUILayout.Width(300));
                    {
                        EditorGUI.indentLevel++;
                        if (!sc.config.environmentSettings.iblShadows)
                        {
                            GUI.enabled = false;
                        }
                        EditorGUILayout.PropertyField(iblBandingVsNoise, new GUIContent("Shadow Noise", "Controls the appearance of the shadows, banded shadows look more aliased, but noisy shadows flicker more in animations."), GUILayout.Width(300));
                        if (sc.config.environmentSettings.iblEmitLight)
                        {
                            GUI.enabled = true;
                        }
                    }
                    EditorGUI.indentLevel--;
                }
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.Space();
            }
            EditorGUI.indentLevel--;
            EditorGUI.EndDisabledGroup();

            if (GUI.changed)
            {
                serializedConfig.ApplyModifiedProperties();
                SaveConfig();
            }

            float width    = 80;
            float height   = 30;
            bool  disabled = !InternalEditorUtility.HasPro();

            if (disabled)
            {
                EditorGUILayout.HelpBox("Global Illumination baking is a Unity Pro feature :(", MessageType.Error);
            }
            EditorGUI.BeginDisabledGroup(disabled);
            {
                EditorGUILayout.Space();
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(10);
                    EditorGUI.BeginDisabledGroup(Lightmapping.isRunning);
                    if (GUILayout.Button("Clear", GUILayout.Width(width)))
                    {
                        if (EditorUtility.DisplayDialog("Clear Lightmapping Data", "Do you want to clear all lightmap and probe data from the scene?", "OK", "Cancel"))
                        {
                            Lightmapping.Clear();
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal(); {
                    if (!Lightmapping.isRunning)
                    {
                        GUILayout.Space(10);
                        bool scene    = GUILayout.Button("Bake Scene", GUILayout.Height(height));
                        bool selected = GUILayout.Button("Bake Selected", GUILayout.Height(height));
                        bool probes   = GUILayout.Button("Bake Probes", GUILayout.Height(height));

                        if ((scene || selected || probes) && CheckSettingsIntegrity())
                        {
                            if (scene)
                            {
                                Lightmapping.BakeAsync();
                            }
                            else if (selected)
                            {
                                Lightmapping.BakeSelectedAsync();
                            }
                            else if (probes)
                            {
                                Lightmapping.BakeLightProbesOnlyAsync();
                            }
                        }
                        GUILayout.Space(10);
                    }
                    else
                    {
                        GUILayout.Space(10);
                        if (GUILayout.Button("Cancel", GUILayout.Width(width), GUILayout.Height(height)))
                        {
                            Lightmapping.Cancel();
                        }
                    }
                } GUILayout.EndHorizontal();
            }
            EditorGUI.EndDisabledGroup();
        }
 /// <summary>
 /// Cancel lighting bake
 /// </summary>
 public static void CancelLighting()
 {
     Lightmapping.Cancel();
 }
Beispiel #3
0
 /// <inheritdoc />
 protected override void OnInterrupt()
 {
     Lightmapping.Cancel();
 }
Beispiel #4
0
    void OnGUI()
    {
        if (_bakeWasAlreadyInProgress)
        {
            GUILayout.Label("Bake was in progress before opening window. Waiting for bake to finish.");
            if (!Lightmapping.isRunning)
            {
                _bakeWasAlreadyInProgress = false;
            }
            return;
        }

        if (_bakeInProgress)
        {
            GUILayout.Label("Baking in progress");

            float progress = (float)_currentlyBakingScene / _scenePathsToBake.Count + (1.0f / _scenePathsToBake.Count) * Lightmapping.buildProgress;

            var shouldCancel = EditorUtility.DisplayCancelableProgressBar("Lightmap bake", "Baking " + _currentlyBakingScene + "/" + _scenePathsToBake.Count, progress);

            // todo: fix this. It doesn't seem to work, though it's exactly how the Unity docs say to use it. Maybe the scene loading/saving popping up interrupts the current progress bar?
            if (shouldCancel)
            {
                Debug.Log("Cancelling bake");
                Lightmapping.Cancel();
                _bakeInProgress = false;
            }
        }
        else
        {
            if (GUILayout.Button("All"))
            {
                for (int sceneIndex = 0; sceneIndex < _numScenes; ++sceneIndex)
                {
                    _shouldBakeScene[sceneIndex] = true;
                }
            }

            if (GUILayout.Button("None"))
            {
                for (int sceneIndex = 0; sceneIndex < _numScenes; ++sceneIndex)
                {
                    _shouldBakeScene[sceneIndex] = false;
                }
            }

            int numSelected = 0;

            if (_numScenes > 0)
            {
                _scrollPosition = GUILayout.BeginScrollView(_scrollPosition);


                for (int sceneIndex = 0; sceneIndex < _numScenes; ++sceneIndex)
                {
                    _shouldBakeScene[sceneIndex] = EditorGUILayout.ToggleLeft(EditorBuildSettings.scenes[sceneIndex].path, _shouldBakeScene[sceneIndex]);
                    if (_shouldBakeScene[sceneIndex])
                    {
                        ++numSelected;
                    }
                }

                GUILayout.EndScrollView();
            }

            // Grey out the bake button if no scenes are selected.
            GUI.enabled = numSelected > 0;

            if (GUILayout.Button("Bake selected (" + numSelected + ")") && numSelected > 0)
            {
                BakeSelected();
            }

            // Clear greyed out controls.
            GUI.enabled = true;
        }
    }
Beispiel #5
0
        private void OnGUILighting()
        {
            if (m_BakingToggle = EditorGUILayout.BeginToggleGroup("Lighting And Baking", m_BakingToggle))
            {
                EditorGUI.indentLevel++;

                if (PlayerSettings.colorSpace != ColorSpace.Linear)
                {
                    EditorGUILayout.HelpBox("Color Space", MessageType.None);

                    EditorGUILayout.HelpBox(kColorSpaceWarningString, MessageType.Warning);

                    if (GUILayout.Button("Fix color space Settings"))
                    {
                        EditorApplication.ExecuteMenuItem("Edit/Project Settings/Player");
                    }
                }

                EditorGUILayout.Separator();

                SerializedObject _soRend = GetRenderSettings();

                //
                EditorGUILayout.HelpBox("Lighting", MessageType.None);
                SerializedProperty _spAmbientSkyColor  = _soRend.FindProperty("m_AmbientSkyColor");
                SerializedProperty _spAmbientIntensity = _soRend.FindProperty("m_AmbientIntensity");
                SerializedProperty _spAmbientMode      = _soRend.FindProperty("m_AmbientMode");
                SerializedProperty _spSkybox           = _soRend.FindProperty("m_SkyboxMaterial");

                EditorGUI.BeginChangeCheck();
                var _skyColor = EditorGUILayout.ColorField(new GUIContent("Ambient color"), _spAmbientSkyColor.colorValue, true, false, true, kHdrConfig);
                if (EditorGUI.EndChangeCheck())
                {
                    _spAmbientSkyColor.colorValue = _skyColor;
                }

                EditorGUILayout.IntPopup(_spAmbientMode, kAmbientModeStrings, kAmbientModeValues, new GUIContent("Ambient Source"));

                EditorGUILayout.Slider(_spAmbientIntensity, 0f, 8f, new GUIContent("Ambient intensity"));

                EditorGUILayout.PropertyField(_spSkybox, new GUIContent("Skybox Material"));

                EditorGUILayout.Separator();

                SerializedObject _soLmap = GetLighmapSettings();

                SerializedProperty _spRealTime = _soLmap.FindProperty("m_GISettings.m_EnableRealtimeLightmaps");
                SerializedProperty _spBaked    = _soLmap.FindProperty("m_GISettings.m_EnableBakedLightmaps");

                if (Toggle(_spRealTime, new GUIContent("Pre-Realtime GI")))
                {
                    EditorGUI.indentLevel++;

                    SerializedProperty _spResolution = _soLmap.FindProperty("m_LightmapEditorSettings.m_Resolution");

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(_spResolution, new GUIContent("Realtime Resolution"));
                    EditorGUILayout.LabelField("texels per unit");
                    EditorGUILayout.EndHorizontal();

                    SerializedProperty _spCPU = _soLmap.FindProperty("m_RuntimeCPUUsage");
                    EditorGUILayout.IntPopup(_spCPU, kRuntimeCPUUsageStrings, kRuntimeCPUUsageValues, new GUIContent("CPU Usage"));

                    EditorGUILayout.Separator();

                    EditorGUI.indentLevel--;
                }

                if (Toggle(_spBaked, new GUIContent("Baked GI")))
                {
                    EditorGUI.indentLevel++;

                    EditorGUI.BeginDisabledGroup(Lightmapping.isRunning);

                    SerializedProperty _spBakeMode = _soLmap.FindProperty("m_LightmapEditorSettings.m_LightmapsBakeMode");
                    SerializedProperty _spCompress = _soLmap.FindProperty("m_LightmapEditorSettings.m_TextureCompression");

                    EditorGUILayout.IntPopup(_spBakeMode, kBakeModeStrings, kBakeModeValues, new GUIContent("Baking Mode"));
                    EditorGUILayout.PropertyField(_spCompress, new GUIContent("Compressed"));

                    EditorGUILayout.Separator();

                    SerializedProperty _spDirectRes   = _soLmap.FindProperty("m_LightmapEditorSettings.m_BakeResolution");
                    SerializedProperty _spIndirectRes = _soLmap.FindProperty("m_LightmapEditorSettings.m_Resolution");
                    SerializedProperty _spPadding     = _soLmap.FindProperty("m_LightmapEditorSettings.m_Padding");
                    SerializedProperty _spAtlasSize   = _soLmap.FindProperty("m_LightmapEditorSettings.m_TextureWidth");

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(_spDirectRes, new GUIContent("Direct Resolution"));
                    EditorGUILayout.LabelField("texels per unit");
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(_spIndirectRes, new GUIContent("Indirect Resolution"));
                    EditorGUILayout.LabelField("texels per unit");
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.BeginHorizontal();
                    EditorGUILayout.PropertyField(_spPadding, new GUIContent("Padding"));
                    EditorGUILayout.LabelField("texels");
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.IntPopup(
                        _spAtlasSize,
                        kMaxAtlasSizeStrings,
                        kMaxAtlasSizeValues,
                        new GUIContent("Atlas Size"));

                    //LightmapEditorSettings.maxAtlasHeight = LightmapEditorSettings.maxAtlasWidth;

                    EditorGUILayout.Separator();

                    SerializedProperty _spAO            = _soLmap.FindProperty("m_LightmapEditorSettings.m_AO");
                    SerializedProperty _spAODist        = _soLmap.FindProperty("m_LightmapEditorSettings.m_AOMaxDistance");
                    SerializedProperty _spAOExpIndirect = _soLmap.FindProperty("m_LightmapEditorSettings.m_CompAOExponent");
                    SerializedProperty _spAOExpDirect   = _soLmap.FindProperty("m_LightmapEditorSettings.m_CompAOExponentDirect");

                    if (Toggle(_spAO, new GUIContent("Ambient Occlusion")))
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(_spAODist, new GUIContent("Max Distance"));
                        EditorGUILayout.Slider(_spAOExpIndirect, 0, 10, new GUIContent("Indirect"));
                        EditorGUILayout.Slider(_spAOExpDirect, 0, 10, new GUIContent("Direct"));
                        EditorGUI.indentLevel--;
                    }

                    EditorGUILayout.Separator();

                    SerializedProperty _spFinalGather       = _soLmap.FindProperty("m_LightmapEditorSettings.m_FinalGather");
                    SerializedProperty _spFinalGatherRayCnt = _soLmap.FindProperty("m_LightmapEditorSettings.m_FinalGatherRayCount");
                    SerializedProperty _spFinalGatherFilter = _soLmap.FindProperty("m_LightmapEditorSettings.m_FinalGatherFiltering");

                    if (Toggle(_spFinalGather, new GUIContent("Final Gather")))
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.PropertyField(_spFinalGatherRayCnt, new GUIContent("Ray Count"));
                        EditorGUILayout.PropertyField(_spFinalGatherFilter, new GUIContent("Filter"));
                        EditorGUI.indentLevel--;
                    }

                    EditorGUI.indentLevel--;
                }

                SerializedProperty _spAlbedoBoost        = _soLmap.FindProperty("m_GISettings.m_AlbedoBoost");
                SerializedProperty _spIndirectOuputScale = _soLmap.FindProperty("m_GISettings.m_IndirectOutputScale");
                SerializedProperty _spParams             = _soLmap.FindProperty("m_LightmapEditorSettings.m_LightmapParameters");

                EditorGUILayout.Slider(_spAlbedoBoost, 1, 10, new GUIContent("Bounce Boost"));
                EditorGUILayout.Slider(_spIndirectOuputScale, 0, 5, new GUIContent("Indirect Intensity"));
                EditorGUILayout.PropertyField(_spParams, new GUIContent("Default Parameters"));

                _soLmap.ApplyModifiedProperties();
                _soRend.ApplyModifiedProperties();

                EditorGUILayout.Separator();
                EditorGUILayout.Separator();

                if (GUILayout.Button("Bake All"))
                {
                    Lightmapping.BakeAsync();
                }

                if (GUILayout.Button("Bake (Preview)"))
                {
                    m_LastDirRes = LightmapEditorSettings.bakeResolution;
                    m_LasrIndRes = LightmapEditorSettings.realtimeResolution;

                    LightmapEditorSettings.bakeResolution     = m_LastDirRes * 0.5f;
                    LightmapEditorSettings.realtimeResolution = m_LasrIndRes * 0.5f;

                    Lightmapping.completed += OnBakeCompleted;

                    Lightmapping.BakeAsync();
                }

                if (GUILayout.Button("Bake Light Probes Only"))
                {
                    Lightmapping.BakeAsync();
                }

                EditorGUI.EndDisabledGroup();

                EditorGUI.BeginDisabledGroup(!Lightmapping.isRunning);

                if (GUILayout.Button("Cancel"))
                {
                    Lightmapping.Cancel();
                }

                EditorGUI.EndDisabledGroup();

                EditorGUILayout.Separator();
                EditorGUILayout.Separator();

                EditorGUI.indentLevel--;
            }

            EditorGUILayout.EndToggleGroup();
            Line();
        }
Beispiel #6
0
    public override IEnumerator Execute(UTContext context)
    {
        if (UTPreferences.DebugMode)
        {
            Debug.Log("Applying lightmap settings", this);
        }
        LightmapEditorSettings.aoAmount        = aoAmount.EvaluateIn(context);
        LightmapEditorSettings.aoContrast      = aoContrast.EvaluateIn(context);
        LightmapEditorSettings.aoMaxDistance   = aoMaxDistance.EvaluateIn(context);
        LightmapEditorSettings.bounceBoost     = bounceBoost.EvaluateIn(context);
        LightmapEditorSettings.bounceIntensity = bounceIntensity.EvaluateIn(context);
        LightmapEditorSettings.bounces         = bounces.EvaluateIn(context);
        LightmapEditorSettings.finalGatherContrastThreshold = finalGatherContrastTreshold.EvaluateIn(context);
        LightmapEditorSettings.finalGatherGradientThreshold = finalGatherGradientTreshold.EvaluateIn(context);
        LightmapEditorSettings.finalGatherRays    = finalGatherRays.EvaluateIn(context);
        LightmapEditorSettings.lockAtlas          = lockAtlas.EvaluateIn(context);
        LightmapEditorSettings.maxAtlasHeight     = maxAtlasHeight.EvaluateIn(context);
        LightmapEditorSettings.maxAtlasWidth      = maxAtlasWidth.EvaluateIn(context);
        LightmapEditorSettings.padding            = padding.EvaluateIn(context);
        LightmapEditorSettings.quality            = quality.EvaluateIn(context);
        LightmapEditorSettings.resolution         = resolution.EvaluateIn(context);
        LightmapEditorSettings.skyLightColor      = skyLightColor.EvaluateIn(context);
        LightmapEditorSettings.skyLightIntensity  = skyLightIntensity.EvaluateIn(context);
        LightmapEditorSettings.textureCompression = textureCompression.EvaluateIn(context);
        LightmapSettings.lightmapsMode            = lightMapsMode.EvaluateIn(context);
        if (UTPreferences.DebugMode)
        {
            Debug.Log("Lightmap settings applied.", this);
        }
        var whatReallyToBake = whatToBake.EvaluateIn(context);

        switch (whatReallyToBake)
        {
        case UTTypeOfBake.Everything:
            Debug.Log("Building lightmaps for current scene. This may take a while.", this);
            if (!Lightmapping.BakeAsync())
            {
                throw new UTFailBuildException("Lightmapping was not finished successfully.", this);
            }
            break;

        case UTTypeOfBake.SelectionOnly:
            Debug.Log("Building lightmaps for current selection. This may take a while.", this);
            if (!Lightmapping.BakeSelectedAsync())
            {
                throw new UTFailBuildException("Lightmapping was not finished successfully.", this);
            }
            break;

        case UTTypeOfBake.LightProbesOnly:
            Debug.Log("Building light probes for current scene. This may take a while.", this);
            if (!Lightmapping.BakeLightProbesOnlyAsync())
            {
                throw new UTFailBuildException("Lightmapping was not finished successfully.", this);
            }
            break;
        }
        do
        {
            yield return("");

            if (context.CancelRequested)
            {
                Lightmapping.Cancel();
            }
        } while (Lightmapping.isRunning);
        Debug.Log("Lightmapping finished.", this);
    }