//#define TEMPLY_COMMENT_PROFLARE
//#define TEMPLY_COMMENT_PARAMDEBUG
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
using System.IO;
using UnityEngine.Assertions;
using UnityEngine.Rendering;


namespace X2Engine
{
    class DoCreateEnvProfile : EndNameEditAction
    {
        public override void Action(int instanceId, string pathName, string resourceFile)
        {
            var profile = EnvProfileInspector.CreateEnvProfileAtPath(pathName);
            ProjectWindowUtil.ShowCreatedAsset(profile);
        }
    }

    [CustomEditor(typeof(EnvironmentProfile))]
    public class EnvProfileInspector : Editor
    {
//        [MenuItem("Tools/YJHTest/Environment Profile Convert")]
//        public static void ConvertProfile()
//        {
//#if SCENE_EDITOR
//            string sceneSourcePath = "Assets/Asset/art_resource/profiler/";
//#else
//            string sceneSourcePath = "Assets/Resources/asset/art_resource/profiler/";
//#endif
//            string[] filesNames = Directory.GetFiles(sceneSourcePath, "*.asset", SearchOption.AllDirectories);
//            foreach (var fileName in filesNames)
//            {
//                EnvironmentProfile profile = AssetDatabase.LoadAssetAtPath<EnvironmentProfile>(fileName);
//                if (profile)
//                {
//                    var tex = profile.skybox.texture;
//                    var fullPath = AssetDatabase.GetAssetPath(tex);
//#if SCENE_EDITOR
//                        profile.skybox.texPath = fullPath.Replace("Assets/Asset/", "");
//#else
//                    profile.skybox.texPath = fullPath.Replace("Assets/Resources/asset/", "");
//#endif
//                    AssetDatabase.SaveAssets();
//                }
//            }

//            AssetDatabase.SaveAssets();
//            AssetDatabase.Refresh();
//        }

        [MenuItem("Assets/Create/Environment Profile")]
        public static void CreateNewProfile()
        {
            ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreateEnvProfile>(), "NewEnvProfile.asset", null, null);
        }

        public static EnvironmentProfile CreateEnvProfileAtPath(string path)
        {
            var profile = ScriptableObject.CreateInstance<EnvironmentProfile>();
            profile.name = Path.GetFileName(path);
            AssetDatabase.CreateAsset(profile, path);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
            return profile;
        }

        //EnvironmentProfile m_profile;
        EnvProfileDrawer m_Drawer;
       
        void OnEnable()
        {
            //m_profile = target as EnvironmentProfile;
            m_Drawer = new EnvProfileDrawer(this);
            m_Drawer.Init(target as EnvironmentProfile, serializedObject);
        }

        void OnDisable()
        {
            m_Drawer = null;
        }

