Hello Guest

Author Topic: Using 2dtoolkit UI with native Unity TextMesh  (Read 3949 times)

ghostnova

  • Newbie
  • *
  • Posts: 3
    • View Profile
Using 2dtoolkit UI with native Unity TextMesh
« on: August 27, 2014, 12:46:34 am »
Hello.

I am using 2dtoolkit to build the UI in my game. However, I prefer using the native TextMesh for fonts (so that I don't have to generate the fonts with BMFont).

I was able to make them work with very little coding (just had to write  a small script to make them respect the Sorting Order). So far so good.

The problem I'm having appears when I try to use tk2dUIMask to cover the native TextMesh fonts. tk2dUIMask simply ignores the native TextMesh. I believe the piece of code that hides things is this:
Quote
   if (ThisMeshFilter.sharedMesh == null) {
         Mesh mesh = new Mesh();
         mesh.hideFlags = HideFlags.DontSave;
         ThisMeshFilter.mesh = FillMesh(mesh);
      }
      else {
         FillMesh(ThisMeshFilter.sharedMesh);
      }

However, I'm not sure how to fix it. Any suggestions?

Thank you,
Andrei




unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Using 2dtoolkit UI with native Unity TextMesh
« Reply #1 on: August 27, 2014, 09:49:17 am »
That isn't the code that hides things - its done in a shader. The built in text mesh wont work, but the 3d text mesh will if you assign the correct shader to it, any tk2d shader should work. You'll have to test it out to find the most suitable one.

ghostnova

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Using 2dtoolkit UI with native Unity TextMesh
« Reply #2 on: August 27, 2014, 03:27:52 pm »
Thank you. Adding a tk2d shader worked, and fixed my original problem.
However, now the font is always black.  (It ignores the color i set to it in the textmesh).
If I use the tk2d/Goodies/PackedTextMesh, I can set the color of the text to whatever I want. However, it also means that I need to create a material for each color I want to use in the game which is a bit overkill. Is there a different way? Any ideas?

Andrei
« Last Edit: August 27, 2014, 04:02:16 pm by ghostnova »

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Using 2dtoolkit UI with native Unity TextMesh
« Reply #3 on: August 27, 2014, 05:04:50 pm »
I guess you need a shader that doesn't use the texture color channels, eg. duplicate the blendvertexcolor shader, then replace fixed4 col = tex2D(_MainTex, i.texcoord) * i.color; with fixed4 col = tex2D(_MainTex, i.texcoord).a * i.color;

ghostnova

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Using 2dtoolkit UI with native Unity TextMesh
« Reply #4 on: August 27, 2014, 06:23:58 pm »
Thank you. That solved the problem.