예제 #1
0
        /// <summary>
        /// Draws the GUI
        /// </summary>
        /// <param name="materialEditor">Material editor provided by the custom inspector</param>
        /// <param name="properties">Array of materialProperties provided by the custom inspector</param>
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
        {
            //if is the first cycle it runs, do the initializzations needed on the start function
            if (isFirstCycle)
            {
                Start(materialEditor, properties);
                isFirstCycle = false;
            }
            TSFunctions.DrawHeader(EditorGUIUtility.currentViewWidth, 10);

            //Temporary code for converting back HDR colors
#if UNITY_2018_1_OR_NEWER
            if (FindProperty("_NeedsFix", properties).floatValue == 1)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Convert HDR colors back to 2017 look"))
                {
                    foreach (MaterialProperty m in properties)
                    {
                        if (m.flags == MaterialProperty.PropFlags.HDR)
                        {
                            m.colorValue = m.colorValue.linear;
                        }
                    }
                    FindProperty("_NeedsFix", properties).floatValue = 0;
                }
                if (GUILayout.Button("Keep current colors"))
                {
                    FindProperty("_NeedsFix", properties).floatValue = 0;
                }
                EditorGUILayout.EndHorizontal();
            }
#endif

            //if a keyword is used to apply the effects on the shader caused by enabling/disabling a section, it needs to be set every update
            foreach (Material mat in _SpecularOn.targets)
            {
                TSFunctions.SetKeyword(mat, "_SPECULARHIGHLIGHTS_OFF", !(mat.GetFloat(_SpecularOn.name) != 0));
                TSFunctions.SetKeyword(mat, "_DETAIL_MULX2", mat.GetFloat(_DetailMapOn.name) != 0);
            }

            //draw main section
            if (inspectorLevel == InspectorLevel.Basic)
            {
                basicMain.DrawSection(materialEditor);
            }
            else
            {
                main.DrawSection(materialEditor);
            }
            group.DrawSectionsList(materialEditor, properties);
            group.DrawAddButton(properties);

            TSFunctions.DrawFooter();
        }
예제 #2
0
        /// <summary>
        /// Draws the GUI
        /// </summary>
        /// <param name="materialEditor">Material editor provided by the custom inspector</param>
        /// <param name="properties">Array of materialProperties provided by the custom inspector</param>
        public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
        {
            //if is the first cycle it runs, do the initializzations needed on the start function
            if (isFirstCycle)
            {
                Start(materialEditor, properties);
                isFirstCycle = false;
            }
            //Fetching properties is needed only if the start function has not run since the start function already fetches them once
            else
            {
                FindProperties(properties);
            }
            TSFunctions.DrawHeader(EditorGUIUtility.currentViewWidth, 10);

            //Temporary code for converting back HDR colors
            #if UNITY_2018_1_OR_NEWER
            if (FindProperty("_NeedsFix", properties).floatValue == 1)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("Convert HDR colors back to 2017 look"))
                {
                    foreach (MaterialProperty m in properties)
                    {
                        if (m.flags == MaterialProperty.PropFlags.HDR)
                        {
                            m.colorValue = m.colorValue.linear;
                        }
                    }
                    FindProperty("_NeedsFix", properties).floatValue = 0;
                }
                if (GUILayout.Button("Keep current colors"))
                {
                    FindProperty("_NeedsFix", properties).floatValue = 0;
                }
                EditorGUILayout.EndHorizontal();
            }
            #endif

            //if a keyword is used to apply the effects on the shader caused by enabling/disabling a section, it needs to be set every update
            foreach (Material mat in _SpecularOn.targets)
            {
                TSFunctions.SetKeyword(mat, "_ENABLE_SPECULAR", mat.GetFloat(_SpecularOn.name) != 0);
                TSFunctions.SetKeyword(mat, "_DETAIL_MAP", mat.GetFloat(_DetailMapOn.name) != 0);
            }

            //draw main section
            if (inspectorLevel == InspectorLevel.Basic)
            {
                DrawBasicMainSection(materialEditor);
            }
            else
            {
                if (!_RampOn.hasMixedValue && _RampOn.floatValue == 0f)
                {
                    _Ramp.textureValue          = TSConstants.DefaultRamp;
                    _RampOffset.floatValue      = 0f;
                    _ShadowIntensity.floatValue = 0.4f;
                }
                DrawMainSection(materialEditor);
            }
            group.DrawSectionsList(materialEditor);
            group.DrawAddButton();

            TSFunctions.DrawFooter();
        }