Sprite - Icons with text (e.g. emoticons)


it seems that one feature we use from NGUI is missing: To have special markup in the font gets replaced by custom icons. :(

We use this to display things like resource symbols in tooltip flow-text like "This spell costs {G} 100 and will do {FD} 10-15 damage" and {G} gets replaced by a gold coin and {FD} by a symbol for fire damage..

Any ideas how this could be achieved with the upcoming UI?

Can we use custom bitmap font textures where some rarely used unicode characters are replaced by icons?
How would we import and setup these bitmap font textures?

Ciao, Imi.

1 Like

Yeah, that was a really useful feature in NGUI. I hope it will be added.

Can the richtext option be used with the new UI? (Don’t have the beta here ATM, can test it later if nobody is faster ;))

The new UI supports richtext, meaning quad can be used.

1 Like

Just learned about this feature here. Anyone have an example of using the quad tag in richtext? I tried assigning a material for the emoticon on the Text component but it affects the look of my ordinary texts too. Does it work only with bitmap font?


Because of how materials ect work in UI Quad is not supported. We will be addressing the inline image issue in the future.


Is there another way for us to embed images into a paragraph of text?

@ , did anything change on this front since September?

If not, is there any alternative way how to embed images into floating text? Can I control the font atlassing? Or alter the font atlas after creation (and so use this to replace some unused characters with my symbols)? How would you proceed with this feature if you can’t access the unity source and your life depends on it? G (kidding)

Greetings, Imi.

Nope nothing has changed on this front. If your life depended on it you would have to derive from Text yourself and change how the OnFillVBO works. i.e. instead of just taking the verts generated by the TextGenerator you'd manipulate them and insert your icon where appropriate. Or just hide from what's threatening your life :)

“…derive from Text yourself and change how the OnFillVBO works. i.e. instead of just taking the verts generated by the TextGenerator you’d manipulate them and insert your icon where appropriate…”

Interesting… thanks! That doesn’t sound too hard… so use some unused unicode char, find out the generated UIVertex positions for the character and replace them in the list… right?

I assume, that I can set the character width with Font.characterInfo?

BTW… chrm… blush… Is the source code of uGUI available somewhere already? You know… so I don’t feel so guilty when I copy’n’paste the disassembled Text.OnFillVBO? ;). And will the magic cpp-parts be ever available someday? :slight_smile: (e.g. whatever runs behind TextGenerator.Populate_Internal. This smells like another nice place to patch some stuff into)

Another approach: What about hooking into the bitmap font atlas and replacing the sprite there for some characters? Do we have access to the font texture after import? Font.textureRebuildCallback looks promising for a nice place to hook into, but I can’t find a way to grab&modify any generated texture… (haven’t looked that long, tbh…)

Or… I just wait until you guys are finished with the feature and use the richtext until then… :-D. A bit yellow G100 instead of a gold symbol may be sufficient for now…

Greetings, Imi.

Parts of the UI source has been released although Tim is the one doing it and i personally dont know where he’s been putting them (he’s told me i just always forget). A search of the forums might turn up the location

As for the magic cpp-parts i dont think we’ll ever make those available just because they need to be built into the engine dll so there would be no way for a user to patch pieces (at least for now).

you might be able to set Font.characterInfo.size though i dont know if it would work. Worth a shot though.

This one looks suspiciously UI-ish... and the Text.cs contains a the OnFillVBO. ;) Thanks again (and pass my thanks to TomC). Keep up the good work!

And of course, you are right about the C++ code when it comes to patch and recompile. :)

That'd be the one :) I dont know how out of date those are but they are at least a good starting point.

Just as an FYI

1 Like

Going to keep using NGUI until this functionality is implemented into Unity's UI. Hope someone figures out something soon!

Hi, I found that add UIVertex into the list of FillSpriteVBO of Text will draw an image with the font texture but not the sprite.
The UIVertex are obtained using the code in Image.FillSpriteVBO, GenerateSimpleSprite, this one.

Is it because the UIVertex.uv0 is relevant to the altas texture?
How can I make it work? I need help…

Now i found that if you want derive from Text (in UnityEngine.UI) and modify the OnFillVBO method ,the main problem is how to make your icons added to the font texture!!!.

For the dynamic font ,the font texture is generated at runtime .which mean we should APPEND our icons in the same way.

Here , i came up with an idea,use Texture2D.PackTextures() to append the icons and get the Rects then get the UVs. I have't try it out, maybe this will work!!:roll_eyes:

@Tim-C , any updates on this?

Unity 5.1 is out now... Does this work yet?