Hello Guest

Author Topic: Inline Styling  (Read 204 times)

benj11

  • Newbie
  • *
  • Posts: 5
    • View Profile
Inline Styling
« 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9646
    • View Profile
Re: Inline Styling
« Reply #1 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.

benj11

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Inline Styling
« Reply #2 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.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9646
    • View Profile
Re: Inline Styling
« Reply #3 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.
« Last Edit: June 23, 2017, 12:45:46 AM by unikronsoftware »

benj11

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Inline Styling
« Reply #4 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