Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

FancyLabel - Multicolor and Multifont label

Discussion in 'Immediate Mode GUI (IMGUI)' started by Dafu, Mar 16, 2008.

Thread Status:
Not open for further replies.
  1. hound0999

    hound0999

    Joined:
    Jun 30, 2009
    Posts:
    124
    Yes this would be better for static text. I just have just changed mine so it only formats when a new message is received now. Thx.

    Also I updated the zip with the new getting started info.
     
    Last edited: Dec 7, 2011
  2. Alchemyst

    Alchemyst

    Joined:
    Jun 1, 2010
    Posts:
    51
    Nice work guys. Works quite nicely. Too bad the performance is horrible. I know it's the Unity GUI at fault on that one - just really is too bad, because otherwise it's super sweet.
     
  3. Alchemyst

    Alchemyst

    Joined:
    Jun 1, 2010
    Posts:
    51
    Does that help the performance much? What did you do to make this change? I wanted to use this for a chat window, so some kind of "Recalc" method when a new message comes in might be nice. Although, I suspect that won't do much to cut down on the frame rate hits for all the different text objects.
     
  4. jedy

    jedy

    Joined:
    Aug 1, 2010
    Posts:
    579
    I was thinking about an asyncroneous parser in a separate thread. It will parse the files, save them in the form of a static class and then the unity gui will just do the visualization.
     
  5. Stephane.Bessette

    Stephane.Bessette

    Joined:
    Nov 18, 2010
    Posts:
    9
    The performance gained depends on the text to format/parse. Regardless, the text formatting phase should not be performed every time OnGUI is called. Text formatting should only happen when the text to be drawn has changed.

    If you implemented your chat window as a single string then I hope that you only format the new string rather then first appending the new text and then formatting the whole string. As more and more messages come in, the format function would take more and more time.
     
  6. hound0999

    hound0999

    Joined:
    Jun 30, 2009
    Posts:
    124
    Well I don't notice any difference on my computer but i suspect a system with less cores or even a single core cpu may benefit. I like to practice best optimizations. I only parse the new text format when a new chat message is received is all. No it won't help with the frame rates, that is just an issue with unity GUI.
     
  7. Alchemyst

    Alchemyst

    Joined:
    Jun 1, 2010
    Posts:
    51
    Here's to hoping that the new Unity GUI will include this feature natively. It's a pretty basic requirement for game text. Even "complex hover tooltip" windows when hovering over a piece of text have become pretty standard in many games these days. *crosses fingers*
     
  8. jedy

    jedy

    Joined:
    Aug 1, 2010
    Posts:
    579
    I'm going over the FancyLabel code and I'm thinking - the draw method is a bit too much for the OnGUI function.
    All those cases could be pulled off in the initialization and the GUI code could be pushed in an Action ( void delegate with no args ) without any foreaches, cases etc.
    I'm redesigning my GUI system, and I will try to figure out a better and faster way to do this.
     
  9. jedy

    jedy

    Joined:
    Aug 1, 2010
    Posts:
    579
    Okay after some testing, this is what I found out.

    The fastest way to render different styled labels, is to render one label for each style and layer them over each other.

    That will result - one draw call for every style ( font-size, color etc ) and 1 more for each hyperlink. It should work pretty fast,
     

    Attached Files:

    Last edited: Jan 3, 2012
  10. Berenger

    Berenger

    Joined:
    Jul 11, 2012
    Posts:
    78
    Hi !

    This is an awesome code guys ! Here is my humble contribution :

    First, I've splitted FormattedLabel in three partial class, to improve the clarity. They are in the files FormattedLabel.cs, TextFormatter.cs and FormattedHyperlink (all the hyperlinks stuff).

    Now the interesting part. The parsing of the text at each gui loops was the main reason for performance loss, so that's where I did my job. Instead of re-analysing the text, each line is stored into a class FormattedLines.

    Each of them contains a list of Sequence, which are words with the same parameters.

    Finally, each sequences has a list of ICommand. That interface has just an Apply function and is implemented by stuff like BackColor, FontSize, FontColor etc. Here is an example of the FormattedLines seen by the output window after the formatting (each sequences are separated by <||>, and their commands are after the : )

    Not Everything is working, like the hyperlinks, and there might be other surprises.
    The GUI calls are, apparently twice as fast. I used the profiler from the wiki (included in the .rar). The formatting still have all the former code so it's longer. If the community approves, I'll clean it up.

    Tell me what you think !

    Oh, and i also changed the string comparison, according to that article, which says it's faster to use string.Compare than Upper + ==.
     

    Attached Files:

    Last edited: Mar 17, 2012
  11. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I approve!

    Until UT finishes the vapour product called the new UI system, this is the only real alternative, but it's not viable yet.
     
  12. Berenger

    Berenger

    Joined:
    Jul 11, 2012
    Posts:
    78
    Well, it's been a while. I kind of drop it out, because I came to realize it was way more complicated and expensive for my curent needs. However, I just added this to the wiki. If the possibilities are not even close to the FancyLabels stuff, but it is much much simpler.
     
  13. atimes

    atimes

    Joined:
    Feb 13, 2013
    Posts:
    1
    Hello everyone. I downloaded FormattedLabel for a project here at work and made some modifications which I'm adding here.

    Basically I added the ability to apply some existing styling options to the code as well as search for a style other than "Label" when it came to setting color's etc.

    Hope it helps.

    View attachment $FormattedLabel.zip
     
  14. leegod

    leegod

    Joined:
    May 5, 2010
    Posts:
    2,472
    Is this usabel in Android game's UnityGUI?
     
  15. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
Thread Status:
Not open for further replies.