コード例 #1
0
        void OnGUI()
        {
            // If this is the first iteration since the window is opened, do the needed initializzations
            if (firstCycle)
            {
                Start();
                firstCycle = false;
            }

            if (gradientEditor.DrawGUI())
            {
                Repaint();
            }

            if (GUILayout.Button("Save Gradient"))
            {
                string path = TSFunctions.GetSelectedPathOrFallback();
                path = EditorUtility.SaveFilePanel("Save Ramp", path, "gradient", "png");
                if (path.Length != 0)
                {
                    gradientEditor.SaveGradient(path);
                }
            }
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        public override void SectionContent(MaterialEditor materialEditor, MaterialProperty[] properties)
        {
            FindProperties(properties);

            bool isOcclusionOffsetEnabled;

            EditorGUILayout.Space();
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.BeginHorizontal();
            materialEditor.TexturePropertySingleLine(Styles.ramp, _Ramp, _RampColor);

            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)_Ramp.textureValue);
                    PreviousRamp = _Ramp.textureValue;
                }
                if (_Ramp.textureValue != (Texture)gradientEditor.GetGradientTexture())
                {
                    _Ramp.textureValue = (Texture)gradientEditor.GetGradientTexture();
                }
                if (gradientEditor.DrawGUI())
                {
                    materialEditor.Repaint();
                }
                if (GUILayout.Button("Save and apply"))
                {
                    string path = inspector.GetTextureDestinationPath((Material)_Ramp.targets[0], "_ramp.png");
                    _Ramp.textureValue      = (Texture)gradientEditor.SaveGradient(path);
                    needToStorePreviousRamp = true;
                    PreviousRamp            = null;
                    isGradientEditorOpen    = false;
                }
                EditorGUILayout.EndVertical();
            }
            else
            {
                if (PreviousRamp != null)
                {
                    _Ramp.textureValue      = PreviousRamp;
                    PreviousRamp            = null;
                    needToStorePreviousRamp = true;
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                inspector.GenerateRampMinMax(properties);
            }

            EditorGUILayout.Space();

            materialEditor.ShaderProperty(_RampOffset, Styles.rampOffset);
            EditorGUI.BeginChangeCheck();
            materialEditor.ShaderProperty(_ShadowIntensity, Styles.shadowIntensity);
            if (EditorGUI.EndChangeCheck())
            {
                inspector.GenerateRampMinMax(properties);
            }

            isOcclusionOffsetEnabled = TSFunctions.ProperToggle(ref _OcclusionOffset, Styles.occlusionOffsetIntensity);
            if (!isOcclusionOffsetEnabled && !_OcclusionOffset.hasMixedValue)
            {
                _OcclusionOffsetIntensity.floatValue = 0;
            }
            if (isOcclusionOffsetEnabled)
            {
                materialEditor.ShaderProperty(_OcclusionOffsetIntensity, Styles.occlusionOffsetIntensity);
            }


            EditorGUILayout.Space();
        }