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)); } }
private bool GUIMask(string label, string tooltip, string maskKeyword, string channelKeyword, string feature = null, bool enabled = true, bool increaseIndentLevel = false, bool visible = true, string helpTopic = null) { string[] labelsAndKeywords = new string[] { "Off|", "Main Texture|mainTex", "Mask 1|mask1", "Mask 2|mask2", "Mask 3|mask3" }; if (!enabled) { GUI.enabled = false; } if (increaseIndentLevel) { label = "▪ " + label; } string[] labels = new string[labelsAndKeywords.Length]; string[] masks = new string[labelsAndKeywords.Length]; string[] uvs = new string[] { "Main Tex UV", "Independent UV" }; for (int i = 0; i < labelsAndKeywords.Length; i++) { string[] data = labelsAndKeywords[i].Split('|'); labels[i] = data[0]; masks[i] = data[1]; } int curMask = System.Array.IndexOf(masks, TCP2_ShaderGeneratorUtils.GetKeyword(mCurrentConfig, maskKeyword)); if (curMask < 0) { curMask = 0; } TCP2_Utils.TextureChannel curChannel = TCP2_Utils.FromShader(TCP2_ShaderGeneratorUtils.GetKeyword(mCurrentConfig, channelKeyword)); if (curMask <= 1) { curChannel = TCP2_Utils.TextureChannel.Alpha; } string uvKey = (curMask > 1) ? "UV_" + masks[curMask] : null; int curUv = System.Array.IndexOf(uvs, TCP2_ShaderGeneratorUtils.GetKeyword(mCurrentConfig, uvKey)); if (curUv < 0) { curUv = 0; } if (mHideDisabled) { visible = enabled; } if (visible) { EditorGUILayout.BeginHorizontal(); float w = 166; if (!string.IsNullOrEmpty(helpTopic)) { w -= 20; TCP2_GUI.HelpButton(label.TrimStart('▪', ' '), helpTopic); } TCP2_GUI.SubHeader(label, tooltip, (curMask > 0) && enabled, w); curMask = EditorGUILayout.Popup(curMask, labels); GUI.enabled = curMask > 1; curChannel = (TCP2_Utils.TextureChannel)EditorGUILayout.EnumPopup(curChannel); curUv = EditorGUILayout.Popup(curUv, uvs); GUI.enabled = mGUIEnabled; TCP2_GUI.HelpButton("Masks"); EditorGUILayout.EndHorizontal(); } TCP2_ShaderGeneratorUtils.SetKeyword(mCurrentConfig.Keywords, maskKeyword, masks[curMask]); if (curMask > 0) { TCP2_ShaderGeneratorUtils.SetKeyword(mCurrentConfig.Keywords, channelKeyword, curChannel.ToShader()); } if (curMask > 1 && !string.IsNullOrEmpty(uvKey)) { TCP2_ShaderGeneratorUtils.SetKeyword(mCurrentConfig.Keywords, uvKey, uvs[curUv]); } TCP2_ShaderGeneratorUtils.ToggleSingleFeature(mCurrentConfig.Features, feature, (curMask > 0)); if (!enabled) { GUI.enabled = mGUIEnabled; } return(curMask > 0); }