Пример #1
0
            void DisplayOutlineWarning(MaterialProperty outlineProp)
            {
                if (outlineProp == null)
                {
                    return;
                }

                if (outlineProp.floatValue > 0 || outlineProp.hasMixedValue)
                {
                    GUILayout.Space(4f);

#if UNITY_2019_3_OR_NEWER
                    var srp = GraphicsSettings.currentRenderPipeline;
#else
                    var srp = GraphicsSettings.renderPipelineAsset;
#endif
                    if (srp != null && srp.GetType().ToString().Contains("Universal"))
                    {
                        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                        {
                            GUILayout.Label(TCP2_GUI.TempContent("Universal Render Pipeline requires some additional setup for the Outline to work, using the 'Renderer Features' system."), EditorStyles.wordWrappedLabel);
                            GUILayout.BeginHorizontal();
                            {
                                GUILayout.FlexibleSpace();
                                if (GUILayout.Button(TCP2_GUI.TempContent("See documentation"), GUILayout.ExpandWidth(false)))
                                {
                                    Application.OpenURL(OUTLINE_URP_DOCUMENTATION);
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                        EditorGUILayout.EndHorizontal();
                    }
                }
            }
Пример #2
0
            public static T DrawProObjectField <T>(T obj, params GUILayoutOption[] options) where T : UnityEngine.Object
            {
                int pickerID = "ShurikenObjectField".GetHashCode();

                var rect    = EditorGUILayout.GetControlRect(false, Styles.shurikenLineHeight, Styles.ShurikenValue, options);
                var btnRect = rect;

                btnRect.width = 20;
                rect.xMax    -= btnRect.width;
                btnRect.x    += rect.width;

                GUI.Label(rect, TCP2_GUI.TempContent(obj != null ? obj.name : "None (" + typeof(T).ToString() + ")"), Styles.ShurikenValue);
                if (GUI.Button(btnRect, "...", "MiniToolbarButton"))
                {
                    EditorGUIUtility.ShowObjectPicker <T>(obj, false, "", pickerID);
                }
                if (Event.current.commandName == "ObjectSelectorUpdated")
                {
                    if (EditorGUIUtility.GetObjectPickerControlID() == pickerID)
                    {
                        obj = EditorGUIUtility.GetObjectPickerObject() as T;
                    }
                }
                return(obj);
            }
Пример #3
0
            void HandleMobileMode()
            {
                bool showMixed      = EditorGUI.showMixedValue;
                var  mobileModeProp = FindProperty(PROP_MOBILE_MODE, _properties);

                EditorGUI.showMixedValue = mobileModeProp.hasMixedValue;
                {
                    var newMobileMode = (MobileMode)EditorGUILayout.EnumPopup(TCP2_GUI.TempContent("Mobile Mode", mobileModeHelp), (MobileMode)mobileModeProp.floatValue);
                    if ((float)newMobileMode != mobileModeProp.floatValue)
                    {
                        Undo.RecordObjects(this._materialEditor.targets, "Change Material Mobile Mode");
                        IterateMaterials(mat =>
                        {
                            mat.SetFloat(PROP_MOBILE_MODE, (float)newMobileMode);
                            if (newMobileMode == MobileMode.Enabled)
                            {
                                mat.EnableKeyword(KEYWORD_MOBILE_MODE);
                            }
                            else
                            {
                                mat.DisableKeyword(KEYWORD_MOBILE_MODE);
                            }
                        });
                    }
                }
                EditorGUI.showMixedValue = showMixed;

                if (mobileModeProp.floatValue > 0)
                {
                    EditorGUILayout.HelpBox(mobileModeHelp, MessageType.Info);
                }
            }
Пример #4
0
            void HandleOutlinePass(MaterialProperty outlineProp)
            {
                bool showMixed = EditorGUI.showMixedValue;

                // Keep track of the outline prop values and detect any change
                // This is to handle the "Reset" context menu option, which won't trigger any callback
                InitOutlineMapping();
                bool outlineValuesChanged = false;

                IterateMaterialsByIndex((mat, i) => outlineValuesChanged |= materialsOutlineMapping[i] != mat.GetFloat(PROP_OUTLINE));
                if (outlineValuesChanged)
                {
                    UpdateOutlineMapping(true);
                }

                EditorGUI.showMixedValue = outlineProp.hasMixedValue;
                {
                    EditorGUI.BeginChangeCheck();
                    _materialEditor.ShaderProperty(outlineProp, TCP2_GUI.TempContent(outlineProp.displayName));
                    if (EditorGUI.EndChangeCheck())
                    {
                        bool enableOutline = outlineProp.floatValue > 0;
                        Undo.RecordObjects(this._materialEditor.targets, (enableOutline ? "Enable" : "Disable") + " Outline on Material(s)");
                        UpdateOutlineMapping(true);
                    }
                }
                EditorGUI.showMixedValue = showMixed;
            }
Пример #5
0
            void HandleRenderingMode()
            {
                bool showMixed         = EditorGUI.showMixedValue;
                var  renderingModeProp = FindProperty(PROP_RENDERING_MODE, _properties);

                EditorGUI.showMixedValue = renderingModeProp.hasMixedValue;
                {
                    var newRenderingMode = (RenderingMode)EditorGUILayout.EnumPopup(TCP2_GUI.TempContent("Rendering Mode"), (RenderingMode)renderingModeProp.floatValue);
                    if ((float)newRenderingMode != renderingModeProp.floatValue)
                    {
                        Undo.RecordObjects(this._materialEditor.targets, "Change Material Rendering Mode");
                        SetRenderingMode(newRenderingMode);
                    }
                }
                EditorGUI.showMixedValue = showMixed;
            }
Пример #6
0
            void HandleRenderingMode()
            {
                bool showMixed         = EditorGUI.showMixedValue;
                var  renderingModeProp = FindProperty(PROP_RENDERING_MODE, _properties);

                EditorGUI.showMixedValue = renderingModeProp.hasMixedValue;
                {
                    EditorGUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.PrefixLabel(TCP2_GUI.TempContent("Rendering Mode"));
                        GUILayout.FlexibleSpace();
                        var newRenderingMode = (RenderingMode)EditorGUILayout.EnumPopup(GUIContent.none, (RenderingMode)renderingModeProp.floatValue, GUILayout.Width(118));
                        if ((float)newRenderingMode != renderingModeProp.floatValue)
                        {
                            Undo.RecordObjects(this._materialEditor.targets, "Change Material Rendering Mode");
                            SetRenderingMode(newRenderingMode);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUI.showMixedValue = showMixed;
            }
Пример #7
0
 public static bool Foldout(bool foldout, string label, string tooltip = null, bool highlighted = false)
 {
     return(Foldout(foldout, TCP2_GUI.TempContent(label, tooltip), highlighted));
 }
Пример #8
0
        void OnGUI()
        {
            TCP2_GUI.UseNewHelpIcon = true;

            EditorGUILayout.BeginHorizontal();
            TCP2_GUI.HeaderBig("TCP 2 - SMOOTHED NORMALS UTILITY");
            TCP2_GUI.HelpButton("Smoothed Normals Utility");
            EditorGUILayout.EndHorizontal();
            TCP2_GUI.Separator();

            TCP2_GUI.UseNewHelpIcon = false;

            /*
             * mFormat = EditorGUILayout.TextField(new GUIContent("Axis format", "Normals axis may need to be swapped before being packed into vertex colors/tangent/uv2 data. See documentation for more information."), mFormat);
             * mFormat = Regex.Replace(mFormat, @"[^xyzXYZ-]", "");
             * EditorGUILayout.BeginHorizontal();
             * GUILayout.Label("Known formats:");
             * if(GUILayout.Button("XYZ", EditorStyles.miniButtonLeft)) { mFormat = "XYZ"; GUI.FocusControl(null); }
             * if(GUILayout.Button("-YZ-X", EditorStyles.miniButtonMid)) { mFormat = "-YZ-X"; GUI.FocusControl(null); }
             * if(GUILayout.Button("-Z-Y-X", EditorStyles.miniButtonRight)) { mFormat = "-Z-Y-X"; GUI.FocusControl(null); }
             * EditorGUILayout.EndHorizontal();
             */

            if (mMeshes != null && mMeshes.Count > 0)
            {
                GUILayout.Space(4);
                TCP2_GUI.Header("Meshes ready to be processed:", null, true);
                mScroll = EditorGUILayout.BeginScrollView(mScroll);
                TCP2_GUI.SeparatorSimple();
                bool hasSkinnedMeshes = false;
                foreach (var sm in mMeshes.Values)
                {
                    GUILayout.Space(2);
                    GUILayout.BeginHorizontal();
                    var label = sm.name;
                    if (label.Contains(mFilenameSuffix))
                    {
                        label = label.Replace(mFilenameSuffix, "\n" + mFilenameSuffix);
                    }
                    GUILayout.Label(label, EditorStyles.wordWrappedMiniLabel, GUILayout.Width(260));
                    sm.isSkinned      = GUILayout.Toggle(sm.isSkinned, new GUIContent(" Skinned", "Should be checked if the mesh will be used on a SkinnedMeshRenderer"));
                    hasSkinnedMeshes |= sm.isSkinned;
                    GUILayout.Space(6);
                    GUILayout.EndHorizontal();
                    GUILayout.Space(2);
                    TCP2_GUI.SeparatorSimple();
                }
                EditorGUILayout.EndScrollView();
                GUILayout.FlexibleSpace();

                if (hasSkinnedMeshes)
                {
                    EditorGUILayout.HelpBox("Smoothed Normals for Skinned meshes will be stored in Tangents only. See Help to know why.", MessageType.Warning);
                }

                if (GUILayout.Button(mMeshes.Count == 1 ? "Generate Smoothed Mesh" : "Generate Smoothed Meshes", GUILayout.Height(30)))
                {
                    try
                    {
                        var   selection = new List <Object>();
                        float progress  = 1;
                        float total     = mMeshes.Count;
                        foreach (var sm in mMeshes.Values)
                        {
                            if (sm == null)
                            {
                                continue;
                            }

                            EditorUtility.DisplayProgressBar("Hold On", (mMeshes.Count > 1 ? "Generating Smoothed Meshes:\n" : "Generating Smoothed Mesh:\n") + sm.name, progress / total);
                            progress++;
                            Object o = CreateSmoothedMeshAsset(sm);
                            if (o != null)
                            {
                                selection.Add(o);
                            }
                        }
                        Selection.objects = selection.ToArray();
                    }
                    finally
                    {
                        EditorUtility.ClearProgressBar();
                    }
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Select one or multiple meshes to create a smoothed normals version.\n\nYou can also select models directly in the Scene, the new mesh will automatically be assigned.", MessageType.Info);
                GUILayout.FlexibleSpace();
                using (new EditorGUI.DisabledScope(true))
                    GUILayout.Button("Generate Smoothed Mesh", GUILayout.Height(30));
            }

            TCP2_GUI.Separator();

            smoothedNormalChannel = (Utils.SmoothedNormalsChannel)EditorGUILayout.EnumPopup(TCP2_GUI.TempContent("Vertex Data Target", "Defines where to store the smoothed normals in the mesh; use a target where there isn't any data already."), smoothedNormalChannel);
            EditorGUI.BeginDisabledGroup(smoothedNormalChannel == Utils.SmoothedNormalsChannel.Tangents || smoothedNormalChannel == Utils.SmoothedNormalsChannel.VertexColors);
            smoothedNormalUVType = (Utils.SmoothedNormalsUVType)EditorGUILayout.EnumPopup(TCP2_GUI.TempContent("UV Data Type", "Defines where and how to store the smoothed normals in the target vertex UV channel."), smoothedNormalUVType);
            EditorGUI.EndDisabledGroup();

            EditorGUILayout.HelpBox("You will need to select the proper option in the Material Inspector depending on the selected target/format!", MessageType.Info);

            /*
             * if (smoothedNormalChannel == Utils.SmoothedNormalsChannel.UV1 || smoothedNormalChannel == Utils.SmoothedNormalsChannel.UV3 || smoothedNormalChannel == Utils.SmoothedNormalsChannel.UV4 ||
             *      (smoothedNormalChannel == Utils.SmoothedNormalsChannel.UV2 && smoothedNormalUVType != Utils.SmoothedNormalsUVType.CompressedXY))
             * {
             *      EditorGUILayout.HelpBox("Only shaders made with the Shader Generator 2 support all texture coordinates.\nOther shaders only support UV2 with 'Compressed XY' option. UV1, UV3, UV4 won't work with them, as well as 'Full XYZ' and 'Compressed ZW' data types.", MessageType.Warning);
             * }
             */

            TCP2_GUI.Separator();

            TCP2_GUI.Header("Options", null, true);
            mFilenameSuffix  = EditorGUILayout.TextField(TCP2_GUI.TempContent("File name suffix"), mFilenameSuffix);
            mAlwaysOverwrite = EditorGUILayout.Toggle(new GUIContent("Always Overwrite", "Will always overwrite existing [TCP2 Smoothed] meshes"), mAlwaysOverwrite);
            mCustomDirectory = EditorGUILayout.Toggle(new GUIContent("Custom Output Directory", "Save the generated smoothed meshes in a custom directory"), mCustomDirectory);
            using (new EditorGUI.DisabledScope(!mCustomDirectory))
            {
                EditorGUILayout.BeginHorizontal();
                mCustomDirectoryPath = EditorGUILayout.TextField(GUIContent.none, mCustomDirectoryPath);
                if (GUILayout.Button("Select...", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
                {
                    var outputPath = Utils.OpenFolderPanel_ProjectPath("Choose custom output directory for generated smoothed meshes", mCustomDirectoryPath);
                    if (!string.IsNullOrEmpty(outputPath))
                    {
                        mCustomDirectoryPath = outputPath;
                    }
                }
                EditorGUILayout.EndHorizontal();
            };

            GUILayout.Space(10);
        }
Пример #9
0
 public static Rect InlineLabel(string label, bool highlight)
 {
     return(InlineLabel(TCP2_GUI.TempContent(label), highlight));
 }
Пример #10
0
 public static Rect InlineLabel(string label, string tooltip = null, bool highlight = false)
 {
     return(InlineLabel(TCP2_GUI.TempContent(label, tooltip), highlight));
 }
Пример #11
0
                public void DrawGUI(TerrainLayer terrainLayer)
                {
                    bool disabledByDiffuseAlpha = false;

                    if (this.variable == TerrainLayerVariable.smoothness)
                    {
                        bool diffuseHasAlpha = terrainLayer.diffuseTexture != null && GraphicsFormatUtility.HasAlphaChannel(terrainLayer.diffuseTexture.graphicsFormat);
                        if (diffuseHasAlpha)
                        {
                            disabledByDiffuseAlpha = true;
                        }
                    }

                    if (disabledByDiffuseAlpha)
                    {
                        EditorGUI.BeginDisabledGroup(true);
                    }

                    switch (type)
                    {
                    case ShaderPropertyType.Color:
                    {
                        colorValue = EditorGUILayout.ColorField(TCP2_GUI.TempContent(label), colorValue, true, true, hdr);
                        break;
                    }

                    case ShaderPropertyType.Float:
                    {
                        if (this.isVector4)
                        {
                            // Hack: this defines the 4 Floats mode
                            if (showR)
                            {
                                vectorValue.x = EditorGUILayout.FloatField(TCP2_GUI.TempContent(labelR), vectorValue.x);
                            }
                            if (showG)
                            {
                                vectorValue.y = EditorGUILayout.FloatField(TCP2_GUI.TempContent(labelG), vectorValue.y);
                            }
                            if (showB)
                            {
                                vectorValue.z = EditorGUILayout.FloatField(TCP2_GUI.TempContent(labelB), vectorValue.z);
                            }
                            if (showA)
                            {
                                vectorValue.w = EditorGUILayout.FloatField(TCP2_GUI.TempContent(labelAlpha), vectorValue.w);
                            }
                        }
                        else
                        {
                            floatValue = EditorGUILayout.FloatField(TCP2_GUI.TempContent(label), disabledByDiffuseAlpha ? 1f : floatValue);
                        }
                        break;
                    }

                    case ShaderPropertyType.Range:
                        if (this.isVector4)
                        {
                            // Hack: this defines the Color RGB + Float mode
                            colorValue = EditorGUILayout.ColorField(TCP2_GUI.TempContent(label), colorValue, true, false, true);
                            floatValue = EditorGUILayout.FloatField(TCP2_GUI.TempContent(labelAlpha), floatValue);
                        }
                        else
                        {
                            floatValue = EditorGUILayout.Slider(TCP2_GUI.TempContent(label), disabledByDiffuseAlpha ? 1f : floatValue, rangeLimits.x, rangeLimits.y);
                        }
                        break;

                    case ShaderPropertyType.Vector:
                    {
                        vectorValue = EditorGUILayout.Vector4Field(TCP2_GUI.TempContent(label), vectorValue);
                        break;
                    }

                    case ShaderPropertyType.Texture:
                        textureValue = EditorGUILayout.ObjectField(TCP2_GUI.TempContent(label), textureValue, typeof(Texture2D), false) as Texture2D;
                        break;
                    }

                    if (disabledByDiffuseAlpha)
                    {
                        EditorGUI.EndDisabledGroup();
                        TCP2_GUI.HelpBoxLayout("The Albedo texture has an alpha channel, so this value is <b>forced at 1.0</b> (this is a limitation of Unity's terrain system).\nPlease either use a <b>texture without alpha</b>, or use <b>another terrain layer data slot</b> in the <b>Shader Properties</b> tab of the <b>Shader Generator 2</b>.", MessageType.Warning);
                    }
                }
Пример #12
0
 public static void InlineLabel(string label, bool highlight)
 {
     InlineLabel(TCP2_GUI.TempContent(label), highlight);
 }
Пример #13
0
            public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
            {
                _materialEditor = materialEditor;
                _properties     = properties;

#if UNITY_2019_3_OR_NEWER
                var srp = GraphicsSettings.currentRenderPipeline;
#else
                var srp = GraphicsSettings.renderPipelineAsset;
#endif
                _isURP    = srp != null && srp.GetType().ToString().Contains("Universal");
                _isMobile = FindProperty(PROP_MOBILE_MODE, properties).floatValue > 0;

#if SHOW_DEFAULT_INSPECTOR
                base.OnGUI();
                return;
#endif
                //init:
                //- read metadata in properties comment to generate ui layout
                //- force update if timestamp doesn't match last (= file externally updated)
                //- do at the first Repaint to avoid layout mismatch errors
                if (Event.current.type == EventType.Repaint)
                {
                    bool force = (shaderImporter != null && shaderImporter.assetTimeStamp != lastTimestamp);
                    Initialize(materialEditor, properties, force);
                }

                var shader = (materialEditor.target as Material).shader;
                materialEditor.SetDefaultGUIWidths();

                ShowNextProperty    = true;
                DisableNextProperty = false;
                ShowStack.Clear();
                DisableStack.Clear();

                float labelWidth = EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = labelWidth - 50;

                // Header
                GUILayout.Label(TCP2_GUI.TempContent(EditorGUIUtility.currentViewWidth > 355f ? "Toony Colors Pro 2 - Hybrid Shader" : "TCP2 - Hybrid Shader"), SGUILayout.Styles.OrangeHeader);
                TCP2_GUI.Separator();

                // Mobile mode
                HandleMobileMode();
                TCP2_GUI.Separator();

                // Specific
                GUILayout.Label(TCP2_GUI.TempContent("Transparency"), SGUILayout.Styles.OrangeBoldLabel);
                HandleRenderingMode();

                // Iterate properties
                MaterialProperty outlineProp = null;
                for (int i = 0; i < properties.Length; i++)
                {
                    if (properties[i].type == MaterialProperty.PropType.Float)
                    {
                        EditorGUIUtility.labelWidth = labelWidth - 50;
                    }

                    if (guiCommands.ContainsKey(i))
                    {
                        for (int j = 0; j < guiCommands[i].Count; j++)
                        {
                            guiCommands[i][j].OnGUI();
                        }
                    }

                    //Use custom properties to enable/disable groups based on keywords
                    if (ShowNextProperty)
                    {
                        bool guiEnabled = GUI.enabled;
                        GUI.enabled = !DisableNextProperty;

                        if (properties[i].name == PROP_OUTLINE)
                        {
                            outlineProp = properties[i];
                            HandleOutlinePass(outlineProp);
                        }
                        else
                        {
                            if ((properties[i].flags & (MaterialProperty.PropFlags.HideInInspector | MaterialProperty.PropFlags.PerRendererData)) == MaterialProperty.PropFlags.None)
                            {
                                string displayName = splitLabels.ContainsKey(i) ? splitLabels[i][_isMobile ? 1 : 0] : properties[i].displayName;
                                DisplayProperty(properties[i], displayName, materialEditor);
                            }
                        }

                        GUI.enabled = guiEnabled;
                    }

                    if (properties[i].name == PROP_OUTLINE_LAST)
                    {
                        DisplayOutlineWarning(outlineProp);
                    }

                    EditorGUIUtility.labelWidth = labelWidth;
                }

                //make sure to show gui commands that are after properties
                int index = properties.Length;
                if (guiCommands.ContainsKey(index))
                {
                    for (int j = 0; j < guiCommands[index].Count; j++)
                    {
                        guiCommands[index][j].OnGUI();
                    }
                }

                GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);
                materialEditor.RenderQueueField();
                materialEditor.EnableInstancingField();
            }
Пример #14
0
            bool ITerrainLayerCustomUI.OnTerrainLayerGUI(TerrainLayer terrainLayer, Terrain terrain)
            {
                if (terrain.materialTemplate == null)
                {
                    return(false);
                }

                bool updatedTimestamp = SG2Timestamp != ShaderGenerator2.LastCompilationTimestamp;

                if (terrainShader != terrain.materialTemplate.shader || updatedTimestamp)
                {
                    SG2Timestamp  = ShaderGenerator2.LastCompilationTimestamp;
                    terrainShader = terrain.materialTemplate.shader;
                    FindUsedTerrainProperties(terrainShader);
                }

                if (currentTerrainLayer != terrainLayer || updatedTimestamp)
                {
                    currentTerrainLayer = terrainLayer;
                    foreach (var terrainLayerProperty in terrainLayerProperties)
                    {
                        terrainLayerProperty.FetchValuesFromTerrainLayer(currentTerrainLayer);
                    }
                }

                // Header
                var label = (Screen.width > 450f) ? "TOONY COLORS PRO 2 - Terrain Layer" : "TCP2 - Terrain Layer";

                TCP2_GUI.HeaderBig(label);

                // Diffuse texture
                terrainLayer.diffuseTexture = EditorGUILayout.ObjectField(TCP2_GUI.TempContent("Albedo"), terrainLayer.diffuseTexture, typeof(Texture2D), false) as Texture2D;
                TerrainLayerUtility.ValidateDiffuseTextureUI(terrainLayer.diffuseTexture);
                // TerrainLayerUtility.TilingSettingsUI(terrainLayer);

                TCP2_GUI.Header("Tiling Settings");
                terrainLayer.tileSize   = EditorGUILayout.Vector2Field(TCP2_GUI.TempContent("Size"), terrainLayer.tileSize);
                terrainLayer.tileOffset = EditorGUILayout.Vector2Field(TCP2_GUI.TempContent("Offset"), terrainLayer.tileOffset);

                GUILayout.Space(8f);

                // Custom properties
                if (terrainLayerProperties.Count > 0)
                {
                    TCP2_GUI.Header("Custom Properties");
                    foreach (var terrainLayerProperty in terrainLayerProperties)
                    {
                        EditorGUI.BeginChangeCheck();
                        {
                            terrainLayerProperty.DrawGUI(terrainLayer);
                        }
                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(terrainLayer, "Change terrain layer properties");
                            terrainLayerProperty.TransferValueToTerrainLayer(terrainLayer);
                        }
                    }
                }

                return(true);
            }
Пример #15
0
 public static bool Foldout(bool foldout, string label, bool highlighted)
 {
     return(Foldout(foldout, TCP2_GUI.TempContent(label), highlighted));
 }
Пример #16
0
 public static void InlineLabel(string label, string tooltip = null, bool highlight = false)
 {
     InlineLabel(TCP2_GUI.TempContent(label, tooltip), highlight);
 }
Пример #17
0
            //--------------------------------------------------------------------------------------------------

            public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
            {
                _materialEditor = materialEditor;
                _properties     = properties;

                hasAutoTransparency = System.Array.Exists(_properties, prop => prop.name == PROP_RENDERING_MODE);

#if SHOW_DEFAULT_INSPECTOR
                base.OnGUI();
                return;
#else
                //Header
                EditorGUILayout.BeginHorizontal();
                var label = (Screen.width > 450f) ? "TOONY COLORS PRO 2 - INSPECTOR (Generated Shader)" : (Screen.width > 300f ? "TOONY COLORS PRO 2 - INSPECTOR" : "TOONY COLORS PRO 2");
                TCP2_GUI.HeaderBig(label);
                if (TCP2_GUI.Button(TCP2_GUI.CogIcon2, "SG2", "Open in Shader Generator"))
                {
                    if (targetMaterial.shader != null)
                    {
                        ShaderGenerator2.OpenWithShader(targetMaterial.shader);
                    }
                }
                EditorGUILayout.EndHorizontal();
                TCP2_GUI.Separator();

                //Iterate Shader properties
                materialEditor.serializedObject.Update();
                var mShader = materialEditor.serializedObject.FindProperty("m_Shader");
                toggledGroups.Clear();

                // Auto-transparency
                if (hasAutoTransparency)
                {
                    int indent = EditorGUI.indentLevel;
                    EditorGUI.indentLevel++;
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            GUILayout.Space(15);
                            GUILayout.Label(TCP2_GUI.TempContent("Transparency"), EditorStyles.boldLabel);
                        }
                        EditorGUILayout.EndHorizontal();
                        HandleRenderingMode();
                    }
                    EditorGUI.indentLevel = indent;
                }

                if (materialEditor.isVisible && !mShader.hasMultipleDifferentValues && mShader.objectReferenceValue != null)
                {
                    //Retina display fix
                    EditorGUIUtility.labelWidth = Utils.ScreenWidthRetina - 120f;
                    EditorGUIUtility.fieldWidth = 64f;

                    EditorGUI.BeginChangeCheck();

                    EditorGUI.indentLevel++;
                    foreach (var p in properties)
                    {
                        var visible = (toggledGroups.Count == 0 || toggledGroups.Peek());

                        //Hacky way to separate material inspector properties into foldout groups
                        if (p.name.StartsWith("__BeginGroup"))
                        {
                            //Foldout
                            if (visible)
                            {
                                GUILayout.Space(2f);
                                Rect propertyRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight, EditorStyles.layerMaskField);
                                propertyRect.x     += 12;
                                propertyRect.width -= 12;
                                p.floatValue        = EditorGUI.Foldout(propertyRect, p.floatValue > 0, p.displayName, true) ? 1 : 0;
                            }

                            EditorGUI.indentLevel++;
                            toggledGroups.Push((p.floatValue > 0) && visible);
                        }
                        else if (p.name.StartsWith("__EndGroup"))
                        {
                            EditorGUI.indentLevel--;
                            toggledGroups.Pop();
                            GUILayout.Space(2f);
                        }
                        else
                        {
                            //Draw regular property
                            if (visible && (p.flags & (MaterialProperty.PropFlags.PerRendererData | MaterialProperty.PropFlags.HideInInspector)) == MaterialProperty.PropFlags.None)
                            {
                                _materialEditor.ShaderProperty(p, p.displayName);
                            }
                        }
                    }
                    EditorGUI.indentLevel--;

                    if (EditorGUI.EndChangeCheck())
                    {
                        materialEditor.PropertiesChanged();
                    }
                }
#endif     // !SHOW_DEFAULT_INSPECTOR

#if UNITY_5_5_OR_NEWER
                TCP2_GUI.Separator();
                materialEditor.RenderQueueField();
#endif
#if UNITY_5_6_OR_NEWER
                materialEditor.EnableInstancingField();
#endif
            }
Пример #18
0
 public static void InlineHeader(string label, string tooltip = null)
 {
     InlineHeader(TCP2_GUI.TempContent(label, tooltip));
 }
 public static bool ButtonPopup(string label)
 {
     return(ButtonPopup(TCP2_GUI.TempContent(label)));
 }