using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace DBT
{
    public class SceneAdvancedShaderGUI : SceneBaseShaderGUI
    {
        private static class Styles
        {
            //public static string shaderText = "[----------Cloud Shadow----------]";        
            // public static readonly GUIContent CloudShadowLabel = new GUIContent("Cloud_Shadow","");
            // public static GUIContent shadowSwitchLabel = EditorGUIUtility.TrTextContent("SHADOW SWITCH","");
            // public static GUIContent isRotateLabel = EditorGUIUtility.TrTextContent("IsRotate","");
            // public static GUIContent shadowTexLabel = EditorGUIUtility.TrTextContent("Shadow (RGB) Trans (A)",""); 
            // public static GUIContent dirXLabel = EditorGUIUtility.TrTextContent("DirX",""); 
            // public static GUIContent dirYLabel = EditorGUIUtility.TrTextContent("DirY",""); 
            // public static GUIContent speedLabel = EditorGUIUtility.TrTextContent("Speed",""); 
            // public static GUIContent shadowAlphaRatioLabel = EditorGUIUtility.TrTextContent("ShadowAlphaRatio",""); 
            //public static string shaderText = "[----------Fog----------]";        
            //public static readonly GUIContent FogLabel = new GUIContent("Fog","");
            //public static GUIContent useHFogLabel = EditorGUIUtility.TrTextContent("Use HFog","");
            //public static GUIContent hFogColorLabel = EditorGUIUtility.TrTextContent("HFog Color","");
            //public static GUIContent hFogStartLabel = EditorGUIUtility.TrTextContent("Height Fog Start","");
            //public static GUIContent hFogEndLabel = EditorGUIUtility.TrTextContent("Height Fog End","");
            //public static GUIContent startPointLabel = EditorGUIUtility.TrTextContent("Start Point",""); 
            //public static GUIContent customFogLabel = EditorGUIUtility.TrTextContent("Custom Fog",""); 
            //public static GUIContent fogStartLabel = EditorGUIUtility.TrTextContent("Fog Start",""); 
            //public static GUIContent fogEndLabel = EditorGUIUtility.TrTextContent("Fog End",""); 
            //public static GUIContent fogColorLabel = EditorGUIUtility.TrTextContent("Fog Color","");
            public static GUIContent HoleLabel = EditorGUIUtility.TrTextContent("HoleLabel", "");

            public static readonly GUIContent InjectEffectLabel = new GUIContent("Inject Effect","");

            public static GUIContent EffectUVScaleLabel = EditorGUIUtility.TrTextContent("Effect UV Scale", "");
            public static GUIContent EffectWeightLabel = EditorGUIUtility.TrTextContent("Effect Weight", "");
            public static GUIContent SceneBloomFactorLabel = EditorGUIUtility.TrTextContent("Scene Bloom Factor", "");
        }

        // MaterialProperty ShadowSwitch = null;
        // MaterialProperty IsRotate = null;
        // MaterialProperty ShadowTex = null;
        // MaterialProperty DirX = null;
        // MaterialProperty DirY = null;
        // MaterialProperty Speed = null;
        // MaterialProperty ShadowAlphaRatio = null;
        //MaterialProperty UseHFog = null;
        //MaterialProperty HFogColor = null;
        //MaterialProperty HFogStart = null;
        //MaterialProperty HFogEnd = null;
        //MaterialProperty StartPoint = null;
        //MaterialProperty CustomFog = null;
        //MaterialProperty FogStart = null;
        //MaterialProperty FogEnd = null;
        //MaterialProperty FogColor = null;
        MaterialProperty EffectUVScale = null;
        MaterialProperty EffectWeight = null;
        
        MaterialProperty Hole = null;

        //MaterialProperty SceneBloomFactor = null;

        bool m_CloudShadowFoldout;
        bool m_FogFoldout;

        bool m_InjectEffectFoldout;

        public new void FindProperties(MaterialProperty[] props)
        {
            // ShadowSwitch = FindProperty("_SHADOW_SWITCH", props);
            // IsRotate = FindProperty("_IsRotate", props);
            // ShadowTex = FindProperty("_ShadowTex", props);
            // DirX = FindProperty("_DirX", props);
            // DirY = FindProperty("_DirY", props);
            // Speed = FindProperty("_Speed", props);
            // ShadowAlphaRatio = FindProperty("_ShadowAlphaRatio", props);
            //UseHFog = FindProperty("_Use_HFog", props);
            //HFogColor = FindProperty("_HFogColor", props);
            //HFogStart = FindProperty("_HFogStart", props);
            //HFogEnd = FindProperty("_HFogEnd", props);
            //StartPoint = FindProperty("_StartPoint", props);
            //CustomFog = FindProperty("_CustomFog", props);
            //FogStart = FindProperty("_FogStart", props);
            //FogEnd = FindProperty("_FogEnd", props);
            //FogColor = FindProperty("_FogColor", props);
            EffectUVScale = FindProperty("_EffectUVScale", props);
            EffectWeight = FindProperty("_EffectWeight", props);
            Hole = FindProperty("_UseHole", props);

            //SceneBloomFactor = FindProperty("_SceneBloomFactor", props);
        }

        public new void ShaderPropertiesGUI(Material material)
        {
            EditorGUI.BeginChangeCheck();
            {
                //GUILayout.Label(Styles.shaderText, EditorStyles.boldLabel);
                // m_CloudShadowFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(m_CloudShadowFoldout, Styles.CloudShadowLabel);
                // if (m_CloudShadowFoldout)
                // {
                //     m_MaterialEditor.ShaderProperty(ShadowSwitch, Styles.shadowSwitchLabel);
                //     m_MaterialEditor.ShaderProperty(IsRotate, Styles.isRotateLabel);
                //     m_MaterialEditor.TexturePropertySingleLine(Styles.shadowTexLabel, ShadowTex);
                //     m_MaterialEditor.ShaderProperty(DirX, Styles.dirXLabel);
                //     m_MaterialEditor.ShaderProperty(DirY, Styles.dirYLabel);
                //     m_MaterialEditor.ShaderProperty(Speed, Styles.speedLabel);
                //     m_MaterialEditor.ShaderProperty(ShadowAlphaRatio, Styles.shadowAlphaRatioLabel);
                //     EditorGUILayout.Space();
                // }
                // EditorGUILayout.EndFoldoutHeaderGroup();
                
                //m_FogFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(m_FogFoldout, Styles.FogLabel);
                //if (m_FogFoldout)
                //{
                //    m_MaterialEditor.ShaderProperty(UseHFog, Styles.useHFogLabel);
                //    m_MaterialEditor.ShaderProperty(HFogColor, Styles.hFogColorLabel);
                //    m_MaterialEditor.ShaderProperty(HFogStart, Styles.hFogStartLabel);
                //    m_MaterialEditor.ShaderProperty(HFogEnd, Styles.hFogEndLabel);
                //    m_MaterialEditor.ShaderProperty(StartPoint, Styles.startPointLabel);
                //    m_MaterialEditor.ShaderProperty(CustomFog, Styles.customFogLabel);
                //    m_MaterialEditor.ShaderProperty(FogStart, Styles.fogStartLabel);
                //    m_MaterialEditor.ShaderProperty(FogEnd, Styles.fogEndLabel);
                //    m_MaterialEditor.ShaderProperty(FogColor, Styles.fogColorLabel);
                //    EditorGUILayout.Space();
                //}
                //EditorGUILayout.EndFoldoutHeaderGroup();

                m_InjectEffectFoldout = EditorGUILayout.BeginFoldoutHeaderGroup(m_InjectEffectFoldout, Styles.InjectEffectLabel);
                if(m_InjectEffectFoldout)
                {
                    m_MaterialEditor.ShaderProperty(EffectUVScale, Styles.EffectUVScaleLabel);
                    m_MaterialEditor.ShaderProperty(EffectWeight, Styles.EffectWeightLabel);
                    EditorGUILayout.Space();
                }
                EditorGUILayout.EndFoldoutHeaderGroup();

                m_MaterialEditor.ShaderProperty(Hole, Styles.HoleLabel);

                //m_MaterialEditor.ShaderProperty(SceneBloomFactor, Styles.SceneBloomFactorLabel);
                EditorGUILayout.Space();
            }
            if (EditorGUI.EndChangeCheck())
            {
                
            }
        }

        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props)
        {
            base.FindProperties(props);
            FindProperties(props);
            m_MaterialEditor = materialEditor;
            Material material = materialEditor.target as Material;
            base.ShaderPropertiesGUI(material);
            ShaderPropertiesGUI(material);
            m_MaterialEditor.RenderQueueField();
            m_MaterialEditor.EnableInstancingField();
        }
        
    }
}
