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); }
static public void HelpBoxLayout(string message, MessageType msgType) { EditorGUILayout.LabelField(GUIContent.none, new GUIContent(message, TCP2_GUI.GetHelpBoxIcon(msgType)), TCP2_GUI.HelpBoxRichTextStyle); }
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() { 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 TCP2HelpBoxDecorator(string messageType, string msg) { msgType = (MessageType)Enum.Parse(typeof(MessageType), messageType); message = ParseMessage(msg); icon = TCP2_GUI.GetHelpBoxIcon(msgType); }
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(); if(editMode) { 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; } GUILayout.Label("Click on the gradient to edit it:"); var so = new SerializedObject(this); var sp = so.FindProperty("mGradient"); EditorGUILayout.PropertyField(sp, GUIContent.none); if(!editMode) { 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(); } if (GUI.changed) { so.ApplyModifiedProperties(); mGradient.alphaKeys = new[] { new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 1f) }; if(editMode) { textureEdited = true; //Update linked texture var pixels = TCP2_GradientManager.GetPixelsFromGradient(mGradient, linkedTexture.width); 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; 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)); if(saveButton) { var path = EditorUtility.SaveFilePanel("Save Generated Ramp", TCP2_GradientManager.LAST_SAVE_PATH, editMode ? linkedTexture.name : "TCP2_CustomRamp", "png"); if(!string.IsNullOrEmpty(path)) { TCP2_GradientManager.LAST_SAVE_PATH = Path.GetDirectoryName(path); var projectPath = path.Replace(Application.dataPath, "Assets"); GenerateAndSaveTexture(projectPath); 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(); } }