public override void SectionContent(MaterialEditor materialEditor, MaterialProperty[] properties)
        {
            FindProperties(properties);

            bool isToonyHighlightsEnabled;

            EditorGUILayout.Space();

            TSFunctions.DrawSelector(Enum.GetNames(typeof(Workflow)), _workflow, Styles.workflow, materialEditor);
            if ((Workflow)_workflow.floatValue == Workflow.Metallic)
            {
                if (level == InspectorLevel.Normal)
                {
                    Rect r = TSFunctions.GetControlRectForSingleLine();
                    EditorGUI.BeginChangeCheck();
                    materialEditor.TexturePropertyMiniThumbnail(r, _MetallicMap, Styles.metallic.text, Styles.metallic.tooltip);
                    if (EditorGUI.EndChangeCheck())
                    {
                        inspector.RegenerateMSOT();
                    }
                    TSFunctions.ProperSlider(MaterialEditor.GetRectAfterLabelWidth(r), ref _Metallic);
                }
                else
                {
                    materialEditor.ShaderProperty(_Metallic, Styles.metallic);
                }
            }
            else if ((Workflow)_workflow.floatValue == Workflow.Specular)
            {
                materialEditor.TexturePropertySingleLine(Styles.specular, _MetallicMap);
            }

            if (level == InspectorLevel.Normal)
            {
                Rect r = TSFunctions.GetControlRectForSingleLine();
                EditorGUI.BeginChangeCheck();
                materialEditor.TexturePropertyMiniThumbnail(r, _GlossinessMap, Styles.smoothness.text, Styles.smoothness.tooltip);
                if (EditorGUI.EndChangeCheck())
                {
                    inspector.RegenerateMSOT();
                }
                TSFunctions.ProperSlider(MaterialEditor.GetRectAfterLabelWidth(r), ref _Glossiness);
            }
            else
            {
                materialEditor.ShaderProperty(_Glossiness, Styles.smoothness);
            }

            TSFunctions.DrawSelector(Enum.GetNames(typeof(SpMode)), _SpMode, Styles.spMode, materialEditor);
            if ((SpMode)_SpMode.floatValue == SpMode.Anisotropic)
            {
                materialEditor.TexturePropertySingleLine(Styles.anisotropy, _AnisotropyMap, _Anisotropy);
                materialEditor.TexturePropertySingleLine(Styles.tangent, _TangentMap);
            }
            else if ((SpMode)_SpMode.floatValue == SpMode.Fake)
            {
                materialEditor.TexturePropertySingleLine(Styles.fakeHighlights, _FakeHightlights);
                materialEditor.ShaderProperty(_FakeHighlightIntensity, Styles.fakeHighlightIntensity);
            }

            TSFunctions.DrawSelector(Enum.GetNames(typeof(IndirectSpecular)), _indirectSpecular, Styles.indirectSpecular, materialEditor);
            if ((IndirectSpecular)_indirectSpecular.floatValue == IndirectSpecular.Matcap)
            {
                materialEditor.TexturePropertySingleLine(Styles.matcap, _Matcap);
            }
            else if ((IndirectSpecular)_indirectSpecular.floatValue == IndirectSpecular.Cubemap)
            {
                materialEditor.TexturePropertySingleLine(Styles.cubemap, _Cubemap);
            }
            else if ((IndirectSpecular)_indirectSpecular.floatValue == IndirectSpecular.Color)
            {
                TSFunctions.ProperColorBox(ref _IndirectColor, Styles.indirectColor);
            }
            if ((IndirectSpecular)_indirectSpecular.floatValue != IndirectSpecular.None)
            {
                TSFunctions.ProperToggle(ref _IndirectOverride, Styles.indirectOverride);
            }
            else
            {
                _IndirectOverride.floatValue = 0;
            }

            isToonyHighlightsEnabled = TSFunctions.ProperToggle(ref _ToonyHighlights, Styles.toonyHighlight);

            if (isToonyHighlightsEnabled)
            {
                EditorGUILayout.BeginHorizontal();
                materialEditor.TexturePropertySingleLine(Styles.highlightRamp, _HighlightRamp, _HighlightRampColor);

                if (GUILayout.Button(Styles.GradientEditorButton))
                {
                    EditorGUILayout.EndHorizontal();
                    isGradientEditorOpen = !isGradientEditorOpen;
                    Styles.ToggleGradientEditorToggle(isGradientEditorOpen);
                }
                else
                {
                    EditorGUILayout.EndHorizontal();
                }
                if (isGradientEditorOpen)
                {
                    EditorGUILayout.BeginVertical("box");
                    if (needToStorePreviousRamp)
                    {
                        needToStorePreviousRamp = false;
                        gradientEditor.TranslateTextureToGradient((Texture2D)_HighlightRamp.textureValue);
                        PreviousRamp = _HighlightRamp.textureValue;
                    }
                    if (_HighlightRamp.textureValue != (Texture)gradientEditor.GetGradientTexture())
                    {
                        _HighlightRamp.textureValue = (Texture)gradientEditor.GetGradientTexture();
                    }
                    if (gradientEditor.DrawGUI())
                    {
                        materialEditor.Repaint();
                    }
                    if (GUILayout.Button("Save and apply"))
                    {
                        string path = inspector.GetTextureDestinationPath((Material)_HighlightRamp.targets[0], "_highlight_ramp.png");
                        _HighlightRamp.textureValue = (Texture)gradientEditor.SaveGradient(path);
                        needToStorePreviousRamp     = true;
                        PreviousRamp         = null;
                        isGradientEditorOpen = false;
                    }
                    EditorGUILayout.EndVertical();
                }
                else
                {
                    if (PreviousRamp != null)
                    {
                        _HighlightRamp.textureValue = PreviousRamp;
                        PreviousRamp            = null;
                        needToStorePreviousRamp = true;
                    }
                }

                materialEditor.ShaderProperty(_HighlightRampOffset, Styles.hightlightRampOffset);
                materialEditor.ShaderProperty(_HighlightIntensity, Styles.highlightIntensity);
            }

            materialEditor.TexturePropertySingleLine(Styles.highlightPattern, _HighlightPattern);
            EditorGUI.indentLevel++;
            materialEditor.TextureScaleOffsetProperty(_HighlightPattern);
            EditorGUI.indentLevel--;

            EditorGUILayout.Space();
        }
