Search Unity

UI.Image.ImageType=Filled for other UI elements

Discussion in '2D' started by lemus01, Aug 30, 2015.

  1. lemus01

    lemus01

    Joined:
    Feb 3, 2015
    Posts:
    9
    Hello,
    Bacially i would like to ask if its possible/if anyone tried to do something like this:
    filled.jpg

    Because for Image, to display only some slice of it, its very easy, just by setting few properties.
    I would like to achieve similar effect for UI.Text. So it follows changes done to Image.

    I am aware that to achieve this its required to go deep into source code of UI. But did anyone tried to manipulate Text mesh to achieve similar goal?

    Thanks!
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Have you tried using a UI mask?
     
  3. lemus01

    lemus01

    Joined:
    Feb 3, 2015
    Posts:
    9
    Hi Karl,
    No i didn't try UI.Mask. Thought its only for UI.Image. But will try. Thanks!
    By the way, is there any reason why max size of font is 300?
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Attached is an example of what you need.
    Not sure about the 300 limit, I will poke the UI team for an answer. The larger the font size the more space used on the generated font atlas so it could be a limit there.
     

    Attached Files:

  5. lemus01

    lemus01

    Joined:
    Feb 3, 2015
    Posts:
    9
    Thank you so much for the sample. It does exactly what I tried to achieve.
    About max size of font, I was just wondering if I can create one or several letters as "background". So the letter will fulfill the "height" space. I know that I can use UI.Image for that, but for mobile deployment I would have to have several backgrouds with different resolutions. To make it work on phone and tablet. Or one "retina resolution" which will be scaled down on other devices.
    And as font is vector stuff, because it resizes very well regardless resolution, I thought I will be able to do that without any raster graphics.
     
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    I am not sure I follow. Fonts are not vector, they are generated onto a texture atlas, the larger the font size the more space a font will take on the atlas. Can you not use the scale to change your fonts?
    Use a high font size for all and just scale the text down/up to your desired size.
     
  7. lemus01

    lemus01

    Joined:
    Feb 3, 2015
    Posts:
    9
    Ok. I thought it works in little different way. Because no matter what resolution your device have, or 320x240 or 1920x1080, fonts are always clear, with smooth edges, just like vector graphics is. There is no artifacts like there is when you are scalling up raster graphics.
    But I see your point. Because when I set fontSize to be 300 and then start to scale text up RectTransform Scale it behaves more like raster. Its more blurry on edges and small artifacts are there.
    b.png

    On the left side, b character with font size 300 and on the right side the same b, but with Scale factor 2.5

    Ideally i would like to have "right b" with the quality of "left b". But if I understand, its not possible. Thanks.
     
  8. lemus01

    lemus01

    Joined:
    Feb 3, 2015
    Posts:
    9
    Hi once again,
    I would like to return to my initial question about UI Mask. I wasn't playing with Unity3D for a while but now I have installed version 5.3.4p4 and I have noticed strange thing. When I create a UI mask and "maskable child" like in the sample code from karl.jones, it works only when none of my objects (mask and maskable child) have set Material. Is that correct? I mean isn't this possible bug?

    Thanks.
     
  9. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    The masking is done by the UI shader. If you use a different shader it needs to support making. Either use the default ui one or download the built in shaders and try and copy over the masking code into your own shader.