Search Unity

Unity UI Suggestion : add a pixelsperunit factor to UI.image / allow multiple pixels per unit per texture

Discussion in 'UGUI & TextMesh Pro' started by Setsuki, Oct 3, 2018.

  1. Setsuki

    Setsuki

    Joined:
    Aug 21, 2012
    Posts:
    31
    Currently, the Image component uses the sprite's pixels per unit variable in order to determine the sizes when slicing and tiling an image.
    It is currently impossible for a user to have different slicing using only one texture. The only solution I have found was to duplicate the texture file and reimport it, which quickly bloats the texture atlas.

    By copying the Image script, and simply applying a factor to the pixelsPerUnits variable, I have been able to make the slicing manually editable :


    It would be handy to either make the pixelPerUnit variable virtual in order to be overriden, or adding a factor variable.

    You can find the linked feedback ticket here :
    https://feedback.unity3d.com/sugges...sh-allow-multiple-pixels-per-unit-per-texture
     
    aurelien-morel-ubiant likes this.
  2. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    Hello @phil-Unity
    do you think this feature could be useful (cause for us it seems to be a good one) and not too touchy to be accessible by script without create a custom Image component ?
     
  3. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Hasn't seen this thread but i honestly stared at the gif for minutes just mesmerized by the fact we didn't think of this. Personally i think its simple and handy. I will pass it on to get it done (soon (tm)).
     
    Menion-Leah and Ferazel like this.
  4. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    @phil-Unity thanks for the answer ! It's really great to hear that !!
    We will abuse of your kindness by linking you this associated problem in the 2D part (which is maybe a UI trouble we didn't know where to post those 2 topics )

    By soon, do you think it could land into 2018.3 ? (I don't think so but we try)

    The issue/question is in this forum topic : https://forum.unity.com/threads/help-getting-a-sprites-atlas-during-build.576781/

    If you have any hint for this more or less related issue/question ?
     
    Last edited: Nov 7, 2018
    Setsuki likes this.
  5. Setsuki

    Setsuki

    Joined:
    Aug 21, 2012
    Posts:
    31
    Glad this is getting noticed ! The link @aurelien-morel-ubiant is accurate as having multiple ppu for one texture would make the gif above available not only for the Image class, but for every classes using Sprite, which sounds like a more generic solution.
     
  6. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Sorry for the ad, but if you cannot wait for it, you can use Better UI which allows you to do something very similar (and is even a bit more powerful).
     
    Setsuki likes this.
  7. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    So not for 2018.3 for sure as its already in beta and its a "maybe" for 2019.1, depends how fast we could get to it.

    As for the second part i'm not sure off hand, and i think 2D is the better team to answer as technically they own the sprite system.
     
  8. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    it's not the most elegant solution in the world, but you can actually accomplish this by inheriting from the Image class rather than fulling copying it into your own duplicate class.

    first create a public new float pixelsPerUnit to hide the variable from the base class. It so happens that even though this property is not virtual, all of the functions that access it are, so just override all of those functions, and copy paste there contents into your custom Image class so that they use your new pixelsPerUnit variable. There is quite a lot of copy pasting still and it's obviously not ideal, but at least you will still be able to use your custom image class with other UI classes that require Images
     
  9. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    I also would very much like to see this feature. This could save us so many duplicated sprites because the artists want different corner radius on various buttons/backgrounds/etc.
     
  10. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
  11. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Nothing just yet its still in the pipe. I haven't gotten it to behave exactly how i'd like then had to do other things.

    @Setsuki You happen to have the sprite you are using in the example above?
     
  12. VincentPaquinUbiant

    VincentPaquinUbiant

    Joined:
    Nov 6, 2018
    Posts:
    9
    @phil-Unity Yes, but you are going to be disappointed, it is just a circle. I linked the meta file along so you have the sprite import settings with it!
     

    Attached Files:

  13. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Thanks, kind of what i thought but figured just double check with a known asset vs me just pulling some random asset from a bug case.

    Thanks again.
     
  14. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Ok done, look for it likely in 19.2