public static BakeSetSettingsDialog ShowDialog(string bakeSetName, List <LightEntry> lightGroups, bool activeSet, bool forceAllLights, ResultCallback resultCallback)
        {
            m_active         = true;
            m_resultCallback = resultCallback;
            BakeSetSettingsDialog window = EditorWindow.CreateInstance <BakeSetSettingsDialog>();

            window.m_activeSet      = activeSet;
            window.m_bakeSetName    = bakeSetName;
            window.m_forceAllLights = forceAllLights;

            Vector2 point = GUIUtility.GUIToScreenPoint(Event.current.mousePosition);

            window.position         = new Rect(point.x, point.y, 250, 300);
            window.m_selectedLights = new List <LightEntry>(lightGroups);
            DDRSettings.GatherLightGroups(ref window.m_groups);
            window.ShowPopup();
            return(window);
        }
        void OnGUI()
        {
            if (SceneManager.GetActiveScene().name == "")
            {
                GUILayout.Space(50);
                EditorGUILayout.HelpBox("Save the scene to begin baking", MessageType.Info);
                return;
            }

            if (!DaydreamRendererImportSettings.BakingEnabledForScene)
            {
                GUILayout.Space(50);
                EditorGUILayout.HelpBox("Enable vertex baking to use Daydream Static Lighting", MessageType.Info);
                if (GUILayout.Button("Enable Vertex Baking For Scene"))
                {
                    DaydreamRendererImportSettings.BakingEnabledForScene = true;
                }
                return;
            }

            if (!s_settingsRestored)
            {
                BakeData.Instance().SaveBakeSettings();
                s_settingsRestored = true;
            }

            if (Event.current.rawType == EventType.MouseUp)
            {
                if (s_settingsDirty)
                {
                    s_settingsDirty = false;
                    BakeData.Instance().SaveBakeSettings();
                }
            }

            if (s_bakeInProgress)
            {
                if (EditorUtility.DisplayCancelableProgressBar("Daydream Baker", "Baking meshes", VertexBakerLib.Instance.BakeProgress()))
                {
                    VertexBakerLib.Instance.BakeCancel();
                    if (!s_bakeInProgress)
                    {
                        s_bakeIsFinished = true;
                    }
                }

                if (s_bakeIsFinished)
                {
                    s_bakeIsFinished = false;
                    s_bakeInProgress = false;
                    EditorUtility.ClearProgressBar();

                    VertexBakerLib.Instance.BakeFinish(delegate(string msg, float complete)
                    {
                        EditorUtility.DisplayProgressBar("Daydream Baker", msg, complete);
                    });
                    EditorUtility.ClearProgressBar();

                    // queue up next bake
                    if (s_bakeSetQueue.Count > 0)
                    {
                        int bakeSet = s_bakeSetQueue.Dequeue();
                        BakeData.Instance().GetBakeSettings().SetBakeSetIndex(bakeSet);
                        BakeScene();
                    }
                }
            }

            EditorGUI.BeginChangeCheck();

#if DDR_RUNTIME_DLL_LINKING_
            if (GUILayout.Button("Reload Library"))
            {
                if (VertexBakerLib.Instance.LibLoaded)
                {
                    VertexBakerLib.Instance.UnloadLib();
                }
                else
                {
                    VertexBakerLib.Instance.LoadLib();
                }
            }
#endif

            DDRSettings settingsData = BakeData.Instance().GetBakeSettings();

            string[] ids = new string[settingsData.m_settingsList.Count];
            for (int i = 0, k = settingsData.m_settingsList.Count; i < k; ++i)
            {
                ids[i] = settingsData.m_settingsList[i].m_settingsId;
            }

            // update selected data
            GUILayout.Space(20);
            int settingsIndex = -1;
            int selected      = DrawToolBar(settingsData.GetBakeSetIndex(), ids, true, out settingsIndex);

            if (selected >= 0)
            {
                int cur = settingsData.GetBakeSetIndex();
                settingsData.SetBakeSetIndex(selected);

                if (cur != selected)
                {
                    DaydreamVertexLighting.UpdateAllVertexLighting(settingsData.SelectedBakeSet.m_settingsId);
                }
            }

            BakeSettings settings = settingsData.SelectedBakeSet;

            if (selected == Toolbar.kAdd)
            {
                if (!BakeSetDialog.m_active)
                {
                    BakeSetDialog.ShowDialog(delegate(bool result, string name)
                    {
                        if (result)
                        {
                            BakeSettings newSettings = new BakeSettings(name);
                            settingsData.AddBakeSettings(newSettings);
                            EditorUtility.SetDirty(settingsData);
                        }
                    });
                }
            }
            else if (selected == Toolbar.kRemove)
            {
                if (settingsData.m_settingsList.Count > 1)
                {
                    int current = settingsData.GetBakeSetIndex();

                    settingsData.RemoveBakeSetting(current);
                    EditorUtility.SetDirty(settingsData);

                    --current;
                    if (current < 0)
                    {
                        current = 0;
                    }

                    settingsData.SetBakeSetIndex(current);
                    DaydreamVertexLighting.UpdateAllVertexLighting(settingsData.SelectedBakeSet.m_settingsId);
                }
            }
            else if (selected == Toolbar.kSettings)
            {
                if (!BakeSetSettingsDialog.m_active)
                {
                    BakeSettings curSettings = settingsData.m_settingsList[settingsIndex];
                    s_settingsDialog = BakeSetSettingsDialog.ShowDialog(curSettings.m_settingsId, curSettings.m_lightList
                                                                        , curSettings.m_activeSet
                                                                        , curSettings.m_forceAllLights
                                                                        , delegate(BakeSetSettingsDialog.Result result, string bakeSetName, List <LightEntry> selectedLights, bool activeSet, bool forceAllLights)
                    {
                        s_settingsDialog = null;
                        if (settingsData.m_settingsList.Count > 1 && result == BakeSetSettingsDialog.Result.Remove)
                        {
                            settingsData.RemoveBakeSetting(settingsIndex);
                            EditorUtility.SetDirty(settingsData);
                            curSettings = settingsData.m_settingsList[settingsIndex];
                        }
                        else if (result == BakeSetSettingsDialog.Result.Ok)
                        {
                            curSettings.m_settingsId     = bakeSetName;
                            curSettings.m_activeSet      = activeSet;
                            curSettings.m_forceAllLights = forceAllLights;
                            if (selectedLights != null)
                            {
                                // remove empty or stale entries
                                var idsInFile = Utilities.LightsByLocalFileId();
                                selectedLights.RemoveAll(delegate(LightEntry obj){
                                    return(string.IsNullOrEmpty(obj.m_group) && obj.m_idInFile == 0 ||
                                           (!idsInFile.ContainsKey(obj.m_idInFile) &&
                                            (string.IsNullOrEmpty(obj.m_group) || GameObject.Find(obj.m_group) == null)));
                                });

                                curSettings.m_lightList = selectedLights;
                            }
                            EditorUtility.SetDirty(settingsData);
                        }
                    });
                }
                else if (s_settingsDialog != null)
                {
                    s_settingsDialog.CancelDialog();
                }
            }

            DrawShadowAndAOSettings(settings, settingsData);

            //settings.m_diffuseEnergyConservation = EditorGUILayout.Slider("Diffuse Conservation", settings.m_diffuseEnergyConservation, 0f, 1f);

            EditorGUILayout.LabelField(Styles.m_ambientHeader);

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(Styles.kIndent);
            EditorGUILayout.BeginVertical();

            Color solidColor = settings.GetColorSolid();

            Color gradSky     = settings.GetColorGradient(GradientIndex.Sky);
            Color gradEquator = settings.GetColorGradient(GradientIndex.Equator);
            Color gradGround  = settings.GetColorGradient(GradientIndex.Ground);

            Color posX = settings.GetColorCubeFace(Face.PosX);
            Color posY = settings.GetColorCubeFace(Face.PosY);
            Color posZ = settings.GetColorCubeFace(Face.PosZ);

            Color negX = settings.GetColorCubeFace(Face.NegX);
            Color negY = settings.GetColorCubeFace(Face.NegY);
            Color negZ = settings.GetColorCubeFace(Face.NegZ);

            settings.m_colorMode = (BakeSettings.AmbientColorMode)EditorGUILayout.EnumPopup(Styles.m_ambientSource, settings.m_colorMode);

            // Draw color
            EditorGUILayout.BeginHorizontal();
            {
                //GUILayout.Space(Styles.kIndent);
                EditorGUILayout.BeginVertical();

                if (settings.m_colorMode == BakeSettings.AmbientColorMode.kColorCube)
                {
                    // Check for color value change
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(Styles.kIndent);
                    EditorGUILayout.BeginVertical();

                    DrawColorCube(posX, negX, posY, negY, posZ, negZ);
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                }
                else if (settings.m_colorMode == BakeSettings.AmbientColorMode.kColorGradient)
                {
                    // Check for color value change
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(Styles.kIndent);
                    EditorGUILayout.BeginVertical();

                    DrawColorGradient(gradGround, gradEquator, gradSky);
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(Styles.kIndent);
                    Color c = EditorGUILayout.ColorField(Styles.m_ambientColor, solidColor);
                    EditorGUILayout.EndHorizontal();

                    if (c != solidColor)
                    {
                        settings.SetColorSolid(c);
                    }
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();

            float max = settings.m_ambientMax;
            settings.m_ambientMax = EditorGUILayout.Slider(Styles.m_max, settings.m_ambientMax, 0f, 1f);
            if (!s_maxSliderActive && max != settings.m_ambientMax)
            {
                s_control         = EditorGUIUtility.hotControl;
                s_maxSliderActive = true;
            }
            if (s_maxSliderActive && s_control != EditorGUIUtility.hotControl)
            {
                s_control         = -1;
                s_maxSliderActive = false;
            }

            float min = settings.m_ambientMin;
            settings.m_ambientMin = EditorGUILayout.Slider(Styles.m_min, settings.m_ambientMin, 0f, 1f);
            if (!s_minSliderActive && min != settings.m_ambientMin)
            {
                s_control         = EditorGUIUtility.hotControl;
                s_minSliderActive = true;
            }
            if (s_minSliderActive && s_control != EditorGUIUtility.hotControl)
            {
                s_control         = -1;
                s_minSliderActive = false;
            }

            settings.m_ambientMax = Mathf.Clamp(settings.m_ambientMax, settings.m_ambientMin, 1f);
            settings.m_ambientMin = Mathf.Clamp(settings.m_ambientMin, 0f, settings.m_ambientMax);

            if (s_minSliderActive || s_maxSliderActive)
            {
                Color a = Color.black;
                float t = settings.m_ambientMin;
                if (s_maxSliderActive)
                {
                    t = settings.m_ambientMax;
                }

                if (settings.m_colorMode == BakeSettings.AmbientColorMode.kColorCube)
                {
                    Color px = Color.Lerp(a, posX, t);
                    Color nx = Color.Lerp(a, negX, t);
                    Color py = Color.Lerp(a, posY, t);
                    Color ny = Color.Lerp(a, negY, t);
                    Color pz = Color.Lerp(a, posZ, t);
                    Color nz = Color.Lerp(a, negZ, t);

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(Styles.kIndent);
                    EditorGUILayout.BeginVertical();
                    DrawColorCube(px, nx, py, ny, pz, nz, false);
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                }
                else
                if (settings.m_colorMode == BakeSettings.AmbientColorMode.kColorGradient)
                {
                    Color sky     = Color.Lerp(a, gradSky, t);
                    Color equator = Color.Lerp(a, gradEquator, t);
                    Color ground  = Color.Lerp(a, gradGround, t);

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(Styles.kIndent);
                    EditorGUILayout.BeginVertical();
                    DrawColorGradient(ground, equator, sky, false);
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    Color solid = Color.Lerp(a, solidColor, t);

                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(Styles.kIndent);
                    EditorGUILayout.BeginVertical();
                    EditorGUILayout.ColorField(solid);
                    EditorGUILayout.EndVertical();
                    EditorGUILayout.EndHorizontal();
                }
            }

            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(50);

            if (VertexBakerLib.Instance.BakeInProgress())
            {
                if (GUILayout.Button("Cancel"))
                {
                    VertexBakerLib.Instance.BakeCancel();
                }
            }
            else
            {
                settings.m_bakeAllLightSets = EditorGUILayout.ToggleLeft(Styles.m_bakeAll, settings.m_bakeAllLightSets);

                if (GUILayout.Button("Bake Scene"))
                {
                    if (settings.m_bakeAllLightSets)
                    {
                        // enqueue all bake sets
                        for (int i = 0, k = settingsData.m_settingsList.Count; i < k; ++i)
                        {
                            if (settingsData.m_settingsList[i].m_activeSet)
                            {
                                s_bakeSetQueue.Enqueue(i);
                            }
                        }

                        // set the first bake set
                        if (s_bakeSetQueue.Count > 0)
                        {
                            int bakeSet = s_bakeSetQueue.Dequeue();
                            settingsData.SetBakeSetIndex(bakeSet);
                        }
                    }

                    BakeScene();
                }
            }

            BakeSets bakeSets = BakeData.Instance().GetBakeSets();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (bakeSets.m_containers.Count > 0 && GUILayout.Button(Styles.m_clearAllBakeData, Styles.m_clearButton))
            {
                if (EditorUtility.DisplayDialog(Styles.kEditorTitle, "Clear all data, are you sure?", "Yes", "No"))
                {
                    for (int i = 0, k = bakeSets.m_containers.Count; i < k; ++i)
                    {
                        List <Mesh> meshes = bakeSets.m_containers[i].m_list;
                        for (int j = 0; j < meshes.Count; ++j)
                        {
                            DestroyImmediate(meshes[j], true);
                        }
                    }
                }

                EditorUtility.SetDirty(bakeSets);
                AssetDatabase.SaveAssets();
            }
            GUILayout.EndHorizontal();


            if (EditorGUI.EndChangeCheck())
            {
                s_settingsDirty = true;
                Undo.RecordObject(settingsData, "SettingsUndo");
                //VertexBakerLib.Instance.WriteSettings();
                //VertexBakerLib.Instance.SaveSettings();
            }
        }