2D Toolkit Forum

2D Toolkit => Support => Topic started by: benj11 on June 20, 2017, 06:27:48 pm

Title: Inline Styling
Post by: benj11 on June 20, 2017, 06:27:48 pm
I'm using a Tk 2d Text Mesh and within the text field I have "Hi, my name is Ben". I'd like to have "Hi, my name is" in black and "Ben" in green. I'm attempting to do that with an inline style, however, can't figure out how to do it. Here's one of my attempts:

Hi, my name is ^cRGBA(255, 0, 0, 0.2) Ben"

I can't find anywhere the correct syntax for it. Hopefully someone can help.
Title: Re: Inline Styling
Post by: unikronsoftware on June 21, 2017, 10:55:47 am
Hi the syntax is shown when you press the little question mark icon in the text mesh inspector. Having said that though - I've just found a bug in Unity 5.6 with this which I'll fix as soon as possible.

In any case, to use this, you need the hex code for the colour
Eg. for red, 100% alpha

^c0F0FBen would switch colour to green
and ^C00FF00FFBen would do the same but with 8 digit hex code instead

You can copy the 8 digit hex code from the unity colour picker.
Title: Re: Inline Styling
Post by: benj11 on June 22, 2017, 05:15:53 pm
Is there anyway to do this in code for now since it doesn't work in the editor? I'm struggling with finding a solution. I tried to combine 2 text meshes but that didn't work.
Title: Re: Inline Styling
Post by: unikronsoftware on June 23, 2017, 12:43:20 am
Having said that though - I've just found a bug in Unity 5.6 with this which I'll fix as soon as possible.
After further investigation this works fine, my repo was corrupt after switching unity versions repeatedly.

Step by step to get something working -
1. Create new scene
2. Create new text mesh (Hierarchy Window > Create > 2D Object > tk2d > Text Mesh. Set the text mesh to use Demo Font
3. Tick "Inline Styling" in the text mesh inspector
4. Paste this in the Text box
Hello ^cF00Fworld

You can set the same string in code, it works in exactly the same way.
Title: Re: Inline Styling
Post by: benj11 on June 25, 2017, 08:24:32 am
ha wow yep, had the same exact problem. Just created some new text and now it's working. It still doesn't work on the previously created text but at least I have a solution now.

Thanks :D