public override void OnGUI() { if (MaterialInspector_Hybrid.ShowNextProperty) { TCP2_GUI.HelpBoxLayout(message, messageType); } }
protected override void DrawGUI(Rect position, TCP2_Config config) { if (Enabled(config)) { //EditorGUILayout.HelpBox(this.label, msgType); TCP2_GUI.HelpBoxLayout(label, msgType); } }
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 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); } }