protected override void DrawGUI(Rect position, TCP2_Config config) { EditorGUILayout.BeginHorizontal(); TCP2_GUI.HelpButton("Shader Target"); TCP2_GUI.SubHeader("Shader Target", "Defines the shader target level to compile for", config.shaderTarget != 30, LABEL_WIDTH - 24f); int newTarget = EditorGUILayout.IntPopup(config.shaderTarget, #if UNITY_5_4_OR_NEWER new string[] { "2.0", "2.5", "3.0", "3.5", "4.0", "5.0" }, new int[] { 20, 25, 30, 35, 40, 50 }); #else new string[] { "2.0", "3.0", "4.0", "5.0" }, new int[] { 20, 30, 40, 50 }); #endif if (newTarget != config.shaderTarget) { config.shaderTarget = newTarget; } EditorGUILayout.EndHorizontal(); }
protected override void DrawGUI(Rect position, Config config) { //Check if any feature within that Foldout are enabled, and show different color if so var hasToggledFeatures = false; var i = Array.IndexOf(Template.CurrentTemplate.uiFeatures, this); if (i >= 0) { for (i++; i < Template.CurrentTemplate.uiFeatures.Length; i++) { var uiFeature = Template.CurrentTemplate.uiFeatures[i]; if (uiFeature is UIFeature_DropDownEnd) { break; } hasToggledFeatures |= uiFeature.Highlighted(config) && uiFeature.Enabled(config); } } var color = GUI.color; GUI.color *= EditorGUIUtility.isProSkin ? Color.white : new Color(.95f, .95f, .95f, 1f); EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUI.color = color; EditorGUI.BeginChangeCheck(); foldout = TCP2_GUI.HeaderFoldoutHighlight(foldout, guiContent, hasToggledFeatures); FoldoutStack.Push(foldout); if (EditorGUI.EndChangeCheck()) { UpdatePersistentState(); if (Event.current.alt || Event.current.control) { var state = foldout; foreach (var dd in AllDropDowns) { dd.foldout = state; dd.UpdatePersistentState(); } } } }
private void GUISingleFlag(string flagName, string label, string tooltip = null, bool enabled = true, bool increaseIndentLevel = false, bool visible = true, string helpTopic = null) { if (!enabled) { GUI.enabled = false; } if (increaseIndentLevel) { label = "▪ " + label; } bool flag = TCP2_ShaderGeneratorUtils.HasFeatures(mCurrentConfig.Flags, flagName); if (visible) { EditorGUILayout.BeginHorizontal(); if (increaseIndentLevel) { TCP2_GUI.SubHeader(label, tooltip, flag, 165); flag = EditorGUILayout.Toggle(flag); } else { GUI.enabled = mGUIEnabled; if (!string.IsNullOrEmpty(helpTopic)) { TCP2_GUI.HelpButton(label.TrimStart('▪', ' '), string.IsNullOrEmpty(helpTopic) ? label.TrimStart('▪', ' ') : helpTopic); } GUI.enabled = enabled; TCP2_GUI.SubHeader(label, tooltip, flag, 145); flag = EditorGUILayout.Toggle(flag); } EditorGUILayout.EndHorizontal(); } TCP2_ShaderGeneratorUtils.ToggleFlag(mCurrentConfig.Flags, flagName, flag); if (!enabled) { GUI.enabled = mGUIEnabled; } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { FindProperties(props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly m_MaterialEditor = materialEditor; var material = materialEditor.target as Material; // Make sure that needed setup (ie keywords/renderqueue) are set up if we're switching some existing // material to a standard shader. // Do this before any GUI code has been issued to prevent layout issues in subsequent GUILayout statements (case 780071) if (m_FirstTimeApply) { MaterialChanged(material, m_WorkflowMode); m_FirstTimeApply = false; } //TCP2 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.CogIcon, "O", "Open in Shader Generator")) { if (material.shader != null) { TCP2_ShaderGenerator.OpenWithShader(material.shader); } } EditorGUILayout.EndHorizontal(); TCP2_GUI.Separator(); ShaderPropertiesGUI(material); #if UNITY_5_5_OR_NEWER materialEditor.RenderQueueField(); #endif #if UNITY_5_6_OR_NEWER materialEditor.EnableInstancingField(); #endif }
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; }
static public bool ShaderKeywordToggle(string keyword, string label, string tooltip, List <string> list, ref bool update, string helpTopic = null) { float w = EditorGUIUtility.labelWidth; if (!string.IsNullOrEmpty(helpTopic)) { EditorGUILayout.BeginHorizontal(); EditorGUIUtility.labelWidth = w - 16; TCP2_GUI.HelpButton(helpTopic); } bool boolValue = list.Contains(keyword); EditorGUI.BeginChangeCheck(); boolValue = EditorGUILayout.ToggleLeft(new GUIContent(label, tooltip), boolValue, boolValue ? EditorStyles.boldLabel : EditorStyles.label); if (EditorGUI.EndChangeCheck()) { if (boolValue) { list.Add(keyword); } else { list.Remove(keyword); } update = true; } if (!string.IsNullOrEmpty(helpTopic)) { EditorGUIUtility.labelWidth = w; EditorGUILayout.EndHorizontal(); } return(boolValue); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { mMaterialEditor = materialEditor; #if SHOW_DEFAULT_INSPECTOR base.OnGUI(); return; #else if (mJustChangedShader) { mJustChangedShader = false; mVariantError = null; Event.current.Use(); //Avoid layout mismatch error SceneView.RepaintAll(); } UpdateFeaturesFromShader(); //Get material keywords List <string> keywordsList = new List <string>(targetMaterial.shaderKeywords); bool updateKeywords = false; bool updateVariant = false; //Header EditorGUILayout.BeginHorizontal(); TCP2_GUI.HeaderBig("TOONY COLORS PRO 2 - INSPECTOR"); if (isGeneratedShader && TCP2_GUI.Button(TCP2_GUI.CogIcon, "O", "Open in Shader Generator")) { if (targetMaterial.shader != null) { TCP2_ShaderGenerator.OpenWithShader(targetMaterial.shader); } } TCP2_GUI.HelpButton("Unified Shader"); EditorGUILayout.EndHorizontal(); TCP2_GUI.Separator(); if (!string.IsNullOrEmpty(mVariantError)) { EditorGUILayout.HelpBox(mVariantError, MessageType.Error); EditorGUILayout.HelpBox("Some of the shaders are packed to avoid super long loading times when you import Toony Colors Pro 2 into Unity.\n\n" + "You can unpack them by category in the menu:\n\"Tools > Toony Colors Pro 2 > Unpack Shaders > ...\"", MessageType.Info); } //Iterate Shader properties materialEditor.serializedObject.Update(); SerializedProperty mShader = materialEditor.serializedObject.FindProperty("m_Shader"); if (materialEditor.isVisible && !mShader.hasMultipleDifferentValues && mShader.objectReferenceValue != null) { //Retina display fix EditorGUIUtility.labelWidth = TCP2_Utils.ScreenWidthRetina - 120f; EditorGUIUtility.fieldWidth = 64f; EditorGUI.BeginChangeCheck(); MaterialProperty[] props = properties; //UNFILTERED PARAMETERS ============================================================== TCP2_GUI.HeaderAndHelp("BASE", "Base Properties"); if (ShowFilteredProperties(null, props)) { if (!isGeneratedShader) { TCP2_Utils.ShaderKeywordToggle("TCP2_DISABLE_WRAPPED_LIGHT", "Disable Wrapped Lighting", "Disable wrapped lighting, reducing intensity received from lights", keywordsList, ref updateKeywords, "Disable Wrapped Lighting"); } TCP2_GUI.Separator(); } //FILTERED PARAMETERS ================================================================ //RAMP TYPE -------------------------------------------------------------------------- if (CategoryFilter("TEXTURE_RAMP")) { if (isGeneratedShader) { ShowFilteredProperties("#RAMPT#", props); } else { if (TCP2_Utils.ShaderKeywordToggle("TCP2_RAMPTEXT", "Texture Toon Ramp", "Make the toon ramp based on a texture", keywordsList, ref updateKeywords, "Ramp Style")) { ShowFilteredProperties("#RAMPT#", props); } else { ShowFilteredProperties("#RAMPF#", props); } } } else { ShowFilteredProperties("#RAMPF#", props); } TCP2_GUI.Separator(); //BUMP/NORMAL MAPPING ---------------------------------------------------------------- if (CategoryFilter("BUMP")) { if (isGeneratedShader) { TCP2_GUI.HeaderAndHelp("BUMP/NORMAL MAPPING", "Normal/Bump map"); ShowFilteredProperties("#NORM#", props); ShowFilteredProperties("#PLLX#", props); } else { if (TCP2_Utils.ShaderKeywordToggle("TCP2_BUMP", "BUMP/NORMAL MAPPING", "Enable bump mapping using normal maps", keywordsList, ref updateKeywords, "Normal/Bump map")) { ShowFilteredProperties("#NORM#", props); } } TCP2_GUI.Separator(); } //SPECULAR --------------------------------------------------------------------------- if (CategoryFilter("SPECULAR", "SPECULAR_ANISOTROPIC")) { if (isGeneratedShader) { TCP2_GUI.HeaderAndHelp("SPECULAR", "Specular"); ShowFilteredProperties("#SPEC#", props); if (HasFlags("SPECULAR_ANISOTROPIC")) { ShowFilteredProperties("#SPECA#", props); } if (HasFlags("SPECULAR_TOON")) { ShowFilteredProperties("#SPECT#", props); } } else { bool specular = TCP2_Utils.HasKeywords(keywordsList, "TCP2_SPEC", "TCP2_SPEC_TOON"); TCP2_Utils.ShaderVariantUpdate("Specular", ShaderVariants, ShaderVariantsEnabled, specular, ref updateVariant); specular |= TCP2_Utils.ShaderKeywordRadio("SPECULAR", new string[] { "TCP2_SPEC_OFF", "TCP2_SPEC", "TCP2_SPEC_TOON" }, new GUIContent[] { new GUIContent("Off", "No Specular"), new GUIContent("Regular", "Default Blinn-Phong Specular"), new GUIContent("Cartoon", "Specular with smoothness control") }, keywordsList, ref updateKeywords); if (specular) { ShowFilteredProperties("#SPEC#", props); bool specr = TCP2_Utils.HasKeywords(keywordsList, "TCP2_SPEC_TOON"); if (specr) { ShowFilteredProperties("#SPECT#", props); } } } TCP2_GUI.Separator(); } //REFLECTION ------------------------------------------------------------------------- if (CategoryFilter("REFLECTION") && !isMobileShader) { if (isGeneratedShader) { TCP2_GUI.HeaderAndHelp("REFLECTION", "Reflection"); ShowFilteredProperties("#REFL#", props); #if UNITY_5 if (HasFlags("U5_REFLPROBE")) { ShowFilteredProperties("#REFL_U5#", props); } #endif if (HasFlags("REFL_COLOR")) { ShowFilteredProperties("#REFLC#", props); } if (HasFlags("REFL_ROUGH")) { ShowFilteredProperties("#REFLR#", props); EditorGUILayout.HelpBox("Cubemap Texture needs to have MipMaps enabled for Roughness to work!", MessageType.Info); } } else { bool reflection = TCP2_Utils.HasKeywords(keywordsList, "TCP2_REFLECTION", "TCP2_REFLECTION_MASKED"); TCP2_Utils.ShaderVariantUpdate("Reflection", ShaderVariants, ShaderVariantsEnabled, reflection, ref updateVariant); reflection |= TCP2_Utils.ShaderKeywordRadio("REFLECTION", new string[] { "TCP2_REFLECTION_OFF", "TCP2_REFLECTION", "TCP2_REFLECTION_MASKED" }, new GUIContent[] { new GUIContent("Off", "No Cubemap Reflection"), new GUIContent("Global", "Global Cubemap Reflection"), new GUIContent("Masked", "Masked Cubemap Reflection (using the main texture's alpha channel)") }, keywordsList, ref updateKeywords); if (reflection) { #if UNITY_5 //Reflection Probes toggle if (TCP2_Utils.ShaderKeywordToggle("TCP2_U5_REFLPROBE", "Use Reflection Probes", "Use Unity 5's Reflection Probes", keywordsList, ref updateKeywords)) { ShowFilteredProperties("#REFL_U5#", props); } #endif ShowFilteredProperties("#REFL#", props); } } TCP2_GUI.Separator(); } //MATCAP ----------------------------------------------------------------------------- if (CategoryFilter("MATCAP")) { if (isGeneratedShader) { TCP2_GUI.Header("MATCAP"); ShowFilteredProperties("#MC#", props); TCP2_GUI.Separator(); } else if (isMobileShader) { bool matcap = TCP2_Utils.HasKeywords(keywordsList, "TCP2_MC", "TCP2_MCMASK"); TCP2_Utils.ShaderVariantUpdate("Matcap", ShaderVariants, ShaderVariantsEnabled, matcap, ref updateVariant); matcap |= TCP2_Utils.ShaderKeywordRadio("MATCAP", new string[] { "TCP2_MC_OFF", "TCP2_MC", "TCP2_MCMASK" }, new GUIContent[] { new GUIContent("Off", "No MatCap reflection"), new GUIContent("Global", "Global additive MatCap"), new GUIContent("Masked", "Masked additive MatCap (using the main texture's alpha channel)") }, keywordsList, ref updateKeywords); if (matcap) { ShowFilteredProperties("#MC#", props); } TCP2_GUI.Separator(); } } //SUBSURFACE SCATTERING -------------------------------------------------------------------------------- if (CategoryFilter("SUBSURFACE_SCATTERING") && isGeneratedShader) { TCP2_GUI.HeaderAndHelp("SUBSURFACE SCATTERING", "Subsurface Scattering"); ShowFilteredProperties("#SUBS#", props); TCP2_GUI.Separator(); } //RIM -------------------------------------------------------------------------------- if (CategoryFilter("RIM", "RIM_OUTLINE")) { if (isGeneratedShader) { TCP2_GUI.HeaderAndHelp("RIM", "Rim"); ShowFilteredProperties("#RIM#", props); if (HasFlags("RIMDIR")) { ShowFilteredProperties("#RIMDIR#", props); if (HasFlags("PARALLAX")) { EditorGUILayout.HelpBox("Because it affects the view direction vector, Rim Direction may distort Parallax effect.", MessageType.Warning); } } } else { bool rim = TCP2_Utils.HasKeywords(keywordsList, "TCP2_RIM"); bool rimOutline = TCP2_Utils.HasKeywords(keywordsList, "TCP2_RIMO"); TCP2_Utils.ShaderVariantUpdate("Rim", ShaderVariants, ShaderVariantsEnabled, rim, ref updateVariant); TCP2_Utils.ShaderVariantUpdate("RimOutline", ShaderVariants, ShaderVariantsEnabled, rimOutline, ref updateVariant); rim |= rimOutline |= TCP2_Utils.ShaderKeywordRadio("RIM", new string[] { "TCP2_RIM_OFF", "TCP2_RIM", "TCP2_RIMO" }, new GUIContent[] { new GUIContent("Off", "No Rim effect"), new GUIContent("Lighting", "Rim lighting (additive)"), new GUIContent("Outline", "Rim outline (blended)") }, keywordsList, ref updateKeywords); if (rim || rimOutline) { ShowFilteredProperties("#RIM#", props); if (CategoryFilter("RIMDIR")) { if (TCP2_Utils.ShaderKeywordToggle("TCP2_RIMDIR", "Directional Rim", "Enable directional rim control (rim calculation is approximated if enabled)", keywordsList, ref updateKeywords)) { ShowFilteredProperties("#RIMDIR#", props); } } } } TCP2_GUI.Separator(); } //CUBEMAP AMBIENT -------------------------------------------------------------------- if (CategoryFilter("CUBE_AMBIENT") && isGeneratedShader) { TCP2_GUI.HeaderAndHelp("CUBEMAP AMBIENT", "Cubemap Ambient"); ShowFilteredProperties("#CUBEAMB#", props); TCP2_GUI.Separator(); } //DIRECTIONAL AMBIENT -------------------------------------------------------------------- if (CategoryFilter("DIRAMBIENT") && isGeneratedShader) { TCP2_GUI.HeaderAndHelp("DIRECTIONAL AMBIENT", "Directional Ambient"); DirectionalAmbientGUI("#DAMB#", props); TCP2_GUI.Separator(); } //SKETCH -------------------------------------------------------------------------------- if (CategoryFilter("SKETCH", "SKETCH_GRADIENT") && isGeneratedShader) { TCP2_GUI.HeaderAndHelp("SKETCH", "Sketch"); bool sketch = HasFlags("SKETCH"); bool sketchG = HasFlags("SKETCH_GRADIENT"); if (sketch || sketchG) { ShowFilteredProperties("#SKETCH#", props); } if (sketchG) { ShowFilteredProperties("#SKETCHG#", props); } TCP2_GUI.Separator(); } //OUTLINE -------------------------------------------------------------------------------- if (CategoryFilter("OUTLINE", "OUTLINE_BLENDING")) { bool hasOutlineOpaque = false; bool hasOutlineBlending = false; bool hasOutline = false; if (isGeneratedShader) { TCP2_GUI.HeaderAndHelp("OUTLINE", "Outline"); hasOutlineOpaque = HasFlags("OUTLINE"); hasOutlineBlending = HasFlags("OUTLINE_BLENDING"); hasOutline = hasOutlineOpaque || hasOutlineBlending; } else { hasOutlineOpaque = TCP2_Utils.HasKeywords(keywordsList, "OUTLINES"); hasOutlineBlending = TCP2_Utils.HasKeywords(keywordsList, "OUTLINE_BLENDING"); hasOutline = hasOutlineOpaque || hasOutlineBlending; TCP2_Utils.ShaderVariantUpdate("Outline", ShaderVariants, ShaderVariantsEnabled, hasOutlineOpaque, ref updateVariant); TCP2_Utils.ShaderVariantUpdate("OutlineBlending", ShaderVariants, ShaderVariantsEnabled, hasOutlineBlending, ref updateVariant); hasOutline |= TCP2_Utils.ShaderKeywordRadio("OUTLINE", new string[] { "OUTLINE_OFF", "OUTLINES", "OUTLINE_BLENDING" }, new GUIContent[] { new GUIContent("Off", "No Outline"), new GUIContent("Opaque", "Opaque Outline"), new GUIContent("Blended", "Allows transparent Outline and other effects") }, keywordsList, ref updateKeywords); } if (hasOutline) { EditorGUI.indentLevel++; //Outline Type --------------------------------------------------------------------------- ShowFilteredProperties("#OUTLINE#", props, false); if (!isMobileShader && !HasFlags("FORCE_SM2")) { bool outlineTextured = TCP2_Utils.ShaderKeywordToggle("TCP2_OUTLINE_TEXTURED", "Outline Color from Texture", "If enabled, outline will take an averaged color from the main texture multiplied by Outline Color", keywordsList, ref updateKeywords); if (outlineTextured) { ShowFilteredProperties("#OUTLINETEX#", props); } } TCP2_Utils.ShaderKeywordToggle("TCP2_OUTLINE_CONST_SIZE", "Constant Size Outline", "If enabled, outline will have a constant size independently from camera distance", keywordsList, ref updateKeywords); if (TCP2_Utils.ShaderKeywordToggle("TCP2_ZSMOOTH_ON", "Correct Z Artefacts", "Enable the outline z-correction to try to hide artefacts from complex models", keywordsList, ref updateKeywords)) { ShowFilteredProperties("#OUTLINEZ#", props); } //Smoothed Normals ----------------------------------------------------------------------- EditorGUI.indentLevel--; TCP2_GUI.Header("OUTLINE NORMALS", "Defines where to take the vertex normals from to draw the outline.\nChange this when using a smoothed mesh to fill the gaps shown in hard-edged meshes."); EditorGUI.indentLevel++; TCP2_Utils.ShaderKeywordRadio(null, new string[] { "TCP2_NONE", "TCP2_COLORS_AS_NORMALS", "TCP2_TANGENT_AS_NORMALS", "TCP2_UV2_AS_NORMALS" }, new GUIContent[] { new GUIContent("Regular", "Use regular vertex normals"), new GUIContent("Vertex Colors", "Use vertex colors as normals (with smoothed mesh)"), new GUIContent("Tangents", "Use tangents as normals (with smoothed mesh)"), new GUIContent("UV2", "Use second texture coordinates as normals (with smoothed mesh)"), }, keywordsList, ref updateKeywords); EditorGUI.indentLevel--; //Outline Blending ----------------------------------------------------------------------- if (hasOutlineBlending) { MaterialProperty[] blendProps = GetFilteredProperties("#BLEND#", props); if (blendProps.Length != 2) { EditorGUILayout.HelpBox("Couldn't find Blending properties!", MessageType.Error); } else { TCP2_GUI.Header("OUTLINE BLENDING", "BLENDING EXAMPLES:\nAlpha Transparency: SrcAlpha / OneMinusSrcAlpha\nMultiply: DstColor / Zero\nAdd: One / One\nSoft Add: OneMinusDstColor / One"); UnityEngine.Rendering.BlendMode blendSrc = (UnityEngine.Rendering.BlendMode)blendProps[0].floatValue; UnityEngine.Rendering.BlendMode blendDst = (UnityEngine.Rendering.BlendMode)blendProps[1].floatValue; EditorGUI.BeginChangeCheck(); float f = EditorGUIUtility.fieldWidth; float l = EditorGUIUtility.labelWidth; EditorGUIUtility.fieldWidth = 110f; EditorGUIUtility.labelWidth -= Mathf.Abs(f - EditorGUIUtility.fieldWidth); blendSrc = (UnityEngine.Rendering.BlendMode)EditorGUILayout.EnumPopup("Source Factor", blendSrc); blendDst = (UnityEngine.Rendering.BlendMode)EditorGUILayout.EnumPopup("Destination Factor", blendDst); EditorGUIUtility.fieldWidth = f; EditorGUIUtility.labelWidth = l; if (EditorGUI.EndChangeCheck()) { blendProps[0].floatValue = (float)blendSrc; blendProps[1].floatValue = (float)blendDst; } } } } TCP2_GUI.Separator(); } //LIGHTMAP -------------------------------------------------------------------------------- #if UNITY_4_5 if (CategoryFilter("LIGHTMAP") && !isGeneratedShader) { TCP2_Utils.ShaderKeywordRadio("LIGHTMAP", new string[] { "TCP2_LIGHTMAP_OFF", "TCP2_LIGHTMAP" }, new GUIContent[] { new GUIContent("Unity", "Use Unity's built-in lightmap decoding"), new GUIContent("Toony Colors Pro 2", "Use TCP2's lightmap decoding (lightmaps will be affected by ramp and color settings)") }, keywordsList, ref updateKeywords); } #endif //TRANSPARENCY -------------------------------------------------------------------------------- if (CategoryFilter("ALPHA", "CUTOUT") && isGeneratedShader) { bool alpha = false; bool cutout = false; if (isGeneratedShader) { TCP2_GUI.Header("TRANSPARENCY"); alpha = HasFlags("ALPHA"); cutout = HasFlags("CUTOUT"); } if (alpha) { MaterialProperty[] blendProps = GetFilteredProperties("#ALPHA#", props); if (blendProps.Length != 2) { EditorGUILayout.HelpBox("Couldn't find Blending properties!", MessageType.Error); } else { TCP2_GUI.Header("BLENDING", "BLENDING EXAMPLES:\nAlpha Transparency: SrcAlpha / OneMinusSrcAlpha\nMultiply: DstColor / Zero\nAdd: One / One\nSoft Add: OneMinusDstColor / One"); UnityEngine.Rendering.BlendMode blendSrc = (UnityEngine.Rendering.BlendMode)blendProps[0].floatValue; UnityEngine.Rendering.BlendMode blendDst = (UnityEngine.Rendering.BlendMode)blendProps[1].floatValue; EditorGUI.BeginChangeCheck(); float f = EditorGUIUtility.fieldWidth; float l = EditorGUIUtility.labelWidth; EditorGUIUtility.fieldWidth = 110f; EditorGUIUtility.labelWidth -= Mathf.Abs(f - EditorGUIUtility.fieldWidth); blendSrc = (UnityEngine.Rendering.BlendMode)EditorGUILayout.EnumPopup("Source Factor", blendSrc); blendDst = (UnityEngine.Rendering.BlendMode)EditorGUILayout.EnumPopup("Destination Factor", blendDst); EditorGUIUtility.fieldWidth = f; EditorGUIUtility.labelWidth = l; if (EditorGUI.EndChangeCheck()) { blendProps[0].floatValue = (float)blendSrc; blendProps[1].floatValue = (float)blendDst; } } } if (cutout) { ShowFilteredProperties("#CUTOUT#", props); } } #if DEBUG_INFO //-------------------------------------------------------------------------------------- //DEBUG -------------------------------------------------------------------------------- TCP2_GUI.SeparatorBig(); TCP2_GUI.Header("DEBUG"); //Clear Keywords if (GUILayout.Button("Clear Keywords", EditorStyles.miniButton)) { keywordsList.Clear(); updateKeywords = true; } //Shader Flags GUILayout.Label("Features", EditorStyles.boldLabel); string features = ""; if (mShaderFeatures != null) { foreach (string flag in mShaderFeatures) { features += flag + ", "; } } if (features.Length > 0) { features = features.Substring(0, features.Length - 2); } GUILayout.Label(features, EditorStyles.wordWrappedMiniLabel); //Shader Keywords GUILayout.Label("Keywords", EditorStyles.boldLabel); string keywords = ""; foreach (string keyword in keywordsList) { keywords += keyword + ", "; } if (keywords.Length > 0) { keywords = keywords.Substring(0, keywords.Length - 2); } GUILayout.Label(keywords, EditorStyles.wordWrappedMiniLabel); #endif //-------------------------------------------------------------------------------------- if (EditorGUI.EndChangeCheck()) { materialEditor.PropertiesChanged(); } } //Update Keywords if (updateKeywords) { if (materialEditor.targets != null && materialEditor.targets.Length > 0) { foreach (Object t in materialEditor.targets) { (t as Material).shaderKeywords = keywordsList.ToArray(); EditorUtility.SetDirty(t); } } else { targetMaterial.shaderKeywords = keywordsList.ToArray(); EditorUtility.SetDirty(targetMaterial); } } //Update Variant if (updateVariant && !isGeneratedShader) { string baseName = isMobileShader ? BASE_SHADER_NAME_MOB : BASE_SHADER_NAME; string newShader = baseName; for (int i = 0; i < ShaderVariants.Count; i++) { if (ShaderVariantsEnabled[i]) { newShader += " " + ShaderVariants[i]; } } newShader = newShader.TrimEnd(); //If variant shader string basePath = BASE_SHADER_PATH; if (newShader != baseName) { basePath = VARIANT_SHADER_PATH; } Shader shader = Shader.Find(basePath + newShader); if (shader != null) { materialEditor.SetShader(shader, false); mJustChangedShader = true; } else { if (Event.current.type != EventType.Layout) { mVariantError = "Can't find shader variant:\n" + basePath + newShader; } materialEditor.Repaint(); } } else if (!string.IsNullOrEmpty(mVariantError) && Event.current.type != EventType.Layout) { mVariantError = null; materialEditor.Repaint(); } #endif #if UNITY_5_5_OR_NEWER materialEditor.RenderQueueField(); #endif }
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { position.y += 4; position.height -= 4; TCP2_GUI.Separator(position); }
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { TCP2_GUI.HeaderAndHelp(position, this.header, null, this.help); }
static public void HelpBox(Rect position, string message, MessageType msgType) { EditorGUI.LabelField(position, GUIContent.none, new GUIContent(message, TCP2_GUI.GetHelpBoxIcon(msgType)), TCP2_GUI.HelpBoxRichTextStyle); }
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); }
protected override void DrawGUI(Rect position, TCP2_Config config) { TCP2_GUI.Header(label); }
protected override void DrawGUI(Rect position, TCP2_Config config) { //GUIMask(config, this.label, this.tooltip, this.maskKeyword, this.channelKeyword, this.keyword, this.Enabled(config), this.increaseIndent, helpTopic: this.helpTopic, helpIndent: this.helpIndent); var curMask = Array.IndexOf(masks, config.GetKeyword(maskKeyword)); if (curMask < 0) { curMask = 0; } var curChannel = TCP2_Utils.FromShader(config.GetKeyword(channelKeyword)); var uvKey = (curMask > 1 && curMask < 5) ? "UV_" + masks[curMask] : null; var curUv = Array.IndexOf(uvs, config.GetKeyword(uvKey)); if (curUv < 0) { curUv = 0; } EditorGUI.BeginChangeCheck(); //Calculate rects var helpButton = position; helpButton.width = 16f; helpButton.x += 2f; position.width -= helpButton.width; helpButton.x += position.width; //Mask type (MainTex, 1, 2, 3) var sideRect = position; sideRect.width = position.width * 0.75f / 2f; curMask = EditorGUI.Popup(sideRect, curMask, labels); //Mask Channel (RGBA) var middleRect = position; middleRect.width = position.width * 0.25f; middleRect.x += sideRect.width; GUI.enabled &= curMask > 0; curChannel = (TCP2_Utils.TextureChannel)EditorGUI.EnumPopup(middleRect, curChannel); //Mask UVs sideRect.x += sideRect.width + middleRect.width; GUI.enabled &= curMask > 1 && curMask < 5; curUv = EditorGUI.Popup(sideRect, curUv, uvs); //Mask Help TCP2_GUI.HelpButton(helpButton, "Masks"); if (EditorGUI.EndChangeCheck()) { config.SetKeyword(maskKeyword, masks[curMask]); if (curMask > 0) { config.SetKeyword(channelKeyword, curChannel.ToShader()); } if (curMask > 1 && !string.IsNullOrEmpty(uvKey)) { config.SetKeyword(uvKey, uvs[curUv]); } config.ToggleFeature("VCOLORS_MASK", (curMask == 5)); config.ToggleFeature(keyword, (curMask > 0)); } }
public void DrawGUI(TCP2_Config config) { var enabled = Enabled(config); GUI.enabled = enabled; var visible = (sHideDisabled && increaseIndent) ? enabled : true; if (inline) { visible = LastVisible; } visible &= (FoldoutStack.Count > 0) ? FoldoutStack.Peek() : true; ForceValue(config); if (customGUI) { if (visible || ignoreVisibility) { DrawGUI(new Rect(0, 0, EditorGUIUtility.currentViewWidth, 0), config); return; } } else if (visible) { //Total line rect Rect position; position = inline ? LastPosition : EditorGUILayout.GetControlRect(); if (halfWidth) { position.width = (position.width / 2f) - 8f; } //LastPosition is already halved if (inline) { position.x += position.width + 16f; } //Last Position for inlined properties LastPosition = position; if (!inline) { //Help if (showHelp) { var helpRect = HeaderRect(ref position, 20f); TCP2_GUI.HelpButton(helpRect, label, string.IsNullOrEmpty(helpTopic) ? label : helpTopic); } else { HeaderRect(ref position, 20f); } //Indent if (increaseIndent) { HeaderRect(ref position, 6f); } } //Label var guiContent = TempContent((increaseIndent ? "▪ " : "") + label, tooltip); var labelPosition = HeaderRect(ref position, inline ? (EditorStyles.label.CalcSize(guiContent)).x + 8f : LABEL_WIDTH - position.x); TCP2_GUI.SubHeader(labelPosition, guiContent, Highlighted(config) && Enabled(config)); //Actual property DrawGUI(position, config); LastVisible = visible; } GUI.enabled = sGUIEnabled; }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { if (InspectorNeedsUpdate) { //reset properties blendMode = null; albedoMap = null; albedoColor = null; alphaCutoff = null; specularMap = null; specularColor = null; metallicMap = null; metallic = null; smoothness = null; smoothnessScale = null; //smoothnessMapChannel = null; bumpScale = null; bumpMap = null; occlusionStrength = null; occlusionMap = null; heigtMapScale = null; heightMap = null; emissionColorForRendering = null; emissionMap = null; detailMask = null; detailAlbedoMap = null; detailNormalMapScale = null; detailNormalMap = null; //uvSetSecondary = null; } FindProperties(props); // MaterialProperties can be animated so we do not cache them but fetch them every event to ensure animated values are updated correctly m_MaterialEditor = materialEditor; var material = materialEditor.target as Material; // Make sure that needed setup (ie keywords/renderqueue) are set up if we're switching some existing // material to a standard shader. // Do this before any GUI code has been issued to prevent layout issues in subsequent GUILayout statements (case 780071) if (m_FirstTimeApply || InspectorNeedsUpdate) { MaterialChanged(material, m_WorkflowMode); m_FirstTimeApply = false; InspectorNeedsUpdate = false; } //TCP2 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.CogIcon, "O", "Open in Shader Generator")) { if (material.shader != null) { TCP2_ShaderGenerator.OpenWithShader(material.shader); } } EditorGUILayout.EndHorizontal(); TCP2_GUI.Separator(); ShaderPropertiesGUI(material); #if UNITY_5_5_OR_NEWER materialEditor.RenderQueueField(); #endif #if UNITY_5_6_OR_NEWER materialEditor.EnableInstancingField(); #endif }
static private void Space() { TCP2_GUI.GUILine(new Color(0.65f, 0.65f, 0.65f), 1); GUILayout.Space(1); }
void OnGUI() { sGUIEnabled = GUI.enabled; EditorGUILayout.BeginHorizontal(); TCP2_GUI.HeaderBig("TOONY COLORS PRO 2 - SHADER GENERATOR"); TCP2_GUI.HelpButton("Shader Generator"); EditorGUILayout.EndHorizontal(); TCP2_GUI.Separator(); var lW = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 105f; //Avoid refreshing Template meta at every Repaint EditorGUILayout.BeginHorizontal(); var _tmpTemplate = EditorGUILayout.ObjectField("Template:", Template.textAsset, typeof(TextAsset), false) as TextAsset; if (_tmpTemplate != Template.textAsset) { Template.SetTextAsset(_tmpTemplate); } //Load template if (loadTemplateMenu != null) { if (GUILayout.Button("Load ▼", EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { loadTemplateMenu.ShowAsContext(); } } /* * if(GUILayout.Button("Reload", EditorStyles.miniButton, GUILayout.ExpandWidth(false))) * { * Template.Reload(); * } */ EditorGUILayout.EndHorizontal(); //Template not found if (Template == null || Template.textAsset == null) { EditorGUILayout.HelpBox("Couldn't find template file!\n\nVerify that the file 'TCP2_ShaderTemplate_Default.txt' is in your project.\nPlease reimport the pack if you can't find it!", MessageType.Error); return; } //Infobox for custom templates if (!string.IsNullOrEmpty(Template.templateInfo)) { TCP2_GUI.HelpBoxLayout(Template.templateInfo, MessageType.Info); } if (!string.IsNullOrEmpty(Template.templateWarning)) { TCP2_GUI.HelpBoxLayout(Template.templateWarning, MessageType.Warning); } TCP2_GUI.Separator(); //If current shader is unsaved, show yellow color var gColor = GUI.color; GUI.color = mDirtyConfig ? gColor * unsavedChangesColor : GUI.color; EditorGUI.BeginChangeCheck(); mCurrentShader = EditorGUILayout.ObjectField("Current Shader:", mCurrentShader, typeof(Shader), false) as Shader; if (EditorGUI.EndChangeCheck()) { if (mCurrentShader != null) { LoadCurrentConfigFromShader(mCurrentShader); } } EditorGUILayout.BeginHorizontal(); GUILayout.Space(EditorGUIUtility.labelWidth + 4); if (mDirtyConfig) { var guiContent = new GUIContent("Unsaved changes"); var rect = GUILayoutUtility.GetRect(guiContent, EditorStyles.helpBox, GUILayout.Height(16)); rect.y -= 2; GUI.Label(rect, guiContent, EditorStyles.helpBox); } GUILayout.FlexibleSpace(); using (new EditorGUI.DisabledScope(mCurrentShader == null)) { if (GUILayout.Button("Copy", EditorStyles.miniButtonLeft, GUILayout.Width(60f), GUILayout.Height(16))) { CopyShader(); } } if (GUILayout.Button("Load ▼", EditorStyles.miniButtonMid, GUILayout.Width(60f), GUILayout.Height(16))) { loadShadersMenu.ShowAsContext(); } if (GUILayout.Button("New", EditorStyles.miniButtonRight, GUILayout.Width(60f), GUILayout.Height(16))) { NewShader(); } GUILayout.Space(18); //leave space to align with the Object Field box EditorGUILayout.EndHorizontal(); GUI.color = gColor; if (mCurrentConfig == null) { NewShader(); } if (mCurrentConfig.isModifiedExternally) { EditorGUILayout.HelpBox("It looks like this shader has been modified externally/manually. Updating it will overwrite the changes.", MessageType.Warning); } EditorGUIUtility.labelWidth = lW; //Name & Filename TCP2_GUI.Separator(); GUI.enabled = (mCurrentShader == null); EditorGUI.BeginChangeCheck(); mCurrentConfig.ShaderName = EditorGUILayout.TextField(new GUIContent("Shader Name", "Path will indicate how to find the Shader in Unity's drop-down list"), mCurrentConfig.ShaderName); mCurrentConfig.ShaderName = Regex.Replace(mCurrentConfig.ShaderName, @"[^a-zA-Z0-9 _!/]", ""); if (EditorGUI.EndChangeCheck() && sAutoNames) { mCurrentConfig.AutoNames(); } GUI.enabled &= !sAutoNames; EditorGUILayout.BeginHorizontal(); mCurrentConfig.Filename = EditorGUILayout.TextField("File Name", mCurrentConfig.Filename); mCurrentConfig.Filename = Regex.Replace(mCurrentConfig.Filename, @"[^a-zA-Z0-9 _!/]", ""); GUILayout.Label(".shader", GUILayout.Width(50f)); EditorGUILayout.EndHorizontal(); GUI.enabled = sGUIEnabled; TCP2_GUI.Separator(); //######################################################################################################## // FEATURES TCP2_GUI.Header("FEATURES"); //Scroll view mScrollPosition = EditorGUILayout.BeginScrollView(mScrollPosition); EditorGUI.BeginChangeCheck(); if (Template.newSystem) { //New UI embedded into Template Template.FeaturesGUI(mCurrentConfig); if (mFirstHashPass) { mCurrentHash = mCurrentConfig.ToHash(); mFirstHashPass = false; } } else { EditorGUILayout.HelpBox("Old template versions aren't supported anymore.", MessageType.Warning); } #if DEBUG_MODE TCP2_GUI.SeparatorBig(); TCP2_GUI.SubHeaderGray("DEBUG MODE"); GUILayout.BeginHorizontal(); mDebugText = EditorGUILayout.TextField("Custom", mDebugText); if (GUILayout.Button("Add Feature", EditorStyles.miniButtonLeft, GUILayout.Width(80f))) { mCurrentConfig.Features.Add(mDebugText); } if (GUILayout.Button("Add Flag", EditorStyles.miniButtonRight, GUILayout.Width(80f))) { mCurrentConfig.Flags.Add(mDebugText); } GUILayout.EndHorizontal(); GUILayout.Label("Features:"); GUILayout.BeginHorizontal(); int count = 0; for (int i = 0; i < mCurrentConfig.Features.Count; i++) { if (count >= 3) { count = 0; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } count++; if (GUILayout.Button(mCurrentConfig.Features[i], EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { mCurrentConfig.Features.RemoveAt(i); break; } } GUILayout.EndHorizontal(); GUILayout.Label("Flags:"); GUILayout.BeginHorizontal(); count = 0; for (int i = 0; i < mCurrentConfig.Flags.Count; i++) { if (count >= 3) { count = 0; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } count++; if (GUILayout.Button(mCurrentConfig.Flags[i], EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { mCurrentConfig.Flags.RemoveAt(i); break; } } GUILayout.EndHorizontal(); GUILayout.Label("Keywords:"); GUILayout.BeginHorizontal(); count = 0; foreach (KeyValuePair <string, string> kvp in mCurrentConfig.Keywords) { if (count >= 3) { count = 0; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } count++; if (GUILayout.Button(kvp.Key + ":" + kvp.Value, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { mCurrentConfig.Keywords.Remove(kvp.Key); break; } } GUILayout.EndHorizontal(); //---------------------------------------------------------------- Space(); if (mCurrentShader != null) { if (mCurrentShaderImporter == null) { mCurrentShaderImporter = ShaderImporter.GetAtPath(AssetDatabase.GetAssetPath(mCurrentShader)) as ShaderImporter; } if (mCurrentShaderImporter != null && mCurrentShaderImporter.GetShader() == mCurrentShader) { mDebugExpandUserData = EditorGUILayout.Foldout(mDebugExpandUserData, "Shader UserData"); if (mDebugExpandUserData) { string[] userData = mCurrentShaderImporter.userData.Split(','); foreach (var str in userData) { GUILayout.Label(str); } } } } #endif //Update config if (EditorGUI.EndChangeCheck()) { var newHash = mCurrentConfig.ToHash(); if (newHash != mCurrentHash) { mDirtyConfig = true; } else { mDirtyConfig = false; } } //Scroll view EditorGUILayout.EndScrollView(); Space(); //GENERATE EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUI.color = mDirtyConfig ? gColor * unsavedChangesColor : GUI.color; if (GUILayout.Button(mCurrentShader == null ? "Generate Shader" : "Update Shader", GUILayout.Width(120f), GUILayout.Height(30f))) { if (Template == null) { EditorUtility.DisplayDialog("TCP2 : Shader Generation", "Can't generate shader: no Template file defined!\n\nYou most likely want to link the TCP2_User.txt file to the Template field in the Shader Generator.", "Ok"); return; } //Set config type if (Template.templateType != null) { mCurrentConfig.configType = Template.templateType; } //Set config file mCurrentConfig.templateFile = Template.textAsset.name; var generatedShader = TCP2_ShaderGeneratorUtils.Compile(mCurrentConfig, mCurrentShader, Template, true, !sOverwriteConfigs); ReloadUserShaders(); if (generatedShader != null) { mDirtyConfig = false; LoadCurrentConfigFromShader(generatedShader); } //Workaround to force the inspector to refresh, so that state is reset. //Needed in case of switching between specular/metallic and related //options, while the inspector is opened, so that it shows/hides the //relevant properties according to the changes. TCP2_MaterialInspector_SurfacePBS_SG.InspectorNeedsUpdate = true; } GUI.color = gColor; EditorGUILayout.EndHorizontal(); TCP2_GUI.Separator(); // OPTIONS TCP2_GUI.Header("OPTIONS"); GUILayout.BeginHorizontal(); sSelectGeneratedShader = GUILayout.Toggle(sSelectGeneratedShader, new GUIContent("Select Generated Shader", "Will select the generated file in the Project view"), GUILayout.Width(180f)); sAutoNames = GUILayout.Toggle(sAutoNames, new GUIContent("Automatic Name", "Will automatically generate the shader filename based on its UI name"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); sOverwriteConfigs = GUILayout.Toggle(sOverwriteConfigs, new GUIContent("Always overwrite shaders", "Overwrite shaders when generating/updating (no prompt)"), GUILayout.Width(180f)); sHideDisabled = GUILayout.Toggle(sHideDisabled, new GUIContent("Hide disabled fields", "Hide properties settings when they cannot be accessed"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); TCP2_ShaderGeneratorUtils.CustomOutputDir = GUILayout.Toggle(TCP2_ShaderGeneratorUtils.CustomOutputDir, new GUIContent("Custom Output Directory:", "Will save the generated shaders in a custom directory within the Project"), GUILayout.Width(165f)); GUI.enabled &= TCP2_ShaderGeneratorUtils.CustomOutputDir; if (TCP2_ShaderGeneratorUtils.CustomOutputDir) { TCP2_ShaderGeneratorUtils.OutputPath = EditorGUILayout.TextField("", TCP2_ShaderGeneratorUtils.OutputPath); if (GUILayout.Button("Select...", EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { var outputPath = TCP2_Utils.OpenFolderPanel_ProjectPath("Choose custom output directory for TCP2 generated shaders"); if (!string.IsNullOrEmpty(outputPath)) { TCP2_ShaderGeneratorUtils.OutputPath = outputPath; } } } else { EditorGUILayout.TextField("", TCP2_ShaderGeneratorUtils.OUTPUT_PATH); } if (EditorGUI.EndChangeCheck()) { ReloadUserShaders(); } GUI.enabled = sGUIEnabled; EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); sLoadAllShaders = GUILayout.Toggle(sLoadAllShaders, new GUIContent("Reload Shaders from all Project", "Load shaders from all your Project folders instead of just Toony Colors Pro 2.\nEnable it if you move your generated shader files outside of the default TCP2 Generated folder."), GUILayout.ExpandWidth(false)); if (EditorGUI.EndChangeCheck()) { ReloadUserShaders(); } TCP2_ShaderGeneratorUtils.SelectGeneratedShader = sSelectGeneratedShader; }
public static bool Foldout(bool foldout, string label, string tooltip = null, bool highlighted = false) { return(Foldout(foldout, TCP2_GUI.TempContent(label, tooltip), highlighted)); }
void OnGUI() { EditorGUILayout.BeginHorizontal(); TCP2_GUI.HeaderBig(editMode ? "TCP 2 - RAMP EDITOR" : "TCP 2 - RAMP GENERATOR"); TCP2_GUI.HelpButton("Ramp Generator"); EditorGUILayout.EndHorizontal(); TCP2_GUI.Separator(); serializedObject.Update(); if (editMode) { if (!isNewTexture) { var msg = "This will affect <b>all materials</b> that use this texture!" + (editModeFromMaterial ? "\n\nSave as a new texture first if you want to affect this material only." : "\n\nSave as a new texture if you want to keep the original ramp."); EditorGUILayout.LabelField(GUIContent.none, new GUIContent(msg, TCP2_GUI.GetHelpBoxIcon(MessageType.Warning)), TCP2_GUI.HelpBoxRichTextStyle); } var rect = EditorGUILayout.GetControlRect(GUILayout.Height(16f)); var lw = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 50f; var enabled = GUI.enabled; GUI.enabled = false; EditorGUI.ObjectField(rect, "Editing: ", linkedTexture, typeof(Texture2D), false); EditorGUIUtility.labelWidth = lw; GUI.enabled = enabled; } else { /* * EditorGUILayout.BeginHorizontal(); * if (GUILayout.Toggle(tabIndex == 0, "1D RAMP", TCP2_GUI.Tab)) * tabIndex = 0; * if (GUILayout.Toggle(tabIndex == 1, "2D RAMP", TCP2_GUI.Tab)) * tabIndex = 1; * GUILayout.FlexibleSpace(); * EditorGUILayout.EndHorizontal(); * TCP2_GUI.SeparatorSimple(); */ } if (isRamp1d) { GUILayout.Label("Click on the gradient to edit it:"); EditorGUILayout.PropertyField(gradientProperty, GUIContent.none); } else { scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); gradients2dList.DoLayoutList(); EditorGUILayout.EndScrollView(); } if (!editMode) { if (isRamp1d) { textureWidth = EditorGUILayout.IntField("TEXTURE SIZE:", textureWidth); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("64", EditorStyles.miniButtonLeft)) { textureWidth = 64; } if (GUILayout.Button("128", EditorStyles.miniButtonMid)) { textureWidth = 128; } if (GUILayout.Button("256", EditorStyles.miniButtonMid)) { textureWidth = 256; } if (GUILayout.Button("512", EditorStyles.miniButtonMid)) { textureWidth = 512; } if (GUILayout.Button("1024", EditorStyles.miniButtonRight)) { textureWidth = 1024; } EditorGUILayout.EndHorizontal(); } else if (isRamp2d) { GUILayout.BeginHorizontal(); textureWidth = EditorGUILayout.IntField("TEXTURE SIZE:", textureWidth); GUILayout.Label("x"); textureHeight = EditorGUILayout.IntField(GUIContent.none, textureHeight); GUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("64", EditorStyles.miniButtonLeft)) { textureWidth = 64; } if (GUILayout.Button("128", EditorStyles.miniButtonMid)) { textureWidth = 128; } if (GUILayout.Button("256", EditorStyles.miniButtonMid)) { textureWidth = 256; } if (GUILayout.Button("512", EditorStyles.miniButtonMid)) { textureWidth = 512; } if (GUILayout.Button("1024", EditorStyles.miniButtonRight)) { textureWidth = 1024; } GUILayout.Space(8); if (GUILayout.Button("64", EditorStyles.miniButtonLeft)) { textureHeight = 64; } if (GUILayout.Button("128", EditorStyles.miniButtonMid)) { textureHeight = 128; } if (GUILayout.Button("256", EditorStyles.miniButtonMid)) { textureHeight = 256; } if (GUILayout.Button("512", EditorStyles.miniButtonMid)) { textureHeight = 512; } if (GUILayout.Button("1024", EditorStyles.miniButtonRight)) { textureHeight = 1024; } EditorGUILayout.EndHorizontal(); } } if (GUI.changed) { serializedObject.ApplyModifiedProperties(); mGradient.alphaKeys = new[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) }; if (editMode) { textureIsDirty = true; //Update linked texture if (editedTextureIs2d) { GradientManager.SetPixelsFromGradients(linkedTexture, m2dGradients, linkedTexture.width, linkedTexture.height); } else { var pixels = GradientManager.GetPixelsFromGradient(mGradient, linkedTexture.width, linkedTexture.height); linkedTexture.SetPixels(pixels); linkedTexture.Apply(true, false); } } } GUILayout.Space(8f); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (editMode) { if (GUILayout.Button("Discard", GUILayout.Width(90f), GUILayout.Height(20f))) { DiscardEditedTexture(); if (editModeFromMaterial) { Close(); } else { OpenTool(); } } if (GUILayout.Button("Apply", GUILayout.Width(90f), GUILayout.Height(20f))) { SaveEditedTexture(); if (editModeFromMaterial) { Close(); } else { OpenTool(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); } var saveButton = false; EditorGUI.BeginDisabledGroup(isRamp2d && (m2dGradients == null || m2dGradients.Length < 2)); if (editMode) { saveButton = GUILayout.Button("Save as...", EditorStyles.miniButton, GUILayout.Width(120f), GUILayout.Height(16f)); } else { saveButton = GUILayout.Button("GENERATE", GUILayout.Width(120f), GUILayout.Height(34f)); } EditorGUI.EndDisabledGroup(); if (saveButton) { var path = EditorUtility.SaveFilePanel("Save Generated Ramp", GradientManager.LAST_SAVE_PATH, editMode ? linkedTexture.name : "TCP2_CustomRamp", "png"); if (!string.IsNullOrEmpty(path)) { GradientManager.LAST_SAVE_PATH = Path.GetDirectoryName(path); var projectPath = path.Replace(Application.dataPath, "Assets"); GenerateAndSaveTexture(projectPath, isRamp2d); if (editMode) { var newTexture = AssetDatabase.LoadAssetAtPath <Texture2D>(projectPath); if (newTexture != null) { foreach (var mat in linkedMaterials) { mat.SetTexture("_Ramp", newTexture); EditorUtility.SetDirty(mat); } } //Reinitialize edit mode InitEditMode(newTexture, linkedMaterials); } } } EditorGUILayout.EndHorizontal(); if (!editMode) { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Load Texture", EditorStyles.miniButton, GUILayout.Width(120f))) { LoadTexture(); } EditorGUILayout.EndHorizontal(); } }
public static bool Foldout(bool foldout, string label, bool highlighted) { return(Foldout(foldout, TCP2_GUI.TempContent(label), highlighted)); }
static public void HelpBoxLayout(string message, MessageType msgType) { EditorGUILayout.LabelField(GUIContent.none, new GUIContent(message, TCP2_GUI.GetHelpBoxIcon(msgType)), TCP2_GUI.HelpBoxRichTextStyle); }
public static void InlineLabel(string label, string tooltip = null, bool highlight = false) { InlineLabel(TCP2_GUI.TempContent(label, tooltip), highlight); }
public TCP2HelpBoxDecorator(string messageType, string msg) { this.msgType = (MessageType)System.Enum.Parse(typeof(MessageType), messageType); this.message = ParseMessage(msg); this.icon = TCP2_GUI.GetHelpBoxIcon(this.msgType); }
public static void InlineLabel(string label, bool highlight) { InlineLabel(TCP2_GUI.TempContent(label), highlight); }
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { position.y += 2; TCP2_GUI.Header(position, header); }
public static void InlineHeader(string label, string tooltip = null) { InlineHeader(TCP2_GUI.TempContent(label, tooltip)); }
static public bool ShaderKeywordRadio(string header, string[] keywords, GUIContent[] labels, List <string> list, ref bool update) { int index = 0; for (int i = 1; i < keywords.Length; i++) { if (list.Contains(keywords[i])) { index = i; break; } } EditorGUI.BeginChangeCheck(); //Header and rect calculations bool hasHeader = (!string.IsNullOrEmpty(header)); Rect headerRect = GUILayoutUtility.GetRect(120f, 16f, GUILayout.ExpandWidth(false)); Rect r = headerRect; if (hasHeader) { Rect helpRect = headerRect; helpRect.width = 16; headerRect.width -= 16; headerRect.x += 16; string helpTopic = header.ToLowerInvariant(); helpTopic = char.ToUpperInvariant(helpTopic[0]) + helpTopic.Substring(1); TCP2_GUI.HelpButton(helpRect, helpTopic); GUI.Label(headerRect, header, index > 0 ? EditorStyles.boldLabel : EditorStyles.label); r.width = Screen.width - headerRect.width - 34f; r.x += headerRect.width; } else { r.width = Screen.width - 34f; } for (int i = 0; i < keywords.Length; i++) { Rect rI = r; rI.width /= keywords.Length; rI.x += i * rI.width; if (GUI.Toggle(rI, index == i, labels[i], (i == 0) ? EditorStyles.miniButtonLeft : (i == keywords.Length - 1) ? EditorStyles.miniButtonRight : EditorStyles.miniButtonMid)) { index = i; } } if (EditorGUI.EndChangeCheck()) { //Remove all other keywords and add selected for (int i = 0; i < keywords.Length; i++) { if (list.Contains(keywords[i])) { list.Remove(keywords[i]); } } if (index > 0) { list.Add(keywords[index]); } update = true; } return(index > 0); }
void OnGUI() { sGUIEnabled = GUI.enabled; EditorGUILayout.BeginHorizontal(); TCP2_GUI.HeaderBig("TOONY COLORS PRO 2 - SHADER GENERATOR"); TCP2_GUI.HelpButton("Shader Generator"); EditorGUILayout.EndHorizontal(); TCP2_GUI.Separator(); float lW = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 105f; //Avoid refreshing Template meta at every Repaint EditorGUILayout.BeginHorizontal(); TextAsset _tmpTemplate = EditorGUILayout.ObjectField("Template:", Template.textAsset, typeof(TextAsset), false) as TextAsset; if (_tmpTemplate != Template.textAsset) { Template.SetTextAsset(_tmpTemplate); } //Load template if (loadTemplateMenu != null) { if (GUILayout.Button("Load ▼", EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { loadTemplateMenu.ShowAsContext(); } } EditorGUILayout.EndHorizontal(); //Template not found if (Template == null || Template.textAsset == null) { EditorGUILayout.HelpBox("Couldn't find template file!\n\nVerify that the file 'TCP2_ShaderTemplate_Default.txt' is in your project.\nPlease reimport the pack if you can't find it!", MessageType.Error); return; } //Infobox for custom templates if (!string.IsNullOrEmpty(Template.templateInfo)) { EditorGUILayout.HelpBox(Template.templateInfo, MessageType.Info); } if (!string.IsNullOrEmpty(Template.templateWarning)) { EditorGUILayout.HelpBox(Template.templateWarning, MessageType.Warning); } TCP2_GUI.Separator(); EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); mCurrentShader = EditorGUILayout.ObjectField("Current Shader:", mCurrentShader, typeof(Shader), false) as Shader; if (EditorGUI.EndChangeCheck()) { if (mCurrentShader != null) { LoadCurrentConfigFromShader(mCurrentShader); } } if (GUILayout.Button("Copy Shader", EditorStyles.miniButton, GUILayout.Width(78f))) { CopyShader(); } if (GUILayout.Button("New Shader", EditorStyles.miniButton, GUILayout.Width(76f))) { NewShader(); } EditorGUILayout.EndHorizontal(); if (mCurrentConfig.isModifiedExternally) { EditorGUILayout.HelpBox("It looks like this shader has been modified externally/manually. Updating it will overwrite the changes.", MessageType.Warning); } if (mUserShaders != null && mUserShaders.Length > 0) { EditorGUI.BeginChangeCheck(); int prevChoice = mConfigChoice; Color gColor = GUI.color; GUI.color = mDirtyConfig ? gColor * Color.yellow : GUI.color; GUILayout.BeginHorizontal(); mConfigChoice = EditorGUILayout.Popup("Load Shader:", mConfigChoice, mUserShadersLabels.ToArray()); if (GUILayout.Button("◄", EditorStyles.miniButtonLeft, GUILayout.Width(22))) { mConfigChoice--; if (mConfigChoice < 1) { mConfigChoice = mUserShaders.Length; } } if (GUILayout.Button("►", EditorStyles.miniButtonRight, GUILayout.Width(22))) { mConfigChoice++; if (mConfigChoice > mUserShaders.Length) { mConfigChoice = 1; } } GUILayout.EndHorizontal(); GUI.color = gColor; if (EditorGUI.EndChangeCheck() && prevChoice != mConfigChoice) { bool load = true; if (mDirtyConfig) { if (mCurrentShader != null) { load = EditorUtility.DisplayDialog("TCP2 : Shader Generation", "You have unsaved changes for the following shader:\n\n" + mCurrentShader.name + "\n\nDiscard the changes and load a new shader?", "Yes", "No"); } else { load = EditorUtility.DisplayDialog("TCP2 : Shader Generation", "You have unsaved changes.\n\nDiscard the changes and load a new shader?", "Yes", "No"); } } if (load) { //New Shader if (mConfigChoice == 0) { NewShader(); } else { //Load selected Shader Shader selectedShader = mUserShaders[mConfigChoice - 1]; mCurrentShader = selectedShader; LoadCurrentConfigFromShader(mCurrentShader); } } else { //Revert choice mConfigChoice = prevChoice; } } } EditorGUIUtility.labelWidth = lW; if (mCurrentConfig == null) { NewShader(); } //Name & Filename TCP2_GUI.Separator(); GUI.enabled = (mCurrentShader == null); EditorGUI.BeginChangeCheck(); mCurrentConfig.ShaderName = EditorGUILayout.TextField(new GUIContent("Shader Name", "Path will indicate how to find the Shader in Unity's drop-down list"), mCurrentConfig.ShaderName); mCurrentConfig.ShaderName = Regex.Replace(mCurrentConfig.ShaderName, @"[^a-zA-Z0-9 _!/]", ""); if (EditorGUI.EndChangeCheck() && sAutoNames) { mCurrentConfig.AutoNames(); } GUI.enabled &= !sAutoNames; EditorGUILayout.BeginHorizontal(); mCurrentConfig.Filename = EditorGUILayout.TextField("File Name", mCurrentConfig.Filename); mCurrentConfig.Filename = Regex.Replace(mCurrentConfig.Filename, @"[^a-zA-Z0-9 _!/]", ""); GUILayout.Label(".shader", GUILayout.Width(50f)); EditorGUILayout.EndHorizontal(); GUI.enabled = sGUIEnabled; Space(); //######################################################################################################## // FEATURES TCP2_GUI.Header("FEATURES"); //Scroll view mScrollPosition = EditorGUILayout.BeginScrollView(mScrollPosition); EditorGUI.BeginChangeCheck(); if (Template.newSystem) { //New UI embedded into Template Template.FeaturesGUI(mCurrentConfig); } else { EditorGUILayout.HelpBox("Old template versions aren't supported anymore.", MessageType.Warning); } #if DEBUG_MODE TCP2_GUI.SeparatorBig(); TCP2_GUI.SubHeaderGray("DEBUG MODE"); GUILayout.BeginHorizontal(); mDebugText = EditorGUILayout.TextField("Custom", mDebugText); if (GUILayout.Button("Add Feature", EditorStyles.miniButtonLeft, GUILayout.Width(80f))) { mCurrentConfig.Features.Add(mDebugText); } if (GUILayout.Button("Add Flag", EditorStyles.miniButtonRight, GUILayout.Width(80f))) { mCurrentConfig.Flags.Add(mDebugText); } GUILayout.EndHorizontal(); GUILayout.Label("Features:"); GUILayout.BeginHorizontal(); int count = 0; for (int i = 0; i < mCurrentConfig.Features.Count; i++) { if (count >= 3) { count = 0; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } count++; if (GUILayout.Button(mCurrentConfig.Features[i], EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { mCurrentConfig.Features.RemoveAt(i); break; } } GUILayout.EndHorizontal(); GUILayout.Label("Flags:"); GUILayout.BeginHorizontal(); count = 0; for (int i = 0; i < mCurrentConfig.Flags.Count; i++) { if (count >= 3) { count = 0; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } count++; if (GUILayout.Button(mCurrentConfig.Flags[i], EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { mCurrentConfig.Flags.RemoveAt(i); break; } } GUILayout.EndHorizontal(); GUILayout.Label("Keywords:"); GUILayout.BeginHorizontal(); count = 0; foreach (KeyValuePair <string, string> kvp in mCurrentConfig.Keywords) { if (count >= 3) { count = 0; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); } count++; if (GUILayout.Button(kvp.Key + ":" + kvp.Value, EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { mCurrentConfig.Keywords.Remove(kvp.Key); break; } } GUILayout.EndHorizontal(); //---------------------------------------------------------------- Space(); if (mCurrentShader != null) { if (mCurrentShaderImporter == null) { mCurrentShaderImporter = ShaderImporter.GetAtPath(AssetDatabase.GetAssetPath(mCurrentShader)) as ShaderImporter; } if (mCurrentShaderImporter != null && mCurrentShaderImporter.GetShader() == mCurrentShader) { mDebugExpandUserData = EditorGUILayout.Foldout(mDebugExpandUserData, "Shader UserData"); if (mDebugExpandUserData) { string[] userData = mCurrentShaderImporter.userData.Split(','); foreach (var str in userData) { GUILayout.Label(str); } } } } #endif //Update config if (EditorGUI.EndChangeCheck()) { int newHash = mCurrentConfig.ToHash(); if (newHash != mCurrentHash) { mDirtyConfig = true; } else { mDirtyConfig = false; } } //Scroll view EditorGUILayout.EndScrollView(); Space(); //GENERATE EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(mCurrentShader == null ? "Generate Shader" : "Update Shader", GUILayout.Width(120f), GUILayout.Height(30f))) { if (Template == null) { EditorUtility.DisplayDialog("TCP2 : Shader Generation", "Can't generate shader: no Template file defined!\n\nYou most likely want to link the TCP2_User.txt file to the Template field in the Shader Generator.", "Ok"); return; } //Set config type if (Template.templateType != null) { mCurrentConfig.configType = Template.templateType; } //Set config file mCurrentConfig.templateFile = Template.textAsset.name; Shader generatedShader = TCP2_ShaderGeneratorUtils.Compile(mCurrentConfig, mCurrentShader, Template, true, !sOverwriteConfigs); ReloadUserShaders(); if (generatedShader != null) { mDirtyConfig = false; LoadCurrentConfigFromShader(generatedShader); } } EditorGUILayout.EndHorizontal(); TCP2_GUI.Separator(); // OPTIONS TCP2_GUI.Header("OPTIONS"); GUILayout.BeginHorizontal(); sSelectGeneratedShader = GUILayout.Toggle(sSelectGeneratedShader, new GUIContent("Select Generated Shader", "Will select the generated file in the Project view"), GUILayout.Width(180f)); sAutoNames = GUILayout.Toggle(sAutoNames, new GUIContent("Automatic Name", "Will automatically generate the shader filename based on its UI name"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); sOverwriteConfigs = GUILayout.Toggle(sOverwriteConfigs, new GUIContent("Always overwrite shaders", "Overwrite shaders when generating/updating (no prompt)"), GUILayout.Width(180f)); sHideDisabled = GUILayout.Toggle(sHideDisabled, new GUIContent("Hide disabled fields", "Hide properties settings when they cannot be accessed"), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); TCP2_ShaderGeneratorUtils.CustomOutputDir = GUILayout.Toggle(TCP2_ShaderGeneratorUtils.CustomOutputDir, new GUIContent("Custom Output Directory:", "Will save the generated shaders in a custom directory within the Project"), GUILayout.Width(165f)); GUI.enabled &= TCP2_ShaderGeneratorUtils.CustomOutputDir; if (TCP2_ShaderGeneratorUtils.CustomOutputDir) { TCP2_ShaderGeneratorUtils.OutputPath = EditorGUILayout.TextField("", TCP2_ShaderGeneratorUtils.OutputPath); if (GUILayout.Button("Select...", EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { string path = EditorUtility.OpenFolderPanel("Choose custom output directory for TCP2 generated shaders", Application.dataPath, ""); if (!string.IsNullOrEmpty(path)) { bool validPath = TCP2_Utils.SystemToUnityPath(ref path); if (validPath) { if (path == "Assets") { TCP2_ShaderGeneratorUtils.OutputPath = "/"; } else { TCP2_ShaderGeneratorUtils.OutputPath = path.Substring("Assets/".Length); } } else { EditorApplication.Beep(); EditorUtility.DisplayDialog("Invalid Path", "The selected path is invalid.\n\nPlease select a folder inside the \"Assets\" folder of your project!", "Ok"); } } } } else { EditorGUILayout.TextField("", TCP2_ShaderGeneratorUtils.OUTPUT_PATH); } if (EditorGUI.EndChangeCheck()) { ReloadUserShaders(); } GUI.enabled = sGUIEnabled; EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); sLoadAllShaders = GUILayout.Toggle(sLoadAllShaders, new GUIContent("Reload Shaders from all Project", "Load shaders from all your Project folders instead of just Toony Colors Pro 2.\nEnable it if you move your generated shader files outside of the default TCP2 Generated folder."), GUILayout.ExpandWidth(false)); if (EditorGUI.EndChangeCheck()) { ReloadUserShaders(); } TCP2_ShaderGeneratorUtils.SelectGeneratedShader = sSelectGeneratedShader; }
public override void OnInspectorGUI() { if (!this.isVisible) { return; } #if SHOW_DEFAULT_INSPECTOR base.OnInspectorGUI(); return; #else //Detect if Shader has changed if (targetMaterial.shader != mCurrentShader) { mCurrentShader = targetMaterial.shader; } UpdateFeaturesFromShader(); //Get material keywords List <string> keywordsList = new List <string>(targetMaterial.shaderKeywords); bool updateKeywords = false; //Header TCP2_GUI.HeaderBig("TOONY COLORS PRO 2 - Outlines Only"); TCP2_GUI.Separator(); //Iterate Shader properties serializedObject.Update(); SerializedProperty mShader = serializedObject.FindProperty("m_Shader"); if (isVisible && !mShader.hasMultipleDifferentValues && mShader.objectReferenceValue != null) { EditorGUIUtility.labelWidth = TCP2_Utils.ScreenWidthRetina - 120f; EditorGUIUtility.fieldWidth = 64f; EditorGUI.BeginChangeCheck(); MaterialProperty[] props = GetMaterialProperties(this.targets); //UNFILTERED PARAMETERS ============================================================== if (ShowFilteredProperties(null, props, false)) { TCP2_GUI.Separator(); } //FILTERED PARAMETERS ================================================================ //Outline Type --------------------------------------------------------------------------- ShowFilteredProperties("#OUTLINE#", props, false); if (!mShaderModel2) { bool texturedOutline = TCP2_Utils.ShaderKeywordToggle("TCP2_OUTLINE_TEXTURED", "Outline Color from Texture", "If enabled, outline will take an averaged color from the main texture multiplied by Outline Color", keywordsList, ref updateKeywords); if (texturedOutline) { ShowFilteredProperties("#OUTLINETEX#", props); } } TCP2_Utils.ShaderKeywordToggle("TCP2_OUTLINE_CONST_SIZE", "Constant Size Outline", "If enabled, outline will have a constant size independently from camera distance", keywordsList, ref updateKeywords); if (TCP2_Utils.ShaderKeywordToggle("TCP2_ZSMOOTH_ON", "Correct Z Artefacts", "Enable the outline z-correction to try to hide artefacts from complex models", keywordsList, ref updateKeywords)) { ShowFilteredProperties("#OUTLINEZ#", props); } //Smoothed Normals ----------------------------------------------------------------------- TCP2_GUI.Header("OUTLINE NORMALS", "Defines where to take the vertex normals from to draw the outline.\nChange this when using a smoothed mesh to fill the gaps shown in hard-edged meshes."); TCP2_Utils.ShaderKeywordRadio(null, new string[] { "TCP2_NONE", "TCP2_COLORS_AS_NORMALS", "TCP2_TANGENT_AS_NORMALS", "TCP2_UV2_AS_NORMALS" }, new GUIContent[] { new GUIContent("Regular", "Use regular vertex normals"), new GUIContent("Vertex Colors", "Use vertex colors as normals (with smoothed mesh)"), new GUIContent("Tangents", "Use tangents as normals (with smoothed mesh)"), new GUIContent("UV2", "Use second texture coordinates as normals (with smoothed mesh)"), }, keywordsList, ref updateKeywords); //Outline Blending ----------------------------------------------------------------------- if (mIsOutlineBlending) { MaterialProperty[] blendProps = GetFilteredProperties("#BLEND#", props); if (blendProps.Length != 2) { EditorGUILayout.HelpBox("Couldn't find Blending properties!", MessageType.Error); } else { TCP2_GUI.Header("OUTLINE BLENDING", "BLENDING EXAMPLES:\nAlpha Transparency: SrcAlpha / OneMinusSrcAlpha\nMultiply: DstColor / Zero\nAdd: One / One\nSoft Add: OneMinusDstColor / One"); UnityEngine.Rendering.BlendMode blendSrc = (UnityEngine.Rendering.BlendMode)blendProps[0].floatValue; UnityEngine.Rendering.BlendMode blendDst = (UnityEngine.Rendering.BlendMode)blendProps[1].floatValue; EditorGUI.BeginChangeCheck(); float f = EditorGUIUtility.fieldWidth; float l = EditorGUIUtility.labelWidth; EditorGUIUtility.fieldWidth = 110f; EditorGUIUtility.labelWidth -= Mathf.Abs(f - EditorGUIUtility.fieldWidth); blendSrc = (UnityEngine.Rendering.BlendMode)EditorGUILayout.EnumPopup("Source Factor", blendSrc); blendDst = (UnityEngine.Rendering.BlendMode)EditorGUILayout.EnumPopup("Destination Factor", blendDst); EditorGUIUtility.fieldWidth = f; EditorGUIUtility.labelWidth = l; if (EditorGUI.EndChangeCheck()) { blendProps[0].floatValue = (float)blendSrc; blendProps[1].floatValue = (float)blendDst; } } } TCP2_GUI.Separator(); //-------------------------------------------------------------------------------------- if (EditorGUI.EndChangeCheck()) { PropertiesChanged(); } } //Update Keywords if (updateKeywords) { if (targets != null && targets.Length > 0) { foreach (Object t in targets) { (t as Material).shaderKeywords = keywordsList.ToArray(); EditorUtility.SetDirty(t); } } else { targetMaterial.shaderKeywords = keywordsList.ToArray(); EditorUtility.SetDirty(targetMaterial); } } #endif }
public TCP2HelpBoxDecorator(string messageType, string msg) { msgType = (MessageType)Enum.Parse(typeof(MessageType), messageType); message = ParseMessage(msg); icon = TCP2_GUI.GetHelpBoxIcon(msgType); }