Beispiel #2
0
        public void DrawSection(MaterialEditor materialEditor)
        {
            EditorGUI.BeginChangeCheck();
            TSFunctions.DrawSelector(Enum.GetNames(typeof(ToonyStandardGUI.BlendMode)), _blendMode, Styles.blendMode, materialEditor);
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Material mat in _blendMode.targets)
                {
                    ToonyStandardGUI.SetupMaterialWithBlendMode(mat, (ToonyStandardGUI.BlendMode)_blendMode.floatValue, mat.GetFloat("_OutlineOn") > 0);
                }
            }

            //draw cull mode
            materialEditor.ShaderProperty(_Cull, Styles.cullMode);
            EditorGUILayout.Space();

            //draw main properties
            materialEditor.TexturePropertySingleLine(Styles.mainTex, _MainTex, _Color);
            if ((ToonyStandardGUI.BlendMode)_blendMode.floatValue == ToonyStandardGUI.BlendMode.Cutout)
            {
                EditorGUI.indentLevel += MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1;
                materialEditor.ShaderProperty(_Cutoff, Styles.cutOff);
                EditorGUI.indentLevel -= MaterialEditor.kMiniTextureFieldLabelIndentLevel + 1;
            }
            materialEditor.TexturePropertySingleLine(Styles.normal, _BumpMap, _BumpScale);

            if (level == InspectorLevel.Normal)
            {
                Rect r = TSFunctions.GetControlRectForSingleLine();
                EditorGUI.BeginChangeCheck();
                materialEditor.TexturePropertyMiniThumbnail(r, _OcclusionMap, Styles.occlusion.text, Styles.occlusion.tooltip);
                if (EditorGUI.EndChangeCheck())
                {
                    gui.RegenerateMSOT(false);
                }
                TSFunctions.ProperSlider(MaterialEditor.GetRectAfterLabelWidth(r), ref _Occlusion);
            }
            else
            {
                materialEditor.ShaderProperty(_Occlusion, Styles.occlusion);
            }

            //emission
            EditorGUI.BeginChangeCheck();
            if (materialEditor.EmissionEnabledProperty())
            {
                materialEditor.TexturePropertySingleLine(Styles.emission, _Emission, _EmissionColor);
                materialEditor.LightmapEmissionProperty(MaterialEditor.kMiniTextureFieldLabelIndentLevel);
            }
            if (EditorGUI.EndChangeCheck())
            {
                foreach (Material mat in _Emission.targets)
                {
                    MaterialEditor.FixupEmissiveFlag(mat);
                    bool shouldEmissionBeEnabled = (mat.globalIlluminationFlags & MaterialGlobalIlluminationFlags.EmissiveIsBlack) == 0;
                    TSFunctions.SetKeyword(mat, "_EMISSION", shouldEmissionBeEnabled);
                    if (shouldEmissionBeEnabled)
                    {
                        mat.SetOverrideTag("IsEmissive", "true");
                    }
                    else
                    {
                        mat.SetOverrideTag("IsEmissive", "false");
                    }
                }
            }
            //if in expert mode show the MSOT map and a button for the texture packer
            if (level == InspectorLevel.Expert)
            {
                EditorGUILayout.BeginHorizontal();
                materialEditor.TexturePropertySingleLine(Styles.MSOT, _MSOT);
                if (GUILayout.Button(Styles.TexturePackerButton))
                {
                    EditorGUILayout.EndHorizontal();
                    isTexturePackerOpen = !isTexturePackerOpen;
                    Styles.ToggleTexturePackerContent(isTexturePackerOpen);
                }
                else
                {
                    EditorGUILayout.EndHorizontal();
                }

                if (isTexturePackerOpen)
                {
                    EditorGUILayout.BeginVertical("box");
                    packer.DrawGUI();
                    EditorGUILayout.EndVertical();
                    if (_MSOT.textureValue != (Texture)packer.resultTex && packer.resultTex != null)
                    {
                        _MSOT.textureValue = packer.resultTex;
                        packer.resultTex   = null;
                    }
                }
            }
            EditorGUILayout.Space();
            materialEditor.TextureScaleOffsetProperty(_MainTex);
            //EditorGUILayout.Space();
            //materialEditor.RenderQueueField();

            EditorGUILayout.Space();
        }