        public override void OnInspectorGUI()
        {
            //base.OnInspectorGUI();

            m_Drawer.OnGUI();

        }

    }

    public sealed class EnvProfileDrawer
    {
        EnvironmentProfile m_Asset;
        SerializedObject m_SerializedObject;

        public EnvironmentProfile Asset { get { return m_Asset; } }

        public EnvProfileDrawer(Editor editor)
        {
            Assert.IsNotNull(editor);
        }

        private string m_InstallPath;
        private string m_InspectorGUIPath;
        Texture2D m_SeperatorTex;

        public void Init(EnvironmentProfile asset, SerializedObject serializedObject)
        {
            Assert.IsNotNull(asset);
            Assert.IsNotNull(serializedObject);
            m_Asset = asset;
            m_SerializedObject = serializedObject;

            string scriptLocation = AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(asset));
            m_InstallPath = scriptLocation.Replace("/EnvironmentProfile.cs", "");
            m_InspectorGUIPath = m_InstallPath + "/Editor/Textures";
            m_SeperatorTex = AssetDatabase.LoadAssetAtPath(m_InspectorGUIPath + "/Seperator.png", typeof(Texture2D)) as Texture2D;
        }


        public void OnGUI()
        {
            if (null == m_Asset) return;

            if (m_SeperatorTex == null) { m_SeperatorTex = new Texture2D(1, 1); }
            //EditorGUI.BeginChangeCheck();

            m_SerializedObject.Update();
            Undo.RecordObject(m_Asset, "Undo Environment Profile");

            //SerializedProperty property = m_SerializedObject.GetIterator();
            //bool expanded = true;
            //while (property.NextVisible(expanded))
            //{
            //    using (new EditorGUI.DisabledScope("m_Script" == property.propertyPath))
            //    {
            //        EditorGUILayout.PropertyField(property, true);
            //    }
            //    expanded = false;
            //}
            EditorGUILayout.Separator();
            DrawSunSetting();

            EditorGUILayout.Separator();
            DrawAmbientSetting();

            //EditorGUILayout.Separator();
            //DrawAmbientSettingOfCharacter();

            EditorGUILayout.Separator();
            DrawSkyboxSetting();

            EditorGUILayout.Separator();
            DrawAtmosphericScatteringSetting();
            //DrawSkySetting();

            //EditorGUILayout.Separator();
            //DrawNightSkySetting();

            //EditorGUILayout.Separator();
            //DrawFogSetting();

            //EditorGUILayout.Separator();
            //DrawOceanFogSetting();

            EditorGUILayout.Separator();
            DrawCloud2dSetting();

            EditorGUILayout.Separator();
            DrawWeatherSystemSetting();

            //EditorGUILayout.Separator();
            //DrawCloudShadowSetting();

            //EditorGUILayout.Separator();
            //DrawCloudSetting();

            EditorGUILayout.Separator();
            DrawBlackHoleSetting();


            EditorGUILayout.Separator();
            DrawVolumetricFogSetting();

            EditorGUILayout.Space();


            EditorUtility.SetDirty(m_Asset);

            m_SerializedObject.ApplyModifiedProperties();
            //EditorGUI.EndChangeCheck();
        }

        static bool s_showSun = true;
        static bool s_ShadowAlign = false;
        GameObject m_ShadowProxyPrefab;
        static GameObject m_ShadowProxyInstance;
     
        void DrawSunSetting()
        {
            Rect bgRect = EditorGUILayout.GetControlRect();
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, 0).y - 21, bgRect.width, 2), m_SeperatorTex);
            Color oldClr = GUI.color;
            GUI.color = new Color(0, 0, 0, 0);
            if (GUI.Button(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), ""))
                s_showSun = !s_showSun;
            GUI.color = oldClr;
            s_showSun = EditorGUI.Foldout(new Rect(bgRect.width + 15, bgRect.y, bgRect.width, 15), s_showSun, "");
            GUI.Label(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), "SUN", EditorStyles.boldLabel);
            GUI.Label(new Rect(bgRect.width - 40, bgRect.y, bgRect.width, 15), s_showSun ? "| Hide" : "| Show");
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, -4).y - 5, bgRect.width, 2), m_SeperatorTex);
            EditorGUI.indentLevel++;
            if (s_showSun)
            {
                m_Asset.sun.enable = EditorGUILayout.Toggle("是否激活", m_Asset.sun.enable);
                if (m_Asset.sun.enable == true)
                {
                    m_Asset.sun.sunDirection = EditorGUILayout.Slider("Sun Direction", m_Asset.sun.sunDirection, 0f, 360f);
                    m_Asset.sun.sunEquator = EditorGUILayout.Slider("Sun Equator", m_Asset.sun.sunEquator, 0f, 180f);
                    m_Asset.sun.moonDirection = EditorGUILayout.Slider("Moon Direction", m_Asset.sun.moonDirection, 0f, 360f);
                    m_Asset.sun.moonEquator = EditorGUILayout.Slider("Moon Equator", m_Asset.sun.moonEquator, 0f, 180f);

                    s_ShadowAlign = EditorGUILayout.Toggle("是否对齐阴影", s_ShadowAlign);
                    if (s_ShadowAlign)
                    {
                        if (m_ShadowProxyPrefab == null)
                        {
                            m_ShadowProxyPrefab = UnityEditor.AssetDatabase.LoadMainAssetAtPath("Assets/Asset/art_resource/environment/others/ShadowLighting/env_ShadowProxyLighting.prefab") as GameObject;
                        }
                        if (m_ShadowProxyInstance == null)
                        {
                            m_ShadowProxyInstance = (GameObject)UnityEngine.Object.Instantiate(m_ShadowProxyPrefab);
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        if (m_ShadowProxyInstance != null)
                        {
                            GameObject.Destroy(m_ShadowProxyInstance);
                        }
                    }
                    m_Asset.sun.timeline = EditorGUILayout.Slider("Timeline", m_Asset.sun.timeline, 0f, 24f);
                    m_Asset.sun.sunColor = EditorGUILayout.ColorField("Sun Color", m_Asset.sun.sunColor);
                    m_Asset.sun.sunIntensity = Mathf.Max(0, EditorGUILayout.FloatField("Sun Intensity", m_Asset.sun.sunIntensity));
                    m_Asset.sun.sunInDirectionIntensity = Mathf.Max(0, EditorGUILayout.FloatField("Sun IndirectIntensity", m_Asset.sun.sunInDirectionIntensity));
                    m_Asset.sun.charactorLightColor0 = EditorGUILayout.ColorField("Char Main Lit Color", m_Asset.sun.charactorLightColor0);
                    m_Asset.sun.charactorLightIntensity0 = Mathf.Max(0, EditorGUILayout.FloatField("Char Main Lit Intensity", m_Asset.sun.charactorLightIntensity0));
                    m_Asset.sun.charactorLightColor1 = EditorGUILayout.ColorField("Char Virtual Lit Color", m_Asset.sun.charactorLightColor1);
                    m_Asset.sun.charactorLightIntensity1 = Mathf.Max(0, EditorGUILayout.FloatField("Char Virtual Lit Intensity", m_Asset.sun.charactorLightIntensity1));

                    GUILayout.Space(5f);
#if TEMPLY_COMMENT_PROFLARE
                // Proflare Begin
                ProFlare proFlare = null;
                if(EnvironmentSystem.instance != null)
                {
                    //proFlare = EnvironmentSystem.instance.transform.GetComponentInChildren<ProFlare>();
                    Transform proflareTrf = EnvironmentSystem.instance.transform.Find("Env_ProFlare_Camera/ProFlare_Sun");
                    if(proflareTrf != null)
                    {
                        proFlare = proflareTrf.GetComponent<ProFlare>();
                    }

                }
                ProFlareAsset proFlareAsset = EditorGUILayout.ObjectField("ProFlare Asset", m_Asset.sun.proFlareAsset, typeof(ProFlareAsset), false) as ProFlareAsset;

                if(m_Asset.sun.proFlareAsset != proFlareAsset)
                {
                    m_Asset.sun.proFlareAsset = proFlareAsset;
                    if(m_Asset.sun.proFlareAsset != null)
                    {
                        if(proFlare != null)
                        {
                            m_Asset.sun.proFlareAsset.CopyToProFlare(proFlare);
                            EditorUtility.SetDirty(proFlare);
                        }
                    }
                    else
                    {
                        // TODO : 
                    }
                }

                if (m_Asset.sun.proFlareAsset != null)
                {
                    bool bProFlareChanged = false;

                    //Scale
                    m_Asset.sun.GlobalScale = EditorGUILayout.Slider("ProFlare Scale", m_Asset.sun.GlobalScale, 0f, 2000f);

                    if (proFlare != null)
                    {
                        if (proFlare.GlobalScale != m_Asset.sun.GlobalScale)
                            bProFlareChanged = true;

                        proFlare.GlobalScale = m_Asset.sun.GlobalScale;
                    }

                    m_Asset.sun.MultiplyScaleByTransformScale = EditorGUILayout.Toggle("Multiply Scale By Transform Scale", m_Asset.sun.MultiplyScaleByTransformScale);

                    if (proFlare != null)
                    {
                        if (proFlare.MultiplyScaleByTransformScale != m_Asset.sun.MultiplyScaleByTransformScale)
                            bProFlareChanged = true;

                        proFlare.MultiplyScaleByTransformScale = m_Asset.sun.MultiplyScaleByTransformScale;
                    }

                    m_Asset.sun.GlobalBrightness = EditorGUILayout.Slider("ProFlare Brightness", m_Asset.sun.GlobalBrightness, 0f, 1f);

                    if (proFlare != null)
                    {
                        if (proFlare.GlobalBrightness != m_Asset.sun.GlobalBrightness)
                            bProFlareChanged = true;

                        proFlare.GlobalBrightness = m_Asset.sun.GlobalBrightness;
                        proFlare.GlobalTintColor.a = m_Asset.sun.GlobalBrightness;

                    }
                    m_Asset.sun.GlobalTintColor.a = m_Asset.sun.GlobalBrightness;

                    m_Asset.sun.GlobalTintColor = EditorGUILayout.ColorField("ProFlare Tint", m_Asset.sun.GlobalTintColor);

                    if (proFlare != null)
                    {
                        if (proFlare.GlobalTintColor.r != m_Asset.sun.GlobalTintColor.r ||
                            proFlare.GlobalTintColor.g != m_Asset.sun.GlobalTintColor.g ||
                            proFlare.GlobalTintColor.b != m_Asset.sun.GlobalTintColor.b ||
                            proFlare.GlobalTintColor.a != m_Asset.sun.GlobalTintColor.a
                            )
                            bProFlareChanged = true;

                        proFlare.GlobalTintColor = m_Asset.sun.GlobalTintColor;
                        proFlare.GlobalBrightness = m_Asset.sun.GlobalTintColor.a;
                    }
                    m_Asset.sun.GlobalBrightness = m_Asset.sun.GlobalTintColor.a;

                    if (bProFlareChanged == true)
                    {
                        if (proFlare != null)
                        {
                            EditorUtility.SetDirty(proFlare);
                        }
                    }
                }
                // ProFlare End
#endif
                    m_Asset.sun.bakedLighterStength = EditorGUILayout.Slider("BakedLighterStrength", m_Asset.sun.bakedLighterStength, 0f, 1.0f);
                    m_Asset.sun.bakedEnvGIStrength = EditorGUILayout.Slider("EnvGIStrength", m_Asset.sun.bakedEnvGIStrength, 0.0f, 1.5f);
                    m_Asset.sun.shadowStrength = EditorGUILayout.Slider("ShadwoStrength", m_Asset.sun.shadowStrength, 0.0f, 1.0f);
                }

            }
            EditorGUI.indentLevel--;
        }

        static readonly string[] kFullAmbientSource = { "Skybox", "Gradient", "Color","CubeSkyColor" };
        static readonly int[] kFullAmbientSourceValues = { (int)AmbientSettings.kAmbientSourceType.Skybox, (int)AmbientSettings.kAmbientSourceType.Trilight, (int)AmbientSettings.kAmbientSourceType.Flat, (int)AmbientSettings.kAmbientSourceType.CubeSkyColor };
        static readonly GUIContent ambientUp = EditorGUIUtility.TrTextContent("Sky Color", "Controls the color of light emitted from the sky in the Scene.");
        static readonly GUIContent ambientMid = EditorGUIUtility.TrTextContent("Equator Color", "Controls the color of light emitted from the sides of the Scene.");
        static readonly GUIContent ambientDown = EditorGUIUtility.TrTextContent("Ground Color", "Controls the color of light emitted from the ground of the Scene.");
        static readonly GUIContent ambient = EditorGUIUtility.TrTextContent("Ambient Color", "Controls the color of the ambient light contributed to the Scene.");
        static readonly GUIContent env_amb_int = EditorGUIUtility.TrTextContent("Intensity Multiplier", "Controls the brightness of the skybox lighting in the Scene.");

        static readonly GUIContent ambientFront = EditorGUIUtility.TrTextContent("Front Color +Z", "Controls the color of light emitted from the Front in the Scene.");
        static readonly GUIContent ambientBack = EditorGUIUtility.TrTextContent("Back Color -Z", "Controls the color of light emitted from the Back in the Scene.");
        static readonly GUIContent ambientLeft = EditorGUIUtility.TrTextContent("Left Color +X", "Controls the color of light emitted from the Left in the Scene.");
        static readonly GUIContent ambientRight = EditorGUIUtility.TrTextContent("Right Color -X", "Controls the color of light emitted from the Right in the Scene.");
        static readonly GUIContent ambientUpSky = EditorGUIUtility.TrTextContent("Up Color +Y", "Controls the color of light emitted from the Up in the Scene.");
        static readonly GUIContent ambientDownGround = EditorGUIUtility.TrTextContent("Down Color -Y", "Controls the color of light emitted from the Down in the Scene.");

        static bool s_showAmbient = true;

        void DrawAmbientSetting()
        {
            Rect bgRect = EditorGUILayout.GetControlRect();
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, 0).y - 21, bgRect.width, 2), m_SeperatorTex);
            Color oldClr = GUI.color;
            GUI.color = new Color(0, 0, 0, 0);
            if (GUI.Button(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), ""))
                s_showAmbient = !s_showAmbient;
            GUI.color = oldClr;
            s_showAmbient = EditorGUI.Foldout(new Rect(bgRect.width + 15, bgRect.y, bgRect.width, 15), s_showAmbient, "");
            GUI.Label(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), "AMBIENT", EditorStyles.boldLabel);
            GUI.Label(new Rect(bgRect.width - 40, bgRect.y, bgRect.width, 15), s_showAmbient ? "| Hide" : "| Show");
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, -4).y - 5, bgRect.width, 2), m_SeperatorTex);

            bool bCubeSkyDirty = false;
            EditorGUI.indentLevel++;
            if (s_showAmbient)
            {
                m_Asset.ambient.enable = EditorGUILayout.Toggle("是否激活", m_Asset.ambient.enable);
                if (m_Asset.ambient.enable == true)
                {
                    m_Asset.ambient.source = (AmbientSettings.kAmbientSourceType)EditorGUILayout.IntPopup("Source", (int)m_Asset.ambient.source, kFullAmbientSource, kFullAmbientSourceValues);
                    switch (m_Asset.ambient.source)
                    {
                        case AmbientSettings.kAmbientSourceType.Trilight:
                            {
                                Color color;
                                color = EditorGUILayout.ColorField(ambientUp, m_Asset.ambient.skyColor, true, false, true);
                                if (!color.Equals(m_Asset.ambient.skyColor))
                                    bCubeSkyDirty = true;
                                m_Asset.ambient.skyColor = color;

                                color = EditorGUILayout.ColorField(ambientMid, m_Asset.ambient.equatorColor, true, false, true);
                                if (!color.Equals(m_Asset.ambient.equatorColor))
                                    bCubeSkyDirty = true;
                                m_Asset.ambient.equatorColor = color;

                                color = EditorGUILayout.ColorField(ambientDown, m_Asset.ambient.groundColor, true, false, true);
                                if (!color.Equals(m_Asset.ambient.groundColor))
                                    bCubeSkyDirty = true;
                                m_Asset.ambient.groundColor = color;
                            }
                            break;

                        case AmbientSettings.kAmbientSourceType.Flat:
                            {
                                Color color;
                                color = EditorGUILayout.ColorField(ambient, m_Asset.ambient.skyColor, true, false, true);
                                if (!color.Equals(m_Asset.ambient.skyColor))
                                    bCubeSkyDirty = true;
                                m_Asset.ambient.skyColor = color;
                            }
                            break;

                        case AmbientSettings.kAmbientSourceType.Skybox:
                            {
                                float intensity;
                                intensity = EditorGUILayout.Slider(env_amb_int, m_Asset.ambient.intensity, 0.0F, 8.0F);
                                if (!intensity.Equals(m_Asset.ambient.intensity))
                                    bCubeSkyDirty = true;
                                m_Asset.ambient.intensity = intensity;
                            }
                            break;
                        case AmbientSettings.kAmbientSourceType.CubeSkyColor:
                            {
                                Color color;
                                color = EditorGUILayout.ColorField(ambientFront, m_Asset.ambient.frontColor, true, false, true);
                                if (!color.Equals(m_Asset.ambient.frontColor))
                                    bCubeSkyDirty = true;
                                m_Asset.ambient.frontColor = color;

                                color = EditorGUILayout.ColorField(ambientBack, m_Asset.ambient.backColor, true, false, true);
                                if (!color.Equals(m_Asset.ambient.backColor))
                                    bCubeSkyDirty = true;
                                m_Asset.ambient.backColor = color;

                                color = EditorGUILayout.ColorField(ambientLeft, m_Asset.ambient.leftColor, true, false, true);
                                if (!color.Equals(m_Asset.ambient.leftColor))
                                    bCubeSkyDirty = true;
                                m_Asset.ambient.leftColor = color;

                                color = EditorGUILayout.ColorField(ambientRight, m_Asset.ambient.rightColor, true, false, true);
                                if (!color.Equals(m_Asset.ambient.rightColor))
                                    bCubeSkyDirty = true;
                                m_Asset.ambient.rightColor = color;

                                color = EditorGUILayout.ColorField(ambientUpSky, m_Asset.ambient.skyColor, true, false, true);
                                if (!color.Equals(m_Asset.ambient.skyColor))
                                    bCubeSkyDirty = true;
                                m_Asset.ambient.skyColor = color;

                                color = EditorGUILayout.ColorField(ambientDownGround, m_Asset.ambient.groundColor, true, false, true);
                                if (!color.Equals(m_Asset.ambient.groundColor))
                                    bCubeSkyDirty = true;
                                m_Asset.ambient.groundColor = color;

                                m_Asset.ambient.bToBakeGI = false;

                                if (GUILayout.Button("Bake GI"))
                                {
                                    m_Asset.ambient.bToBakeGI = true;
                                }
                            }
                            break;
                    }

                    Material skymat = EditorGUILayout.ObjectField("bakeSky Material", m_Asset.ambient.bakeSkyMat, typeof(Material), false) as Material;
                    if (skymat != null && !skymat.Equals(m_Asset.ambient.bakeSkyMat))
                    {
                        bCubeSkyDirty = true;
                    }
                    m_Asset.ambient.bakeSkyMat = skymat;

                    m_Asset.ambient.bCubeSkyDirty = bCubeSkyDirty;
                    m_Asset.ambient.reflectionIntensity = EditorGUILayout.Slider("Reflection Intensity", m_Asset.ambient.reflectionIntensity, 0.0F, 1.0F);
                }
            }
            EditorGUI.indentLevel--;
        }

        void DrawAmbientSettingOfCharacter()
        {
            Rect bgRect = EditorGUILayout.GetControlRect();
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, 0).y - 21, bgRect.width, 2), m_SeperatorTex);
            Color oldClr = GUI.color;
            GUI.color = new Color(0, 0, 0, 0);
            if (GUI.Button(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), ""))
                s_showAmbient = !s_showAmbient;
            GUI.color = oldClr;
            s_showAmbient = EditorGUI.Foldout(new Rect(bgRect.width + 15, bgRect.y, bgRect.width, 15), s_showAmbient, "");
            GUI.Label(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), "AMBIENT CHARACTER", EditorStyles.boldLabel);
            GUI.Label(new Rect(bgRect.width - 40, bgRect.y, bgRect.width, 15), s_showAmbient ? "| Hide" : "| Show");
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, -4).y - 5, bgRect.width, 2), m_SeperatorTex);

            bool bCubeSkyDirty = false;
            EditorGUI.indentLevel++;
            if (s_showAmbient)
            {

                m_Asset.ambientCharacter.source = (AmbientSettings.kAmbientSourceType)EditorGUILayout.IntPopup("Source", (int)m_Asset.ambientCharacter.source, kFullAmbientSource, kFullAmbientSourceValues);
                switch (m_Asset.ambientCharacter.source)
                {
                    case AmbientSettings.kAmbientSourceType.Trilight:
                        {
                            Color color;
                            color = EditorGUILayout.ColorField(ambientUp, m_Asset.ambientCharacter.skyColor, true, false, true);
                            if (!color.Equals(m_Asset.ambientCharacter.skyColor))
                                bCubeSkyDirty = true;
                            m_Asset.ambientCharacter.skyColor = color;

                            color = EditorGUILayout.ColorField(ambientMid, m_Asset.ambientCharacter.equatorColor, true, false, true);
                            if (!color.Equals(m_Asset.ambientCharacter.equatorColor))
                                bCubeSkyDirty = true;
                            m_Asset.ambientCharacter.equatorColor = color;

                            color = EditorGUILayout.ColorField(ambientDown, m_Asset.ambientCharacter.groundColor, true, false, true);
                            if (!color.Equals(m_Asset.ambientCharacter.groundColor))
                                bCubeSkyDirty = true;
                            m_Asset.ambientCharacter.groundColor = color;
                        }
                        break;

                    case AmbientSettings.kAmbientSourceType.Flat:
                        {
                            Color color;
                            color = EditorGUILayout.ColorField(ambient, m_Asset.ambientCharacter.skyColor, true, false, true);
                            if (!color.Equals(m_Asset.ambientCharacter.skyColor))
                                bCubeSkyDirty = true;
                            m_Asset.ambientCharacter.skyColor = color;
                        }
                        break;

                    case AmbientSettings.kAmbientSourceType.Skybox:
                        {
                            m_Asset.ambientCharacter.intensity = EditorGUILayout.Slider(env_amb_int, m_Asset.ambientCharacter.intensity, 0.0F, 8.0F);
                        }
                        break;
                    case AmbientSettings.kAmbientSourceType.CubeSkyColor:
                        {
                            Color color;
                            color = EditorGUILayout.ColorField(ambientFront, m_Asset.ambientCharacter.frontColor, true, false, true);
                            if (!color.Equals(m_Asset.ambientCharacter.frontColor))
                                bCubeSkyDirty = true;
                            m_Asset.ambientCharacter.frontColor = color;

                            color = EditorGUILayout.ColorField(ambientBack, m_Asset.ambientCharacter.backColor, true, false, true);
                            if (!color.Equals(m_Asset.ambientCharacter.backColor))
                                bCubeSkyDirty = true;
                            m_Asset.ambientCharacter.backColor = color;

                            color = EditorGUILayout.ColorField(ambientLeft, m_Asset.ambientCharacter.leftColor, true, false, true);
                            if (!color.Equals(m_Asset.ambientCharacter.leftColor))
                                bCubeSkyDirty = true;
                            m_Asset.ambientCharacter.leftColor = color;

                            color = EditorGUILayout.ColorField(ambientRight, m_Asset.ambientCharacter.rightColor, true, false, true);
                            if (!color.Equals(m_Asset.ambientCharacter.rightColor))
                                bCubeSkyDirty = true;
                            m_Asset.ambientCharacter.rightColor = color;

                            color = EditorGUILayout.ColorField(ambientUpSky, m_Asset.ambientCharacter.skyColor, true, false, true);
                            if (!color.Equals(m_Asset.ambientCharacter.skyColor))
                                bCubeSkyDirty = true;
                            m_Asset.ambientCharacter.skyColor = color;

                            color = EditorGUILayout.ColorField(ambientDownGround, m_Asset.ambientCharacter.groundColor, true, false, true);
                            if (!color.Equals(m_Asset.ambientCharacter.groundColor))
                                bCubeSkyDirty = true;
                            m_Asset.ambientCharacter.groundColor = color;                        

                            m_Asset.ambientCharacter.bToBakeGI = false;

                            if (GUILayout.Button("Bake GI"))
                            {
                                m_Asset.ambientCharacter.bToBakeGI = true;
                            }
                        }
                        break;
                }
                m_Asset.ambientCharacter.bCubeSkyDirty = bCubeSkyDirty;
                m_Asset.ambientCharacter.reflectionIntensity = EditorGUILayout.Slider("Reflection Intensity", m_Asset.ambientCharacter.reflectionIntensity, 0.0F, 1.0F);
                m_Asset.ambientCharacter.bUseThisSH = EditorGUILayout.Toggle("to Use this skylight", m_Asset.ambientCharacter.bUseThisSH);

            }
            EditorGUI.indentLevel--;
        }

        static bool s_showSkybox = true;
        void DrawSkyboxSetting()
        {
            Rect bgRect = EditorGUILayout.GetControlRect();
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, 0).y - 21, bgRect.width, 2), m_SeperatorTex);
            Color oldClr = GUI.color;
            GUI.color = new Color(0, 0, 0, 0);
            if (GUI.Button(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), ""))
                s_showSkybox = !s_showSkybox;
            GUI.color = oldClr;
            s_showSkybox = EditorGUI.Foldout(new Rect(bgRect.width + 15, bgRect.y, bgRect.width, 15), s_showSkybox, "");
            GUI.Label(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), "Skybox", EditorStyles.boldLabel);
            GUI.Label(new Rect(bgRect.width - 40, bgRect.y, bgRect.width, 15), s_showSkybox ? "| Hide" : "| Show");
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, -4).y - 5, bgRect.width, 2), m_SeperatorTex);
            EditorGUI.indentLevel++;
            if (s_showSkybox)
            {
                m_Asset.skybox.enable = EditorGUILayout.Toggle("是否激活", m_Asset.skybox.enable);
                if (m_Asset.skybox.enable == true)
                {
                    m_Asset.skybox.exposure = EditorGUILayout.Slider("Exposure", m_Asset.skybox.exposure, 0f, 8f);
                    m_Asset.skybox.rotation = EditorGUILayout.Slider("Rotation", m_Asset.skybox.rotation, 0, 360);
                    //m_Asset.skybox.texture = EditorGUILayout.ObjectField("Texture", m_Asset.skybox.texture, typeof(Cubemap), false) as Cubemap;
                    //#if SCENE_EDITOR
                    //                var path = "Assets/Asset/" + m_Asset.skybox.texPath;
                    //#else
                    var path = m_Asset.skybox.texPath;
                    if (path == null)
                    {

                        var newTex = EditorGUILayout.ObjectField("Texture", null, typeof(Cubemap), false) as Cubemap;
                        if (newTex != null)
                        {
                            var newPath = AssetDatabase.GetAssetPath(newTex);
                            if (newPath != null)
                            {
                                //#if SCENE_EDITOR
                                //                    m_Asset.skybox.texPath = newPath.Replace("Assets/Asset/", "");
                                //#else
                                m_Asset.skybox.texPath = newPath.Replace("Assets/AssetBundles/Asset/", "");
                                //#endif
                                m_Asset.skybox.SkyTexture = null;
                            }
                        }
                    }
                    else
                    {


                        if (path.Contains("Assets/AssetBundles/Asset/") == false)
                        {
                            path = "Assets/AssetBundles/Asset/" + path;
                        }
                        //#endif
                        var tex = AssetDatabase.LoadAssetAtPath<Cubemap>(path);
                        var newTex = EditorGUILayout.ObjectField("Texture", tex, typeof(Cubemap), false) as Cubemap;
                        if (tex != newTex)
                        {
                            var newPath = AssetDatabase.GetAssetPath(newTex);
                            //#if SCENE_EDITOR
                            //                    m_Asset.skybox.texPath = newPath.Replace("Assets/Asset/", "");
                            //#else
                            m_Asset.skybox.texPath = newPath.Replace("Assets/AssetBundles/Asset/", "");
                            //#endif
                            m_Asset.skybox.SkyTexture = null;
                        }
                    }

                    m_Asset.skybox.isFog = EditorGUILayout.Toggle("是否接受雾效", m_Asset.skybox.isFog);

                }
            }
            EditorGUI.indentLevel--;
        }

        static bool s_showAtmosphericScattering = true;
        private void DrawAtmosphericScatteringSetting()
        {
            Rect bgRect = EditorGUILayout.GetControlRect();
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, 0).y - 21, bgRect.width, 2), m_SeperatorTex);
            Color oldClr = GUI.color;
            GUI.color = new Color(0, 0, 0, 0);
            if (GUI.Button(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), ""))
                s_showAtmosphericScattering = !s_showAtmosphericScattering;
            GUI.color = oldClr;
            s_showAtmosphericScattering = EditorGUI.Foldout(new Rect(bgRect.width + 15, bgRect.y, bgRect.width, 15), s_showAtmosphericScattering, "");
            GUI.Label(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), "Fog", EditorStyles.boldLabel);
            GUI.Label(new Rect(bgRect.width - 40, bgRect.y, bgRect.width, 15), s_showAtmosphericScattering ? "| Hide" : "| Show");
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, -4).y - 5, bgRect.width, 2), m_SeperatorTex);

            EditorGUI.indentLevel++;
            if (s_showAtmosphericScattering)
            {
                AtmosphericScatteringSettings setting = m_Asset.atmosphericScattering;
                EditorGUILayout.Separator();
                EditorGUILayout.Separator();
                setting.enable = EditorGUILayout.Toggle("是否激活", setting.enable);
                if (setting.enable == true)
                {
                    EditorGUILayout.Separator();
                    EditorGUILayout.LabelField("太阳");
                    setting.enableSunDisk = EditorGUILayout.Toggle("是否显示太阳", setting.enableSunDisk);
                    setting.sunIrradiance.x = EditorGUILayout.FloatField("光照强度", setting.sunIrradiance.x);
                    setting.sunIrradiance.x = Mathf.Max(0, setting.sunIrradiance.x);
                    setting.sunIrradiance.y = setting.sunIrradiance.z = setting.sunIrradiance.x;
                    setting.sunDiameter = EditorGUILayoutEx.Slider("直径(sr)", setting.sunDiameter, 0f, 200f, 80f);
                    setting.sunBrightness = EditorGUILayoutEx.Slider("太阳亮度", setting.sunBrightness, 0f, 10f, 2.5f);
                    EditorGUILayout.Separator();
                    EditorGUILayout.LabelField("月亮");
                    setting.enableMoon = EditorGUILayout.Toggle("是否显示月亮", setting.enableMoon);
                    setting.moonAlbedo = EditorGUILayoutEx.Slider("反射率", setting.moonAlbedo, 0f, 20f, 4f);
                    setting.moonContrast = EditorGUILayoutEx.Slider("明暗对比度", setting.moonContrast, 0.1f, 10f, 1f);
                    setting.moonDiameter = EditorGUILayoutEx.Slider("直径", setting.moonDiameter, 60f, 360f, 100f);
                    setting.moonLightColor = EditorGUILayoutEx.ColorField("颜色", setting.moonLightColor, Color.white);
                    setting.moonIrradiance = EditorGUILayoutEx.Slider("月光亮度", setting.moonIrradiance, 1E-06f, 1f, 0.2f);
                    setting.moonLightSource.x = EditorGUILayout.Slider("入射光方向", setting.moonLightSource.x, 0f, 1f);
                    setting.moonLightSource.y = EditorGUILayout.Slider(" ", setting.moonLightSource.y, 0f, 1f);
                    EditorGUILayout.Separator();
                    //EditorGUILayout.LabelField("大气散射");
                    ////setting.brightnessPower = EditorGUILayout.Slider("亮度", setting.brightnessPower, 0.01f, 1f);
                    //setting.maxAltitudeKm = EditorGUILayoutEx.Slider("相机最高海拔*", setting.maxAltitudeKm, 2f, 100f, 15f);
                    //setting.maxDistanceKm = EditorGUILayoutEx.Slider("最远可视距离*", setting.maxDistanceKm, 5f, 2000f, 300f);
                    //setting.rayleigh = EditorGUILayoutEx.Vector3Field("瑞丽系数*", setting.rayleigh, new Vector3(0.00712f, 0.01319f, 0.02735f));
                    EditorGUILayout.Separator();
                    EditorGUILayout.LabelField("大气层");
                    setting.ozoneStrength = EditorGUILayoutEx.Slider("臭氧", setting.ozoneStrength, 0f, 0.2f, 0f);
                    setting.baseOzone = EditorGUILayoutEx.ColorField("臭氧颜色*", setting.baseOzone, new Color(0.05882353f, 2f / 51f, 0.0117647061f));
                    setting.emissivity = EditorGUILayoutEx.PowerSlider("辐射系数*", setting.emissivity, 0f, 1f, 0f, 5f);
                    setting.planetRadiusKm = EditorGUILayoutEx.Slider("地球半径*", setting.planetRadiusKm, 100f, 100000f, 6378f);
                    setting.atmosphereThicknessKm = EditorGUILayoutEx.Slider("大气厚度*", setting.atmosphereThicknessKm, 0f, 100f, 64f);
                    EditorGUILayout.Separator();
                    EditorGUILayout.LabelField("星空");
                    setting.enableStar = EditorGUILayout.Toggle("是否显示星星", setting.enableStar);
                    setting.maxStarMagnitude = EditorGUILayout.IntSlider("星星密度", setting.maxStarMagnitude, 0, 9);
                    setting.starBrightness = EditorGUILayoutEx.Slider("星星亮度", setting.starBrightness, 0f, 100f, 50f);
                    setting.starLight = EditorGUILayoutEx.Slider("星光亮度", setting.starLight, 0f, 0.4f, 0.025f);
                    setting.enableMilkyWay = EditorGUILayout.Toggle("是否显示银河", setting.enableMilkyWay);
                    setting.backgroundBrightness = EditorGUILayoutEx.Slider("银河亮度", setting.backgroundBrightness, 0f, 5f, 0f);
                    setting.backgroundOffset = EditorGUILayoutEx.Slider("银河偏移", setting.backgroundOffset, -1f, 1f, 0f);
                    setting.backgroundRotation = EditorGUILayoutEx.Slider("银河旋转", setting.backgroundRotation, 0f, 360f, 0f);
                    //EditorGUILayout.Separator();
                    //EditorGUILayout.LabelField("天空颜色");
                    //var bBlending = EditorGUILayout.Toggle("使用自定义颜色", setting.blendToColours > 0);
                    //if (bBlending)
                    //{
                    //    setting.blendToColours = 1;
                    //    setting.horizon = EditorGUILayout.ColorField(new GUIContent("地平线"), setting.horizon, true, false, true);
                    //    setting.zenith = EditorGUILayout.ColorField(new GUIContent("天空穹"), setting.zenith, true, false, true);
                    //}
                    //else
                    //{
                    //    setting.blendToColours = 0;
                    //}
                    //setting.maxStarMagnitude = EditorGUILayout.IntSlider("星星密度", setting.maxStarMagnitude, 0, 9);
                    //setting.starBrightness = EditorGUILayoutEx.Slider("星星亮度", setting.starBrightness, 0f, 100f, 50f);
                    //setting.starLight = EditorGUILayoutEx.Slider("星光亮度", setting.starLight, 0f, 0.4f, 0.025f);
                    //setting.backgroundBrightness = EditorGUILayoutEx.Slider("背景亮度", setting.backgroundBrightness, 0f, 2f, 0f);
                    EditorGUILayout.Separator();
                    EditorGUILayout.LabelField("雾效");
                    setting.haze = EditorGUILayoutEx.PowerSlider("雾浓度", setting.haze, 1E-05f, 1000f, 1f, 10f);
                    setting.hazeBaseKm = EditorGUILayoutEx.Slider("雾消散起点", setting.hazeBaseKm, -2f, 20f, 0f);
                    setting.hazeScaleKm = EditorGUILayoutEx.Slider("雾消散距离", setting.hazeScaleKm, 0.1f, 10f, 0.5f);
                    setting.hazeEccentricity = EditorGUILayoutEx.Slider("雾离心率*", setting.hazeEccentricity, 0f, 0.99f, 0.82f);
                    setting.autoMie = EditorGUILayout.Toggle("自动", setting.autoMie);
                    setting.mie = EditorGUILayout.Vector3Field("米散射系数", setting.mie);
                    if (setting.autoMie)
                    {
                        setting.mie = Vector3.Lerp(new Vector3(0.03f, 0.04f, 0.06f), new Vector3(6.11f, 8.18f, 11.7f), setting.haze);
                    }

                    EditorGUILayout.Separator();
                    EditorGUILayout.LabelField("高度雾");
                    setting.fogColor = EditorGUILayoutEx.ColorField("颜色", setting.fogColor, new Color(0.047999f, 0.216f, 0.467999f, 0.238217f));
                    setting.fogDensity = EditorGUILayoutEx.Slider("浓度", setting.fogDensity, 0f, 0.1f, 0f);
                    setting.fogHalfDensityHeight = EditorGUILayoutEx.Slider("高度", setting.fogHalfDensityHeight, 1f, 1000f, 1000f);
                    setting.fogHeightOffset = EditorGUILayoutEx.Slider("起始高度", setting.fogHeightOffset, 0f, 200f, 0f);
                    if (setting.fogHeightOffset > setting.fogHalfDensityHeight)
                        setting.fogHeightOffset = setting.fogHalfDensityHeight;
                    setting.fogStartDistance = EditorGUILayoutEx.Slider("起始距离", setting.fogStartDistance, 0f, 200f, 0f);
                    setting.fogRange = EditorGUILayoutEx.Slider("距离", setting.fogRange, 0f, 10000f, 10000f);
                }
                m_Asset.atmosphericScattering = setting;
            }
            EditorGUI.indentLevel--;
        }

        static bool s_showOceanFog = true;
        void DrawOceanFogSetting()
        {
            Rect bgRect = EditorGUILayout.GetControlRect();
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, 0).y - 21, bgRect.width, 2), m_SeperatorTex);
            Color oldClr = GUI.color;
            GUI.color = new Color(0, 0, 0, 0);
            if (GUI.Button(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), ""))
                s_showOceanFog = !s_showOceanFog;
            GUI.color = oldClr;
            s_showOceanFog = EditorGUI.Foldout(new Rect(bgRect.width + 15, bgRect.y, bgRect.width, 15), s_showOceanFog, "");
            GUI.Label(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), "Ocean FOG", EditorStyles.boldLabel);
            GUI.Label(new Rect(bgRect.width - 40, bgRect.y, bgRect.width, 15), s_showOceanFog ? "| Hide" : "| Show");
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, -4).y - 5, bgRect.width, 2), m_SeperatorTex);
            EditorGUI.indentLevel++;
            if (s_showOceanFog)
            {
                m_Asset.oceanFog.enable = EditorGUILayout.Toggle("是否激活", m_Asset.oceanFog.enable);
                if (m_Asset.oceanFog.enable == true)
                {
                    //m_Asset.oceanFog.oceanFogColor = EditorGUILayout.ColorField("Ocean Fog color", m_Asset.oceanFog.oceanFogColor);
                    m_Asset.oceanFog.oceanFogColorMultiplier = Mathf.Max(0f,
                   EditorGUILayout.FloatField("Ocean Fog color Multiplier", m_Asset.oceanFog.oceanFogColorMultiplier));
                    //m_Asset.oceanFog.oceanFogDensity = Mathf.Max(0f,
                    //   EditorGUILayout.FloatField("Ocean Fog Density", m_Asset.oceanFog.oceanFogDensity));
                }

            } //endif
            EditorGUI.indentLevel--;
        }

        static bool s_showCloud2d = true;
        void DrawCloud2dSetting()
        {
            Rect bgRect = EditorGUILayout.GetControlRect();
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, 0).y - 21, bgRect.width, 2), m_SeperatorTex);
            Color oldClr = GUI.color;
            GUI.color = new Color(0, 0, 0, 0);
            if (GUI.Button(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), ""))
                s_showCloud2d = !s_showCloud2d;
            GUI.color = oldClr;
            s_showCloud2d = EditorGUI.Foldout(new Rect(bgRect.width + 15, bgRect.y, bgRect.width, 15), s_showCloud2d, "");
            GUI.Label(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), "ClOULD 2D", EditorStyles.boldLabel);
            GUI.Label(new Rect(bgRect.width - 40, bgRect.y, bgRect.width, 15), s_showCloud2d ? "| Hide" : "| Show");
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, -4).y - 5, bgRect.width, 2), m_SeperatorTex);
            EditorGUI.indentLevel++;
            if (s_showCloud2d)
            {
                m_Asset.cloud2d.enable = EditorGUILayout.Toggle("是否激活", m_Asset.cloud2d.enable);
                if (m_Asset.cloud2d.enable == true)
                {
                    //m_Asset.cloud2d.ambientSource = (Cloud2dSettings.AmbientSource)EditorGUILayout.EnumPopup("Night Mode", m_Asset.cloud2d.ambientSource);
                    m_Asset.cloud2d.attenuation = EditorGUILayout.Slider("Attenuation", m_Asset.cloud2d.attenuation, 0f, 5f);
                    m_Asset.cloud2d.stepSize = EditorGUILayout.Slider("Step Size", m_Asset.cloud2d.stepSize, 0.001f, 0.02f);
                    m_Asset.cloud2d.alphaSaturation = EditorGUILayout.Slider("AlphaSaturation", m_Asset.cloud2d.alphaSaturation, 1f, 10f);
                    m_Asset.cloud2d.lightColorMultiplier = EditorGUILayout.Slider("Light Color Multiplier", m_Asset.cloud2d.lightColorMultiplier, 0f, 10f);
                    m_Asset.cloud2d.skyColor = EditorGUILayout.ColorField("Sky Color", m_Asset.cloud2d.skyColor);
                    m_Asset.cloud2d.skyColorMultiplier = EditorGUILayout.Slider("Sky Color Multiplier", m_Asset.cloud2d.skyColorMultiplier, 0f, 10f);
                    m_Asset.cloud2d.cloudsDensity = EditorGUILayout.Slider("Clouds Density", m_Asset.cloud2d.cloudsDensity, 0f, 4f);
                    m_Asset.cloud2d.scatterMultiplier = EditorGUILayout.Slider("Scatter Multiplier", m_Asset.cloud2d.scatterMultiplier, 0f, 10f);
                    m_Asset.cloud2d.mappingMode = (Cloud2dSettings.MappingMode)EditorGUILayout.EnumPopup("Mapping Mode", m_Asset.cloud2d.mappingMode);
                    m_Asset.cloud2d.rotateSpeed = EditorGUILayout.Slider("Rotate Speed", m_Asset.cloud2d.rotateSpeed, -1f, 1f);
                    m_Asset.cloud2d.heightOffset = EditorGUILayout.FloatField("Height Offset", m_Asset.cloud2d.heightOffset);
                    m_Asset.cloud2d.cloudMaterial = EditorGUILayout.ObjectField("Cloud Material", m_Asset.cloud2d.cloudMaterial, typeof(Material), false) as Material;
                }

            } //endif
            EditorGUI.indentLevel--;
        }

        static bool s_showWeatherSystem = true;
        void DrawWeatherSystemSetting()
        {
            Rect bgRect = EditorGUILayout.GetControlRect();
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, 0).y - 21, bgRect.width, 2), m_SeperatorTex);
            Color oldClr = GUI.color;
            GUI.color = new Color(0, 0, 0, 0);
            if (GUI.Button(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), ""))
                s_showWeatherSystem = !s_showWeatherSystem;
            GUI.color = oldClr;
            s_showWeatherSystem = EditorGUI.Foldout(new Rect(bgRect.width + 15, bgRect.y, bgRect.width, 15), s_showWeatherSystem, "");
            GUI.Label(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), "WEATHER SYSTEM", EditorStyles.boldLabel);
            GUI.Label(new Rect(bgRect.width - 40, bgRect.y, bgRect.width, 15), s_showWeatherSystem ? "| Hide" : "| Show");
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, -4).y - 5, bgRect.width, 2), m_SeperatorTex);
            EditorGUI.indentLevel++;
            if (s_showWeatherSystem)
            {
                m_Asset.weatherSystem.isRaining = EditorGUILayout.Toggle("Rainning", m_Asset.weatherSystem.isRaining);
                if (m_Asset.weatherSystem.isRaining == true)
                {
                    m_Asset.weatherSystem.isFlashLighting = EditorGUILayout.Toggle("Flash Lighting", m_Asset.weatherSystem.isFlashLighting);

                    m_Asset.weatherSystem.rainningAmount = EditorGUILayout.Slider("Amount", m_Asset.weatherSystem.rainningAmount, 0f, 1f);

                    //m_Asset.weatherSystem.diffuseDarkening = Mathf.Max(0f,
                    //   EditorGUILayout.FloatField("Diffuse Darkening", m_Asset.weatherSystem.diffuseDarkening));
                    m_Asset.weatherSystem.diffuseDarkening = EditorGUILayout.Slider("Diffuse Darkening", m_Asset.weatherSystem.diffuseDarkening, 0f, 1f);


                    m_Asset.weatherSystem.puddleAmount = Mathf.Max(0f,
                       EditorGUILayout.FloatField("Puddle Amount", m_Asset.weatherSystem.puddleAmount));

                    m_Asset.weatherSystem.puddleRipplesAmount = Mathf.Max(0f,
                       EditorGUILayout.FloatField("Puddle Ripples Amount", m_Asset.weatherSystem.puddleRipplesAmount));

                    m_Asset.weatherSystem.puddleRipplesScale = Mathf.Max(0f,
                       EditorGUILayout.FloatField("Puddle Ripples Scale", m_Asset.weatherSystem.puddleRipplesScale));

                    m_Asset.weatherSystem.nearRainDropIntensity = Mathf.Max(0f,
                       EditorGUILayout.FloatField("near Rain Drop Distance", m_Asset.weatherSystem.nearRainDropIntensity));

                    m_Asset.weatherSystem.farRainDropIntensity = Mathf.Max(0f,
                       EditorGUILayout.FloatField("far Rain Drop Intensity", m_Asset.weatherSystem.farRainDropIntensity));

                    m_Asset.weatherSystem.isSnowing = EditorGUILayout.Toggle("Snowing", m_Asset.weatherSystem.isSnowing);

                    m_Asset.weatherSystem.rpOutDoorStrength = EditorGUILayout.Slider("ReflectionStrength", m_Asset.weatherSystem.rpOutDoorStrength, 0f, 1.5f);
                }

            }
            EditorGUI.indentLevel--;
        }

        static bool s_showBlackHoleSetting = true;
        void DrawBlackHoleSetting()
        {
            Rect bgRect = EditorGUILayout.GetControlRect();
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, 0).y - 21, bgRect.width, 2), m_SeperatorTex);
            Color oldClr = GUI.color;
            GUI.color = new Color(0, 0, 0, 0);
            if (GUI.Button(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), ""))
                s_showBlackHoleSetting = !s_showBlackHoleSetting;
            GUI.color = oldClr;
            s_showBlackHoleSetting = EditorGUI.Foldout(new Rect(bgRect.width + 15, bgRect.y, bgRect.width, 15), s_showBlackHoleSetting, "");
            GUI.Label(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), "BLACK HOLE SETTING", EditorStyles.boldLabel);
            GUI.Label(new Rect(bgRect.width - 40, bgRect.y, bgRect.width, 15), s_showBlackHoleSetting ? "| Hide" : "| Show");
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, -4).y - 5, bgRect.width, 2), m_SeperatorTex);
            EditorGUI.indentLevel++;
            if (s_showBlackHoleSetting)
            {
                m_Asset.blackHoleSetting.enable = EditorGUILayout.Toggle("是否激活", m_Asset.blackHoleSetting.enable);
                if (m_Asset.blackHoleSetting.enable)
                {
                    m_Asset.blackHoleSetting.radius = EditorGUILayout.Slider("半径", m_Asset.blackHoleSetting.radius, 0, 300);
                    m_Asset.blackHoleSetting.offsetDistance = EditorGUILayout.Slider("中心点相对相机偏移量", m_Asset.blackHoleSetting.offsetDistance, 0, 100);
                    m_Asset.blackHoleSetting.scaleCoef = EditorGUILayout.Slider("边缘过渡", m_Asset.blackHoleSetting.scaleCoef, 0, 10);
                    m_Asset.blackHoleSetting.intensity = EditorGUILayout.Slider("遮罩明暗度", m_Asset.blackHoleSetting.intensity, 0, 100);
                    m_Asset.blackHoleSetting.darkIntensity = EditorGUILayout.Slider("暗部亮度", m_Asset.blackHoleSetting.darkIntensity, 0, 1);
                }
                else
                {
                    m_Asset.blackHoleSetting.radius = 300;
                    m_Asset.blackHoleSetting.scaleCoef = 1.0f;
                    m_Asset.blackHoleSetting.intensity = 1.0f;
                    m_Asset.blackHoleSetting.darkIntensity = 0.0f;
                    m_Asset.blackHoleSetting.offsetDistance = 3.0f;

                }


            }
            EditorGUI.indentLevel--;
        }

        static bool s_showCloudShadow = true;
        void DrawCloudShadowSetting()
        {
            Rect bgRect = EditorGUILayout.GetControlRect();
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, 0).y - 21, bgRect.width, 2), m_SeperatorTex);
            Color oldClr = GUI.color;
            GUI.color = new Color(0, 0, 0, 0);
            if(GUI.Button(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), ""))
                s_showCloudShadow = !s_showCloudShadow;
            GUI.color = oldClr;
            s_showCloudShadow = EditorGUI.Foldout(new Rect(bgRect.width + 15, bgRect.y, bgRect.width, 15), s_showCloudShadow, "");
            GUI.Label(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), "CLOUD SHADOW", EditorStyles.boldLabel);
            GUI.Label(new Rect(bgRect.width - 40, bgRect.y, bgRect.width, 15), s_showCloudShadow? "| Hide" : "| Show");
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, -4).y - 5, bgRect.width, 2), m_SeperatorTex);
            EditorGUI.indentLevel++;
            if (s_showCloudShadow)
            {
                m_Asset.cloudShadow.hasCloudShadow = EditorGUILayout.Toggle("CloudShadow", m_Asset.cloudShadow.hasCloudShadow);
                if (m_Asset.cloudShadow.hasCloudShadow)
                {
                    m_Asset.cloudShadow.cloudTexture = EditorGUILayout.ObjectField("Texture", m_Asset.cloudShadow.cloudTexture, typeof(Texture), false) as Texture;
                    m_Asset.cloudShadow.cloudTiling = EditorGUILayout.Vector2Field("CloudShadowTiling", m_Asset.cloudShadow.cloudTiling);
                    m_Asset.cloudShadow.cloudWindSpeed = EditorGUILayout.Vector2Field("CloudShadowSpeed", m_Asset.cloudShadow.cloudWindSpeed);
                    m_Asset.cloudShadow.cloudFadeOut = EditorGUILayout.Slider("CloudShadowFadeOut", m_Asset.cloudShadow.cloudFadeOut, 0.0f, 1.0f);
                    m_Asset.cloudShadow.shadowIntensity = EditorGUILayout.Slider("ShadowIntensity", m_Asset.cloudShadow.shadowIntensity, 0.0f, 1.0f);
                }

            }
            EditorGUI.indentLevel--;
        }

        static bool s_showCloud = true;
        void DrawCloudSetting()
        {
            Rect bgRect = EditorGUILayout.GetControlRect();
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, 0).y - 21, bgRect.width, 2), m_SeperatorTex);
            Color oldClr = GUI.color;
            GUI.color = new Color(0, 0, 0, 0);
            if (GUI.Button(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), ""))
                s_showCloud = !s_showCloud;
            GUI.color = oldClr;
            s_showCloud = EditorGUI.Foldout(new Rect(bgRect.width + 15, bgRect.y, bgRect.width, 15), s_showCloud, "");
            GUI.Label(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), "CLOUD", EditorStyles.boldLabel);
            GUI.Label(new Rect(bgRect.width - 40, bgRect.y, bgRect.width, 15), s_showCloud ? "| Hide" : "| Show");
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, -4).y - 5, bgRect.width, 2), m_SeperatorTex);
            EditorGUI.indentLevel++;
            if (s_showCloud)
            {
#region Basic

                m_Asset.fogState.FogMainColor = EditorGUILayout.ColorField(new GUIContent("Light energy", "Multiplies all lighting contributions"), m_Asset.fogState.FogMainColor);
                //m_Asset.fogState.fogVolumeScale = EditorGUILayout.Vector3Field("Size", m_Asset.fogState.fogVolumeScale);
#endregion

#region lighting

                GUILayout.BeginVertical("box");

                m_Asset.fogState._AmbientColor = EditorGUILayout.ColorField(new GUIContent("Ambient", "Ambient is added as first light contribution. Alpha is used for volumetric shadows ambient amount"), m_Asset.fogState._AmbientColor);
                //m_Asset.fogState.Absorption = EditorGUILayout.Slider(new GUIContent("Absorption", "How much ambient light is absorbed by noise. Depends on noise density"), m_Asset.fogState.Absorption, 0, 1);
                //m_Asset.fogState.HeightAbsorption = EditorGUILayout.Slider(new GUIContent("Height Absorption", "Multiplies lighting contributoins with height gradient 1"), m_Asset.fogState.HeightAbsorption, 0, 1);

                GUILayout.EndVertical();

#region Inscattering
                GUILayout.BeginVertical("box");
                m_Asset.fogState.InscatteringColor = EditorGUILayout.ColorField("Color", m_Asset.fogState.InscatteringColor);
                //m_Asset.fogState.InscatteringShape = EditorGUILayout.Slider(new GUIContent("Anisotropy", "Balance of forward and back scattering"), m_Asset.fogState.InscatteringShape, -1, 1);
                //m_Asset.fogState.InscatteringIntensity = EditorGUILayout.Slider("Intensity", m_Asset.fogState.InscatteringIntensity, 0, 1);
                //m_Asset.fogState.InscatteringStartDistance = EditorGUILayout.FloatField("Start Distance", m_Asset.fogState.InscatteringStartDistance);
                //m_Asset.fogState.InscatteringTransitionWideness = EditorGUILayout.FloatField("Transition Wideness", m_Asset.fogState.InscatteringTransitionWideness);
                GUILayout.EndVertical();
#endregion

                GUILayout.BeginVertical("box");
                m_Asset.fogState.LightExtinctionColor = EditorGUILayout.ColorField(new GUIContent("Extinction Color", "The color of the light after full absorption"), m_Asset.fogState.LightExtinctionColor);
                m_Asset.fogState.PenetrateScale = EditorGUILayout.Slider("实时云混合缩放", m_Asset.fogState.PenetrateScale, 1.0f, 200.0f);
                m_Asset.fogState.PenetrateMaxDepth = EditorGUILayout.Slider("实时云混合起始深度", m_Asset.fogState.PenetrateMaxDepth, 0.0f, 1.0f);
                //m_Asset.fogState._DirectionalLightingDistance = EditorGUILayout.Slider(new GUIContent("Distance", "Distance between samples"), m_Asset.fogState._DirectionalLightingDistance, 0, 2.0f);
                //m_Asset.fogState.DirectLightingShadowDensity = EditorGUILayout.Slider(new GUIContent("Density", "Amount of light being absorbed"), m_Asset.fogState.DirectLightingShadowDensity, 0, 15);
                GUILayout.EndVertical();
#endregion

#region ColorManagement
                //m_Asset.fogState.Offset = EditorGUILayout.Slider("Offset", m_Asset.fogState.Offset, -.5f, .5f);
                //m_Asset.fogState.Gamma = EditorGUILayout.Slider("Gamma", m_Asset.fogState.Gamma, .01f, 3);
#endregion

#region Renderer
                //m_Asset.fogState.NoiseIntensity = EditorGUILayout.Slider(new GUIContent("Intensity", "Opacity of noise and gradients"), m_Asset.fogState.NoiseIntensity, 0, 1);
                //m_Asset.fogState.FadeDistance = EditorGUILayout.FloatField(new GUIContent("Draw distance", "Noise is faded to black at the given distance. Loop will stop then"), m_Asset.fogState.FadeDistance);

                //GUILayout.BeginVertical("box");
                //m_Asset.fogState.GradMin = EditorGUILayout.Slider("Grad 1 Min", m_Asset.fogState.GradMin, -1, 1);
                //m_Asset.fogState.GradMax = EditorGUILayout.Slider("Grad 1 Max", m_Asset.fogState.GradMax, -1, 1);
                //GUILayout.EndVertical();
                //GUILayout.BeginVertical("box");
                //m_Asset.fogState.GradMin2 = EditorGUILayout.Slider("Grad 2 Min", m_Asset.fogState.GradMin2, -1, 1);
                //m_Asset.fogState.GradMax2 = EditorGUILayout.Slider("Grad 2 Max", m_Asset.fogState.GradMax2, -1, 1);
                //GUILayout.EndVertical();
#endregion

#region Noise
                //GUILayout.BeginVertical("Box");
                //m_Asset.fogState._CumulonimbusIntensity = EditorGUILayout.FloatField(new GUIContent("高低落差云分布强度", "值越大， 高落差云分布越多"), m_Asset.fogState._CumulonimbusIntensity);
                //m_Asset.fogState._CrestaIntensity = EditorGUILayout.FloatField(new GUIContent("高层云分布强度", "值越大， 高层云越多"), m_Asset.fogState._CrestaIntensity);
                //m_Asset.fogState._3DNoiseScale = EditorGUILayout.FloatField(new GUIContent("Scale", "Global size of all the noise layers"), m_Asset.fogState._3DNoiseScale);
                //GUILayout.EndVertical();
                ////
                //GUILayout.BeginVertical("Box");
                //EditorGUILayout.LabelField("Base layer", EditorStyles.boldLabel);
                ////m_Asset.fogState.Coverage = EditorGUILayout.Slider(VariableField("Coverage", "Multiplies the base layer intensity. Lighting is affected as density increases"), m_Asset.fogState.Coverage, 0, 5);
                //m_Asset.fogState.NoiseContrast = EditorGUILayout.Slider(new GUIContent("Contrast", "Apply contrast to noise. High values creates more empty space, which is good for performance"), m_Asset.fogState.NoiseContrast, 0, 20);
                //m_Asset.fogState.NoiseDensity = EditorGUILayout.Slider(new GUIContent("Density", "Opacity of the final noise. This won't change the shape of the noise as Intensity does. It only affects the density / opacity of the noise"),
                //    m_Asset.fogState.NoiseDensity, 0, 20);
                ////m_Asset.fogState.Octaves = EditorGUILayout.IntSlider(new GUIContent("Octaves", "How many layers of noise to use"), m_Asset.fogState.Octaves, 1, 5);
                //GUILayout.EndVertical();

                //GUILayout.BeginVertical("Box");
                //EditorGUILayout.LabelField("Detail layer", EditorStyles.boldLabel);
                //m_Asset.fogState.DetailDistance = EditorGUILayout.FloatField(new GUIContent("Draw Distance", "This layer is a lot more costly than the base. Limit the draw distance to incerase performance"), m_Asset.fogState.DetailDistance);
                //if (m_Asset.fogState.DetailDistance > 0)
                //{
                //    m_Asset.fogState._NoiseDetailRange = EditorGUILayout.Slider(new GUIContent("Trim",
                //        "The detail layer is used to cut the base layer at the edges. If contrast is not too high, this will be more effective"), m_Asset.fogState._NoiseDetailRange, 0, 1);
                //    m_Asset.fogState._DetailMaskingThreshold = EditorGUILayout.Slider(new GUIContent
                //            ("Trim Threshold", "Detail layer is applied only at the edges of the base layer. Use this slider to control the size of this edge"),
                //        m_Asset.fogState._DetailMaskingThreshold, 1, 350);
                //}
                //GUILayout.EndVertical();

#endregion
                GUILayout.BeginVertical("Box");
                m_Asset.fogState.PreBake_Gammar = EditorGUILayout.Slider("预计算伽马", m_Asset.fogState.PreBake_Gammar, 1.0f, 4.2f);
                m_Asset.fogState.TintForPreCal = EditorGUILayout.ColorField("染色", m_Asset.fogState.TintForPreCal);
                m_Asset.fogState.Velocity = EditorGUILayout.Vector2Field("移动速度", m_Asset.fogState.Velocity);
                var ori = m_Asset.fogState.JitterIntensity;
                m_Asset.fogState.JitterIntensity = EditorGUILayout.Slider("扭曲", m_Asset.fogState.JitterIntensity, 0.0f, 0.02f);
                if (ori != m_Asset.fogState.JitterIntensity)
                {
                    Shader.SetGlobalFloat("CloudJitterIntensity", m_Asset.fogState.JitterIntensity);
                }

                m_Asset.fogState.pre_cloud_depth_degeneration_intensity = EditorGUILayout.Slider("预计算云衰减", m_Asset.fogState.pre_cloud_depth_degeneration_intensity, 1, 10);
                m_Asset.fogState.pre_cloud_depth_range = EditorGUILayout.Slider("预计算云衰减起始", m_Asset.fogState.pre_cloud_depth_range, 0.0f, 1.0f);
                GUILayout.EndVertical();

            }
            EditorGUI.indentLevel--;
        }

        static bool s_showVolumetricFog = true;
        void DrawVolumetricFogSetting()
        {
            Rect bgRect = EditorGUILayout.GetControlRect();
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, 0).y - 21, bgRect.width, 2), m_SeperatorTex);
            Color oldClr = GUI.color;
            GUI.color = new Color(0, 0, 0, 0);
            if (GUI.Button(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), ""))
                s_showCloud = !s_showCloud;
            GUI.color = oldClr;
            s_showCloud = EditorGUI.Foldout(new Rect(bgRect.width + 15, bgRect.y, bgRect.width, 15), s_showCloud, "");
            GUI.Label(new Rect(bgRect.x, bgRect.y, bgRect.width, 15), "体积雾", EditorStyles.boldLabel);
            GUI.Label(new Rect(bgRect.width - 40, bgRect.y, bgRect.width, 15), s_showCloud ? "| Hide" : "| Show");
            GUI.DrawTexture(new Rect(GUILayoutUtility.GetRect(bgRect.width, 1).x, GUILayoutUtility.GetRect(bgRect.width, -4).y - 5, bgRect.width, 2), m_SeperatorTex);
            EditorGUI.indentLevel++;
            if (s_showVolumetricFog)
            {
                m_Asset.volumetricFogSetting.enable = EditorGUILayout.Toggle("是否激活", m_Asset.volumetricFogSetting.enable);
                if (m_Asset.volumetricFogSetting.enable)
                {
                    m_Asset.volumetricFogSetting.scatteringCoef = EditorGUILayout.Slider("散射系数", m_Asset.volumetricFogSetting.scatteringCoef, 0.0f, 1.0f);
                    m_Asset.volumetricFogSetting.absorptionCoef = EditorGUILayout.Slider("吸收系数", m_Asset.volumetricFogSetting.absorptionCoef, 0.0f, 1.0f);
                    m_Asset.volumetricFogSetting.phaseAnisotropy = EditorGUILayout.Slider("方向系数", m_Asset.volumetricFogSetting.phaseAnisotropy, -1.0f, 1.0f);

                }
            }
            EditorGUI.indentLevel--;
        }

    }
}

