private void DrawBoxAndContent(Rect rect, Event e, GUIContent content, PropertyOptions options, GUIStyle style) { if (options.reference_property != null) { GUI.Box(rect, "", style); DrawIcons(rect, e); DrawButton(rect, options, e, style); Rect togglePropertyRect = new Rect(rect); togglePropertyRect.x -= 11; togglePropertyRect.y += 2; ShaderProperty prop = ThryEditor.currentlyDrawing.propertyDictionary[options.reference_property]; float labelWidth = EditorGUIUtility.labelWidth; float fieldWidth = EditorGUIUtility.fieldWidth; EditorGUIUtility.labelWidth = UnityHelper.CalculateLengthOfText(prop.content.text) + EditorGUI.indentLevel * 15 + 45; EditorGUIUtility.fieldWidth = 20; prop.Draw(new CRect(togglePropertyRect), content); EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; } else { GUI.Box(rect, content, style); DrawIcons(rect, e); DrawButton(rect, options, e, style); } }
private void DrawBoxAndContent(Rect rect, Event e, GUIContent content, PropertyOptions options, GUIStyle style) { if (options.reference_property != null) { GUI.Box(rect, new GUIContent(" " + content.text, content.tooltip), style); DrawIcons(rect, e); DrawButton(rect, options, e, style); Rect togglePropertyRect = new Rect(rect); togglePropertyRect.x += 5; togglePropertyRect.y += 2; togglePropertyRect.height -= 4; togglePropertyRect.width = GUI.skin.font.fontSize * 3; float fieldWidth = EditorGUIUtility.fieldWidth; EditorGUIUtility.fieldWidth = 20; ShaderProperty prop = ShaderEditor.currentlyDrawing.propertyDictionary[options.reference_property]; int xOffset = prop.xOffset; prop.xOffset = 0; prop.Draw(new CRect(togglePropertyRect), new GUIContent(), isInHeader: true); prop.xOffset = xOffset; EditorGUIUtility.fieldWidth = fieldWidth; } else { GUI.Box(rect, content, style); DrawIcons(rect, e); DrawButton(rect, options, e, style); } }
public static void drawSmallTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties) { Rect thumbnailPos = position; thumbnailPos.x += hasFoldoutProperties ? 20 : 0; editor.TexturePropertyMiniThumbnail(thumbnailPos, prop, label.text, (hasFoldoutProperties ? "Click here for extra properties" : "") + (label.tooltip != "" ? " | " : "") + label.tooltip); if (DrawingData.currentTexProperty.reference_property_exists) { ShaderProperty property = ThryEditor.currentlyDrawing.propertyDictionary[DrawingData.currentTexProperty.options.reference_property]; Rect r = position; r.x += EditorGUIUtility.labelWidth - CurrentIndentWidth(); r.width -= EditorGUIUtility.labelWidth - CurrentIndentWidth(); property.Draw(new CRect(r), new GUIContent()); } if (hasFoldoutProperties && DrawingData.currentTexProperty != null) { //draw dropdown triangle thumbnailPos.x += DrawingData.currentTexProperty.xOffset * 15; if (Event.current.type == EventType.Repaint) { EditorStyles.foldout.Draw(thumbnailPos, false, false, DrawingData.currentTexProperty.showFoldoutProperties, false); } if (DrawingData.is_enabled) { //test click and draw scale/offset if (DrawingData.currentTexProperty.showFoldoutProperties) { EditorGUI.indentLevel += 2; if (DrawingData.currentTexProperty.hasScaleOffset) { ThryEditor.currentlyDrawing.editor.TextureScaleOffsetProperty(prop); } PropertyOptions options = DrawingData.currentTexProperty.options; if (options.reference_properties != null) { foreach (string r_property in options.reference_properties) { ShaderProperty property = ThryEditor.currentlyDrawing.propertyDictionary[r_property]; property.Draw(useEditorIndent: true); } } EditorGUI.indentLevel -= 2; } if (ThryEditor.input.MouseClick && position.Contains(Event.current.mousePosition)) { DrawingData.currentTexProperty.showFoldoutProperties = !DrawingData.currentTexProperty.showFoldoutProperties; editor.Repaint(); } } } DrawingData.lastGuiObjectHeaderRect = position; Rect object_rect = new Rect(position); object_rect.height = GUILayoutUtility.GetLastRect().y - object_rect.y + GUILayoutUtility.GetLastRect().height; DrawingData.lastGuiObjectRect = object_rect; }
private void DrawBoxAndContent(Rect rect, Event e, GUIContent content, PropertyOptions options) { if (options.reference_property != null && ShaderEditor.active.propertyDictionary.ContainsKey(options.reference_property)) { GUI.Box(rect, new GUIContent(" " + content.text, content.tooltip), Styles.dropDownHeader); DrawIcons(rect, e); DrawButton(rect, options, e); Rect togglePropertyRect = new Rect(rect); togglePropertyRect.x += 5; togglePropertyRect.y += 2; togglePropertyRect.height -= 4; togglePropertyRect.width = GUI.skin.font.fontSize * 3; float fieldWidth = EditorGUIUtility.fieldWidth; EditorGUIUtility.fieldWidth = 20; ShaderProperty prop = ShaderEditor.active.propertyDictionary[options.reference_property]; int xOffset = prop.xOffset; prop.xOffset = 0; prop.Draw(new CRect(togglePropertyRect), new GUIContent(), isInHeader: true); prop.xOffset = xOffset; EditorGUIUtility.fieldWidth = fieldWidth; } else if (keyword != null) { GUI.Box(rect, " " + content.text, Styles.dropDownHeader); DrawIcons(rect, e); DrawButton(rect, options, e); Rect togglePropertyRect = new Rect(rect); togglePropertyRect.x += 20; togglePropertyRect.width = 20; EditorGUI.BeginChangeCheck(); bool keywordOn = EditorGUI.Toggle(togglePropertyRect, "", ShaderEditor.active.materials[0].IsKeywordEnabled(keyword)); if (EditorGUI.EndChangeCheck()) { MaterialHelper.ToggleKeyword(ShaderEditor.active.materials, keyword, keywordOn); } } else { GUI.Box(rect, content, Styles.dropDownHeader); DrawIcons(rect, e); DrawButton(rect, options, e); } }
public static void drawSmallTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties) { Rect thumbnailPos = position; Rect foloutClickCheck = position; thumbnailPos.x += hasFoldoutProperties ? 20 : 0; editor.TexturePropertyMiniThumbnail(thumbnailPos, prop, label.text, label.tooltip); if (DrawingData.currentTexProperty.reference_property_exists) { ShaderProperty property = ShaderEditor.active.propertyDictionary[DrawingData.currentTexProperty.options.reference_property]; Rect r = position; r.x += EditorGUIUtility.labelWidth - CurrentIndentWidth(); r.width -= EditorGUIUtility.labelWidth - CurrentIndentWidth(); foloutClickCheck.width -= r.width; property.Draw(new CRect(r), new GUIContent()); property.tooltip.ConditionalDraw(r); } if (hasFoldoutProperties && DrawingData.currentTexProperty != null) { //draw dropdown triangle thumbnailPos.x += DrawingData.currentTexProperty.xOffset * 15; //This is an invisible button with zero functionality. But it needs to be here so that the triangle click reacts fast if (GUI.Button(thumbnailPos, "", GUIStyle.none)) { } if (Event.current.type == EventType.Repaint) { EditorStyles.foldout.Draw(thumbnailPos, false, false, DrawingData.currentTexProperty.showFoldoutProperties, false); } if (DrawingData.is_enabled) { //test click and draw scale/offset if (DrawingData.currentTexProperty.showFoldoutProperties) { EditorGUI.indentLevel += 2; if (DrawingData.currentTexProperty.hasScaleOffset) { ShaderEditor.active.editor.TextureScaleOffsetProperty(prop); } PropertyOptions options = DrawingData.currentTexProperty.options; if (options.reference_properties != null) { foreach (string r_property in options.reference_properties) { ShaderProperty property = ShaderEditor.active.propertyDictionary[r_property]; property.Draw(useEditorIndent: true); } } EditorGUI.indentLevel -= 2; } if (ShaderEditor.input.LeftClick_IgnoreUnityUses && foloutClickCheck.Contains(Event.current.mousePosition)) { ShaderEditor.input.Use(); DrawingData.currentTexProperty.showFoldoutProperties = !DrawingData.currentTexProperty.showFoldoutProperties; } } } Rect object_rect = new Rect(position); object_rect.height = GUILayoutUtility.GetLastRect().y - object_rect.y + GUILayoutUtility.GetLastRect().height; DrawingData.lastGuiObjectRect = object_rect; DrawingData.tooltipCheckRect = position; }
public static void drawStylizedBigTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties, bool skip_drag_and_drop_handling = false) { position.x += (EditorGUI.indentLevel) * 15; position.width -= (EditorGUI.indentLevel) * 15; Rect rect = GUILayoutUtility.GetRect(label, Styles.bigTextureStyle); rect.x += (EditorGUI.indentLevel) * 15; rect.width -= (EditorGUI.indentLevel) * 15; Rect border = new Rect(rect); border.position = new Vector2(border.x, border.y - position.height); border.height += position.height; if (DrawingData.currentTexProperty.reference_properties_exist) { border.height += 8; foreach (string r_property in DrawingData.currentTexProperty.options.reference_properties) { border.height += editor.GetPropertyHeight(ShaderEditor.active.propertyDictionary[r_property].materialProperty); } } if (DrawingData.currentTexProperty.reference_property_exists) { border.height += 8; border.height += editor.GetPropertyHeight(ShaderEditor.active.propertyDictionary[DrawingData.currentTexProperty.options.reference_property].materialProperty); } //background //GUI.DrawTexture(border, Styles.rounded_texture, ScaleMode.StretchToFill, true, 0, Styles.COLOR_BACKGROUND_1, 0, 0); Color prevC = GUI.color; GUI.color = Styles.COLOR_BACKGROUND_1; GUI.DrawTexture(border, Styles.rounded_texture, ScaleMode.StretchToFill, true); Rect quad = new Rect(border); quad.width = quad.height / 2; GUI.DrawTextureWithTexCoords(quad, Styles.rounded_texture, new Rect(0, 0, 0.5f, 1), true); quad.x += border.width - quad.width; GUI.DrawTextureWithTexCoords(quad, Styles.rounded_texture, new Rect(0.5f, 0, 0.5f, 1), true); GUI.color = prevC; quad.width = border.height - 4; quad.height = quad.width; quad.x = border.x + border.width - quad.width - 1; quad.y += 2; Rect preview_rect_border = new Rect(position); preview_rect_border.height = rect.height + position.height - 6; preview_rect_border.width = preview_rect_border.height; preview_rect_border.y += 3; preview_rect_border.x += position.width - preview_rect_border.width - 3; Rect preview_rect = new Rect(preview_rect_border); preview_rect.height -= 6; preview_rect.width -= 6; preview_rect.x += 3; preview_rect.y += 3; if (prop.hasMixedValue) { Rect mixedRect = new Rect(preview_rect); mixedRect.y -= 5; mixedRect.x += mixedRect.width / 2 - 4; GUI.Label(mixedRect, "_"); } else if (prop.textureValue != null) { GUI.DrawTexture(preview_rect, prop.textureValue); } GUI.DrawTexture(preview_rect_border, Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 0, Color.grey, 3, 5); //selection button and pinging Rect select_rect = new Rect(preview_rect); select_rect.height = 12; select_rect.y += preview_rect.height - 12; if (Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == texturePickerWindow && texturePickerWindowProperty.name == prop.name) { prop.textureValue = (Texture)EditorGUIUtility.GetObjectPickerObject(); ShaderEditor.Repaint(); } if (Event.current.commandName == "ObjectSelectorClosed" && EditorGUIUtility.GetObjectPickerControlID() == texturePickerWindow) { texturePickerWindow = -1; texturePickerWindowProperty = null; } if (GUI.Button(select_rect, "Select", EditorStyles.miniButton)) { EditorGUIUtility.ShowObjectPicker <Texture>(prop.textureValue, false, "", 0); texturePickerWindow = EditorGUIUtility.GetObjectPickerControlID(); texturePickerWindowProperty = prop; } else if (Event.current.type == EventType.MouseDown && preview_rect.Contains(Event.current.mousePosition)) { EditorGUIUtility.PingObject(prop.textureValue); } if (!skip_drag_and_drop_handling) { if ((ShaderEditor.input.is_drag_drop_event) && preview_rect.Contains(ShaderEditor.input.mouse_position) && DragAndDrop.objectReferences[0] is Texture) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (ShaderEditor.input.is_drop_event) { DragAndDrop.AcceptDrag(); prop.textureValue = (Texture)DragAndDrop.objectReferences[0]; } } } //scale offset rect if (hasFoldoutProperties || DrawingData.currentTexProperty.options.reference_property != null) { EditorGUI.indentLevel += 2; if (DrawingData.currentTexProperty.hasScaleOffset) { Rect scale_offset_rect = new Rect(position); scale_offset_rect.y += 37; scale_offset_rect.width -= 2 + preview_rect.width + 10 + 30; scale_offset_rect.x += 30; editor.TextureScaleOffsetProperty(scale_offset_rect, prop); } float oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 128; PropertyOptions options = DrawingData.currentTexProperty.options; if (options.reference_property != null) { ShaderProperty property = ShaderEditor.active.propertyDictionary[options.reference_property]; property.Draw(useEditorIndent: true); } if (options.reference_properties != null) { foreach (string r_property in options.reference_properties) { ShaderProperty property = ShaderEditor.active.propertyDictionary[r_property]; property.Draw(useEditorIndent: true); } } EditorGUIUtility.labelWidth = oldLabelWidth; EditorGUI.indentLevel -= 2; } Rect label_rect = new Rect(position); label_rect.x += 2; label_rect.y += 2; GUI.Label(label_rect, label); GUILayoutUtility.GetRect(0, 5); DrawingData.lastGuiObjectRect = border; DrawingData.tooltipCheckRect = border; }
public static void SmallTextureProperty(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor, bool hasFoldoutProperties, Action extraFoldoutGUI = null) { Rect thumbnailPos = position; Rect foloutClickCheck = position; Rect tooltipRect = position; thumbnailPos.x += hasFoldoutProperties ? 20 : 0; editor.TexturePropertyMiniThumbnail(thumbnailPos, prop, label.text, label.tooltip); if (DrawingData.CurrentTextureProperty.DoesReferencePropertyExist) { ShaderProperty property = ShaderEditor.Active.PropertyDictionary[DrawingData.CurrentTextureProperty.Options.reference_property]; Rect r = position; r.x += EditorGUIUtility.labelWidth - CurrentIndentWidth(); r.width -= EditorGUIUtility.labelWidth - CurrentIndentWidth(); foloutClickCheck.width -= r.width; property.Draw(new CRect(r), new GUIContent()); property.tooltip.ConditionalDraw(r); } if (hasFoldoutProperties && DrawingData.CurrentTextureProperty != null) { //draw dropdown triangle thumbnailPos.x += DrawingData.CurrentTextureProperty.XOffset * 15; //This is an invisible button with zero functionality. But it needs to be here so that the triangle click reacts fast if (GUI.Button(thumbnailPos, "", GUIStyle.none)) { } if (Event.current.type == EventType.Repaint) { EditorStyles.foldout.Draw(thumbnailPos, false, false, DrawingData.CurrentTextureProperty.showFoldoutProperties, false); } if (DrawingData.IsEnabled) { //sub properties if (DrawingData.CurrentTextureProperty.showFoldoutProperties) { EditorGUI.indentLevel += 2; extraFoldoutGUI?.Invoke(); if (DrawingData.CurrentTextureProperty.hasScaleOffset) { ShaderEditor.Active.Editor.TextureScaleOffsetProperty(prop); tooltipRect.height += GUILayoutUtility.GetLastRect().height; } //In case of locked material end disabled group here to allow editing of sub properties if (ShaderEditor.Active.IsLockedMaterial) { EditorGUI.EndDisabledGroup(); } PropertyOptions options = DrawingData.CurrentTextureProperty.Options; if (options.reference_properties != null) { foreach (string r_property in options.reference_properties) { ShaderProperty property = ShaderEditor.Active.PropertyDictionary[r_property]; property.Draw(useEditorIndent: true); } } //readd disabled group if (ShaderEditor.Active.IsLockedMaterial) { EditorGUI.BeginDisabledGroup(false); } EditorGUI.indentLevel -= 2; } if (ShaderEditor.Input.LeftClick_IgnoreLockedAndUnityUses && foloutClickCheck.Contains(Event.current.mousePosition)) { ShaderEditor.Input.Use(); DrawingData.CurrentTextureProperty.showFoldoutProperties = !DrawingData.CurrentTextureProperty.showFoldoutProperties; } } } Rect object_rect = new Rect(position); object_rect.height = GUILayoutUtility.GetLastRect().y - object_rect.y + GUILayoutUtility.GetLastRect().height; DrawingData.LastGuiObjectRect = object_rect; DrawingData.TooltipCheckRect = tooltipRect; }
//-------------Main Function-------------- public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { if (firstOnGUICall || (reloadNextDraw && Event.current.type == EventType.Layout)) { editorData = new EditorData(); editorData.editor = materialEditor; editorData.gui = this; editorData.textureArrayProperties = new List <ShaderProperty>(); editorData.firstCall = true; } editorData.properties = props; CheckInAnimationRecordMode(); m_RenderersForAnimationMode = MaterialEditor.PrepareMaterialPropertiesForAnimationMode(props, GUI.enabled); UpdateEvents(); //first time call inits if (firstOnGUICall || (reloadNextDraw && Event.current.type == EventType.Layout)) { InitlizeThryUI(); } editorData.shader = editorData.materials[0].shader; currentlyDrawing = editorData; active = this; //sync shader and get preset handler Config config = Config.Get(); if (editorData.materials != null) { Mediator.SetActiveShader(editorData.materials[0].shader); } //TOP Bar //if header is texture, draw it first so other ui elements can be positions below if (shaderHeader != null && shaderHeader.options.texture != null) { shaderHeader.Draw(); } Rect mainHeaderRect = EditorGUILayout.BeginHorizontal(); //draw editor settings button if (GUILayout.Button(new GUIContent("", Styles.settings_icon), EditorStyles.largeLabel, GUILayout.MaxHeight(20), GUILayout.MaxWidth(20))) { Thry.Settings window = Thry.Settings.getInstance(); window.Show(); window.Focus(); } EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); if (GUILayout.Button(Styles.search_icon, EditorStyles.largeLabel, GUILayout.MaxHeight(20))) { show_search_bar = !show_search_bar; } //draw master label text after ui elements, so it can be positioned between shaderHeader?.Draw(new CRect(mainHeaderRect)); //GUILayout.Label("Thryrallo",GUILayout.ExpandWidth(true)); GUILayout.Label("@UI by Thryrallo", Styles.made_by_style, GUILayout.Height(25), GUILayout.MaxWidth(100)); EditorGUILayout.EndHorizontal(); if (show_search_bar) { EditorGUI.BeginChangeCheck(); header_search_term = EditorGUILayout.TextField(header_search_term); if (EditorGUI.EndChangeCheck()) //Cache the search { editorData.searchedShaderParts = GetFilterSearchedParts(header_search_term); } } //Visibility menu if (editorData.show_HeaderHider) { HeaderHider.HeaderHiderGUI(editorData); } //bool isMaterialLocked = editorData.use_ShaderOptimizer && editorData.propertyDictionary["_ShaderOptimizerEnabled"].materialProperty.floatValue == 1; if (editorData.use_ShaderOptimizer) { ShaderOptimizerProperty?.Draw(); } //PROPERTIES if (show_search_bar && !string.IsNullOrWhiteSpace(header_search_term) && editorData.searchedShaderParts != null) { foreach (ShaderProperty part in editorData.searchedShaderParts) { part.Draw(); } } else { foreach (ShaderPart part in mainHeader.parts) { part.Draw(); } } //Render Queue selection if (config.showRenderQueue) { materialEditor.RenderQueueField(); } //footer try { GuiHelper.drawFooters(footer); }catch (Exception ex) { Debug.LogWarning(ex); } if (GUILayout.Button("@UI Made by Thryrallo", Styles.made_by_style)) { Application.OpenURL("https://www.twitter.com/thryrallo"); } EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); Event e = Event.current; bool isUndo = (e.type == EventType.ExecuteCommand || e.type == EventType.ValidateCommand) && e.commandName == "UndoRedoPerformed"; if (reloadNextDraw && Event.current.type == EventType.Layout) { reloadNextDraw = false; } if (isUndo) { reloadNextDraw = true; } //on swap if (on_swap_to_actions != null && swapped_to_shader) { foreach (DefineableAction a in on_swap_to_actions) { a.Perform(); } on_swap_to_actions = null; swapped_to_shader = false; } //test if material has been reset if (wasUsed && e.type == EventType.Repaint) { if (editorData.materials[0].HasProperty("shader_is_using_thry_editor") && editorData.materials[0].GetFloat("shader_is_using_thry_editor") != 69) { reloadNextDraw = true; HandleReset(); wasUsed = true; } } if (e.type == EventType.Used) { wasUsed = true; } if (input.HadMouseDownRepaint) { input.HadMouseDown = false; } input.HadMouseDownRepaint = false; editorData.firstCall = false; materialPropertyDictionary = null; }