public static void OpenWindow()
        {
            DaydreamRendererImportManager window = EditorWindow.GetWindow <DaydreamRendererImportManager>(Styles.kEditorTitle);

            window.Show();
            window.minSize = new Vector2(300, 500);
        }
Beispiel #2
0
        void OnGUI()
        {
            GUILayout.Space(10);

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Advanced Settings");
            if (GUILayout.Button("X"))
            {
                if (m_resultCallback != null)
                {
                    m_resultCallback(Result.Cancel);
                }
                CloseDialog();
            }
            EditorGUILayout.EndHorizontal();

            DaydreamRenderer renderer = FindObjectOfType <DaydreamRenderer>();

            if (renderer == null)
            {
                EditorGUILayout.LabelField("Daydream Renderer Not Enabled");
                return;
            }

            // ------------------------------------------------------------------- //
            // Daydream Lighting Advanced settings
            GUILayout.Space(5);
            DaydreamRendererImportManager.DrawSection(240, 1);
            renderer.m_enableManualLightingComponents = EditorGUILayout.BeginToggleGroup(Styles.toggleComponents, renderer.m_enableManualLightingComponents);
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(Styles.addComponents))
                {
                    DaydreamRendererImportManager.ApplyLightingComponents();
                }
                if (GUILayout.Button(Styles.removeComponents))
                {
                    DaydreamRendererImportManager.RemoveAllLightingComponents();
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.EndToggleGroup();

            // Add components to FBX and Prefabs not in the scene
            // TODO - rework this UI

            /*
             * EditorGUILayout.BeginHorizontal();
             * if (GUILayout.Button(Styles.addComponentsToProject))
             * {
             *  DaydreamRendererImportManager.ApplyLightingToProject();
             * }
             * if (GUILayout.Button(Styles.removeComponentsFromProject))
             * {
             *  DaydreamRendererImportManager.RemoveAllLightingComponents();
             * }
             * EditorGUILayout.EndHorizontal();
             * //*/
        }
        public static void Init()
        {
            Configure();
            DaydreamRendererImportManager window = EditorWindow.GetWindow <DaydreamRendererImportManager>("Import Wizard");

            window.Show();
        }
            static void Update()
            {
                if (!string.IsNullOrEmpty(SceneManager.GetActiveScene().name) && SceneManager.GetActiveScene().isLoaded)
                {
                    if (DaydreamRendererImportSettings.FirstRun)
                    {
                        DaydreamRendererImportSettings.FirstRun = false;
                        DaydreamRendererImportManager.OpenWindow();
                    }
                }

                DaydreamRenderer renderer = FindObjectOfType <DaydreamRenderer>();

                if (renderer != null && !renderer.m_enableManualLightingComponents && (DateTime.Now - s_lastUpdate).TotalSeconds > 2)
                {
                    ApplyLightingComponents();
                    s_lastUpdate = DateTime.Now;
                }
            }
            static void Update()
            {
                DaydreamRendererImportSettings settings = BakeData.Instance().GetImportSettings();

                if (!string.IsNullOrEmpty(SceneManager.GetActiveScene().name) && SceneManager.GetActiveScene().isLoaded)
                {
                    if (settings != null && settings.m_firstRun)
                    {
                        EditorApplication.update -= Update;
                        settings.m_firstRun       = false;
                        BakeData.Instance().SaveImportSettings();

                        DaydreamRendererImportManager.Init();
                    }
                }

                if (settings.m_enableLightingComponentsAutoAdd && settings.m_daydreamLightinSystemEnabled && (DateTime.Now - s_lastUpdate).TotalSeconds > 2)
                {
                    s_lastUpdate = DateTime.Now;
                    ApplyLightingComponents();
                }
            }
        void OnGUI()
        {
            DaydreamRenderer renderer = FindObjectOfType <DaydreamRenderer>();

            if (renderer == null)
            {
                GUILayout.Space(50);
                EditorGUILayout.HelpBox("Enable Daydream Renderer To Start Baking", MessageType.Info);
                if (GUILayout.Button("Launch Daydream Wizard"))
                {
                    DaydreamRendererImportManager.OpenWindow();
                }
                return;
            }

            if (SceneManager.GetActiveScene().name == "")
            {
                GUILayout.Space(50);
                EditorGUILayout.HelpBox("Save the scene to begin baking", MessageType.Info);
                return;
            }

            if (!renderer.m_enableStaticLightingForScene)
            {
                GUILayout.Space(50);
                EditorGUILayout.HelpBox("Enable vertex baking to use Daydream Static Lighting", MessageType.Info);
                if (GUILayout.Button("Enable Vertex Baking For Scene"))
                {
                    renderer.m_enableStaticLightingForScene = 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();
            }
        }
Beispiel #7
0
        void OnGUI()
        {
            if (s_materialHistory == null)
            {
                Configure();
            }

            //---------------------------------------------------------------------//
            // Daydream Material Wizard
            GUILayout.Space(5);
            EditorGUILayout.LabelField(Styles.kTitle, DaydreamRendererImportManager.Styles.sectionLabel, GUILayout.Height(25));
            DaydreamRendererImportManager.DrawSection(500, 1);
            GUILayout.Space(5);

            EditorGUILayout.HelpBox(Styles.kMatierlConversionInfo, MessageType.Info);

            m_UIFade.target = EditorGUILayout.Foldout(m_UIFade.target, "Legend");

            if (EditorGUILayout.BeginFadeGroup(m_UIFade.faded))
            {
                for (int i = 0; i < Styles.matTypeContent.Length; i += 2)
                {
                    EditorGUILayout.BeginHorizontal();

                    // icon
                    EditorGUILayout.LabelField("", Styles.matTypeIcons[i], GUILayout.Width(16));
                    // info
                    EditorGUILayout.LabelField(Styles.matTypeContent[i].tooltip);

                    if (i + 1 < Styles.matTypeContent.Length)
                    {
                        // icon
                        EditorGUILayout.LabelField("", Styles.matTypeIcons[i + 1], GUILayout.Width(16));
                        // info
                        EditorGUILayout.LabelField(Styles.matTypeContent[i + 1].tooltip);
                    }

                    EditorGUILayout.EndHorizontal();
                }
            }
            EditorGUILayout.EndFadeGroup();


            GUILayout.Space(10);


            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Convert all materials used in the 'Scene'"))
            {
                List <Material> conversionList = new List <Material>();
                var             iter           = m_infoMap.GetEnumerator();
                while (iter.MoveNext())
                {
                    if (iter.Current.Value[0] != null && iter.Current.Value[0].sceneType > 0)
                    {
                        conversionList.Add(iter.Current.Value[0].m_material);
                    }
                }

                ConvertList(conversionList);

                if (EditorUtility.DisplayDialog(Styles.kTitle, "Would you like to bake vertex lighting now?", "Yes", "No"))
                {
                    DaydreamVertexLightingEditor.OpenWindow();
                }
                else
                {
                    // open up conversion dialog again
                    ShowDialog(null);
                }
            }

            if (GUILayout.Button("Convert all materials used in the 'Project'"))
            {
                List <Material> conversionList = new List <Material>();
                var             iter           = m_infoMap.GetEnumerator();
                while (iter.MoveNext())
                {
                    if (iter.Current.Value[0] != null)
                    {
                        conversionList.Add(iter.Current.Value[0].m_material);
                    }
                }

                ConvertList(conversionList);

                if (EditorUtility.DisplayDialog(Styles.kTitle, "Would you like to bake vertex lighting now?", "Yes", "No"))
                {
                    DaydreamVertexLightingEditor.OpenWindow();
                }
                else
                {
                    // open up conversion dialog again
                    ShowDialog(null);
                }
            }
            EditorGUILayout.EndHorizontal();

            DrawAllMaterials();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical();
            if (GUILayout.Button("Delete All Backup Data"))
            {
                if (EditorUtility.DisplayDialog(Styles.kTitle, "Delete all backup materials, are you sure?", "yes", "no"))
                {
                    for (int i = 0, c = s_materialHistory.m_backupMaterials.Count; i < c; ++i)
                    {
                        DestroyImmediate(s_materialHistory.m_backupMaterials[i], true);
                    }
                    s_materialHistory.m_backupMaterials.Clear();
                }
            }
            if (GUILayout.Button("Export Backups"))
            {
                List <string> assetPaths = new List <string>();
                if (!Directory.Exists(kAssetPathBackup + "/Export"))
                {
                    Directory.CreateDirectory(kAssetPathBackup + "/Export");
                }
                for (int i = 0, c = s_materialHistory.m_backupMaterials.Count; i < c; ++i)
                {
                    if (s_materialHistory.m_backupMaterials[i] != null)
                    {
                        Material copy = new Material(s_materialHistory.m_backupMaterials[i]);
                        copy.name = copy.name.Replace(kBackupPrefix, "");
                        AssetDatabase.CreateAsset(copy, kAssetPathBackup + "/Export/" + copy.name + ".mat");
                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();
                        assetPaths.Add(kAssetPathBackup + "/" + copy.name + ".mat");
                    }
                }
                if (assetPaths.Count > 0)
                {
                    EditorUtility.DisplayDialog(Styles.kTitle, "Materials written to " + kAssetPathBackup + "/Export", "ok");
                }
                else
                {
                    EditorUtility.DisplayDialog(Styles.kTitle, "Nothing to export", "ok");
                }
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();

            if (m_repaint)
            {
                List <GameObject> roots = Utilities.GetAllRoots();
                GatherMaterials(roots.ToArray());
                this.Repaint();
            }
        }
Beispiel #8
0
        public override void OnInspectorGUI()
        {
            bool             settingsChanged = false;
            DaydreamRenderer renderer        = target as DaydreamRenderer;

            Styles.Init();

            //This will add the material to the undo list, at the end of the frame Unity will check if its really changed and if so add it to the undo stack.
            //Since Unity does a binary comparison between the copied data and the original material - it should accurately determine if it has changed.
            //And since we're editing one material at a time, the extra memory (one extra copy of the Material) - the memory cost is reasonable.
            Undo.RecordObject(renderer, "Daydream Renderer Settings");

            DaydreamRendererImportManager.DrawDaydreamLightingToggle(renderer);
            //DaydreamRendererImportManager.DrawSection(500, 1);
            GUILayout.Space(5);

            // Material Conversion
            DaydreamRendererImportManager.DrawSection(500, 1);
            EditorGUILayout.LabelField(DaydreamRendererImportManager.Styles.kConversionWizardSegment, Styles.m_sectionLabel, GUILayout.Height(25));
            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(20);
            EditorGUILayout.BeginVertical();
            if (GUILayout.Button(DaydreamRendererImportManager.Styles.kOpenMaterialWizard, EditorStyles.toolbar))
            {
                MaterialConversionDialog.ShowDialog(null);
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(5);

            renderer.m_shadowSettings = EditorGUILayout.Foldout(renderer.m_shadowSettings, Styles.m_shadowSettingsUI);
            if (renderer.m_shadowSettings)
            {
                EditorGUI.indentLevel = 1;

                EditorGUI.BeginChangeCheck();
                renderer.m_shadowWidth      = EditorGUILayout.IntField(Styles.m_shadowWidthUI, renderer.m_shadowWidth);
                renderer.m_shadowHeight     = EditorGUILayout.IntField(Styles.m_shadowHeightUI, renderer.m_shadowHeight);
                renderer.m_sharpness        = EditorGUILayout.Slider(Styles.m_shadowSharpnessUI, renderer.m_sharpness, 0.0f, 1.0f);
                renderer.m_maxShadowCasters = EditorGUILayout.IntSlider(Styles.m_maxShadowCastersUI, renderer.m_maxShadowCasters, 0, 4);
                if (EditorGUI.EndChangeCheck())
                {
                    settingsChanged = true;
                }

                EditorGUI.indentLevel = 0;

                renderer.UpdateFilterParam();
            }

            renderer.m_ambientSettings = EditorGUILayout.Foldout(renderer.m_ambientSettings, Styles.m_ambientSettingsUI);
            if (renderer.m_ambientSettings)
            {
                EditorGUI.indentLevel = 1;

                EditorGUI.BeginChangeCheck();
                renderer.m_globalAmbientUp = EditorGUILayout.ColorField(Styles.m_ambientUpUI, renderer.m_globalAmbientUp);
                renderer.m_globalAmbientDn = EditorGUILayout.ColorField(Styles.m_ambientDownUI, renderer.m_globalAmbientDn);
                if (EditorGUI.EndChangeCheck())
                {
                    settingsChanged = true;
                    renderer.UpdateAmbientParam();
                    EditorUtility.SetDirty(renderer);
                }

                EditorGUI.indentLevel = 0;
            }

            renderer.m_fogSettings = EditorGUILayout.Foldout(renderer.m_fogSettings, Styles.m_fogSettingsUI);
            if (renderer.m_fogSettings)
            {
                EditorGUI.indentLevel = 1;

                EditorGUI.BeginChangeCheck();
                renderer.m_fogEnable       = EditorGUILayout.Toggle(Styles.m_fogEnable, renderer.m_fogEnable);
                renderer.m_heightFogEnable = EditorGUILayout.Toggle(Styles.m_fogHeightEnable, renderer.m_heightFogEnable);
                renderer.m_fogMode         = EditorGUILayout.Popup(Styles.m_fogModeLabel, renderer.m_fogMode, Styles.m_fogModes);

                EditorGUILayout.Space();

                if (renderer.m_fogMode == DaydreamRenderer.FogMode.Linear)
                {
                    renderer.m_fogLinear.x = EditorGUILayout.Slider(Styles.m_fogNear, renderer.m_fogLinear.x, 0.0f, 1000.0f);
                    renderer.m_fogLinear.y = EditorGUILayout.Slider(Styles.m_fogFar, renderer.m_fogLinear.y, 0.0f, 10000.0f);
                }
                if (renderer.m_fogMode != DaydreamRenderer.FogMode.Linear)
                {
                    renderer.m_fogHeight.w = EditorGUILayout.Slider(Styles.m_fogDensity, renderer.m_fogHeight.w, 0.0f, 1.0f);
                }

                renderer.m_fogLinear.z = EditorGUILayout.Slider(Styles.m_fogOpacity, renderer.m_fogLinear.z, 0.0f, 1.0f);
                renderer.m_fogLinear.w = EditorGUILayout.Slider(Styles.m_fogColorScale, renderer.m_fogLinear.w, 0.0f, 4.0f);

                if (renderer.m_heightFogEnable)
                {
                    renderer.m_fogHeight.x = EditorGUILayout.Slider(Styles.m_fogMinHeight, renderer.m_fogHeight.x, -100.0f, 100.0f);
                    renderer.m_fogHeight.y = EditorGUILayout.Slider(Styles.m_fogMaxHeight, renderer.m_fogHeight.y, -100.0f, 100.0f);
                    renderer.m_fogHeight.z = EditorGUILayout.Slider(Styles.m_fogThickness, renderer.m_fogHeight.z, 0.0f, 100.0f);
                }

                renderer.m_fogColorNear = EditorGUILayout.ColorField(Styles.m_fogColorNear, renderer.m_fogColorNear);
                renderer.m_fogColorFar  = EditorGUILayout.ColorField(Styles.m_fogColorFar, renderer.m_fogColorFar);
                if (EditorGUI.EndChangeCheck())
                {
                    settingsChanged = true;
                    renderer.UpdateFogParam();
                    EditorUtility.SetDirty(renderer);
                }

                EditorGUI.indentLevel = 0;
            }

            renderer.m_showFPS = EditorGUILayout.Toggle(Styles.m_showFpsUI, renderer.m_showFPS);

    #if UNITY_EDITOR
            if (settingsChanged && !Application.isPlaying)
            {
                EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
            }
    #endif
        }
        public static void DrawDaydreamLightingToggle(DaydreamRenderer renderer)
        {
            if (renderer == null)
            {
                return;
            }

            // determine lighting system in use
            const int kDaydreamLighting = 0;
            const int kUnityLighting    = 1;
            int       selectedIndex     = renderer.m_daydreamLighting ? kDaydreamLighting : kUnityLighting;

            EditorGUI.BeginChangeCheck();

            // draw section separator
            DrawSection(500, 1);
            EditorGUILayout.BeginHorizontal();
            if (selectedIndex == kDaydreamLighting)
            {
                EditorGUILayout.LabelField("Lighting System", Styles.sectionLabel, GUILayout.Width(105), GUILayout.Height(25));
                GUILayout.Button("", Styles.daydreamLightingStyle, GUILayout.Width(25), GUILayout.Height(25));
            }
            else
            {
                EditorGUILayout.LabelField("Lighting System", Styles.sectionLabel, GUILayout.Width(105), GUILayout.Height(25));
                GUILayout.Button("", Styles.unityLightingStyle, GUILayout.Width(25), GUILayout.Height(25));
            }

            EditorGUILayout.EndHorizontal();
            GUILayout.Space(5);

            EditorGUI.BeginChangeCheck();
            DREditorUtility.RadioButtonOutput selected = DREditorUtility.DrawRadioButton(selectedIndex, Styles.m_lightingSystemUI, Styles.m_buttonUnselected, Styles.m_buttonSelected, 20, 32, 150, new bool[] { true, false });
            if (EditorGUI.EndChangeCheck())
            {
                if (selected.m_selectedIndex == kDaydreamLighting)
                {
                    if (renderer.m_daydreamLighting == false)
                    {
                        renderer.m_daydreamLighting = true;
                        if (!renderer.m_enableManualLightingComponents)
                        {
                            DaydreamRendererImportManager.ApplyLightingComponents();
                        }
                        renderer.EnableEnlighten(false);
                    }
                }
                else
                {
                    if (renderer.m_daydreamLighting == true)
                    {
                        renderer.m_daydreamLighting = false;
                        if (!renderer.m_enableManualLightingComponents)
                        {
                            DaydreamRendererImportManager.RemoveAllLightingComponents();
                        }
                        renderer.EnableEnlighten(true);
                    }
                }

                // display advanced settings
                if (selected.m_dropDownSelected == kDaydreamLighting)
                {
                    LightSystemDialog.ShowDialog(null);
                }
            }
            GUILayout.Space(5);
        }
        void OnGUI()
        {
            DrawCenteredLogo(100);

            DaydreamRenderer renderer = FindObjectOfType <DaydreamRenderer>();

            if (renderer == null)
            {
                m_UIFade.target = false;

                EditorGUILayout.LabelField(Styles.ddrNotEnabled, Styles.helpText);

                GUILayout.Space(10);

                GUILayout.BeginVertical();
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (DREditorUtility.FlexibleHorizButton(Styles.kAddDrToScene, Styles.boldButton, GUILayout.Width(280), GUILayout.Height(50)))
                {
                    GameObject go = GameObject.Find(kDaydreamObjectName);
                    if (go == null)
                    {
                        go = new GameObject(kDaydreamObjectName);
                    }

                    go.AddComponent <DaydreamRenderer>();
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();

                return;
            }
            else
            {
                m_UIFade.target = true;
            }

            //---------------------------------------------------------------------//
            // Daydream lighting
            if (EditorGUILayout.BeginFadeGroup(m_UIFade.faded))
            {
                EditorGUILayout.LabelField(Styles.kDaydreamEnabled, Styles.helpText);

                DrawDaydreamLightingToggle(renderer);
            }
            EditorGUILayout.EndFadeGroup();


            //---------------------------------------------------------------------//
            // Material conversion
            GUILayout.Space(10);
            DaydreamRendererImportManager.DrawSection(500, 1);
            EditorGUILayout.LabelField(Styles.kConversionWizardSegment, DaydreamRendererImportManager.Styles.sectionLabel, GUILayout.Height(25));
            GUILayout.Space(5);

            EditorGUILayout.HelpBox(Styles.kMaterialWizardInfo, MessageType.Info);

            if (GUILayout.Button(Styles.kOpenMaterialWizard))
            {
                MaterialConversionDialog.ShowDialog(null);
            }

            //---------------------------------------------------------------------//
            // Documentation
            GUILayout.Space(10);
            DaydreamRendererImportManager.DrawSection(500, 1);
            EditorGUILayout.LabelField("Documentation", DaydreamRendererImportManager.Styles.sectionLabel, GUILayout.Height(25));
            if (GUILayout.Button(Styles.kOpenDocumentation))
            {
                Application.OpenURL("https://github.com/googlevr/daydream-renderer-for-unity/blob/master/README.md");
            }
        }