Exemplo n.º 1
0
        /// <summary>
        /// <para>Draws text at a specified <see cref="Rect"/>.</para>
        /// </summary>
        /// <param name="rect">The <see cref="Rect"/> in which the item is drawn.</param>
        /// <param name="text">The text to draw for the asset icon.</param>
        /// <param name="style">A style used to modify the appearance of a graphic.</param>
        /// <param name="selected">Whether the graphic should be rendered with a selection tint.</param>
        public static void DrawText(Rect rect, string text,
                                    CompiledStyleDefinition style = null, bool selected = false)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            var originalColor = GUI.color;

            var guiStyle = new GUIStyle(EditorStyles.label)
            {
                alignment = TextAnchor.MiddleCenter,
                fontStyle = FontStyle.Bold
            };

            if (style != null)
            {
                bool display;
                rect = style.Filter(rect, out display);

                if (!display)
                {
                    return;
                }

                GUI.color = style.Tint;

                TextStyle.normal.textColor = style.Tint;
                TextStyle.alignment        = style.TextAnchor;

                TextStyle.fontStyle = style.FontStyle;
            }
            else
            {
                GUI.color = Color.black;

                TextStyle.alignment = TextAnchor.MiddleCenter;
                TextStyle.fontStyle = FontStyle.Normal;
            }

            TextStyle.fontSize = Mathf.FloorToInt(rect.height * 0.3f);

            if (selected)
            {
                GUI.color = AssetIconsPreferences.SelectionTint.Value.Apply(GUI.color);
            }

            EditorGUI.LabelField(rect, text, TextStyle);

            GUI.color = originalColor;
        }
Exemplo n.º 2
0
        private static GeneralDrawInfo ApplyGeneralModifiers(Rect rect,
                                                             CompiledStyleDefinition style)
        {
            var info = new GeneralDrawInfo();

            if (style != null)
            {
                info.Position = style.Filter(rect, out info.Display);
                info.Tint     = style.Tint;
            }
            else
            {
                info.Position = rect;
                info.Tint     = Color.white;
                info.Display  = true;
            }

            return(info);
        }