Search Unity

Anchor Presets doesn't have an option for keeping aspect

Discussion in 'UGUI & TextMesh Pro' started by UPMediaLab, Aug 23, 2014.

  1. UPMediaLab

    UPMediaLab

    Joined:
    Jul 25, 2014
    Posts:
    1
    Hello, sorry if this topic is already in another question.
    I have been playing around with the beta and I've found incredibly frustrating that you can set to stretch on width and or height but it seems there is no preset or way of having the image to adjust using it's aspect ratio, is there any way of doing this?
     
  2. Caio_Lib

    Caio_Lib

    Joined:
    Mar 4, 2014
    Posts:
    83
    Hi UPMediaLab,
    The Image component has property Preserve Aspect when Simple or Filled Image Type is selected.
     
  3. lasercannon

    lasercannon

    Joined:
    Nov 29, 2012
    Posts:
    80
    Hi there,

    I'm running into this issue too. Although there is indeed a "Preserve Aspect" option on Image components, I often find that I want that functionality built into the RectTransform itself, so that I can size something to the aspect ratio of my liking and then preserve that aspect ratio across all resolutions, but still have the objects scale to the height or width.

    It seems the only way around this currently is writing a script that adjusts the RectTransform's SCALE based on the expected resolution.

    It would also be nice to scale text based on this! (The "Best Fit" parameter on the Text component isn't sufficient, because sometimes I DON'T want it to have a "maxSize" and still don't want it to fill the text box!)

    @ Unity devs, is there any chance of having this feature in the future?
     
    thempus likes this.
  4. lasercannon

    lasercannon

    Joined:
    Nov 29, 2012
    Posts:
    80
    Bump in hopes that @runevision can answer. :) Apologies if this has been answered elsewhere, this was the closest thread I could find!
     
  5. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    We don't have a good way of preserving aspect ratios for RectTransforms at the moment. It's possible to make a script that does it, but it's not currently compatible with the auto-layout system (e.g. layout groups), since it creates a circular dependency between widths and heights, at least if you want to be able to adjust the width based on the height, and not just the height based on the width.
     
  6. [RV]CWolf

    [RV]CWolf

    Joined:
    Jan 24, 2013
    Posts:
    33
    I think 'Keep Aspect Ratio' functionality for RecTransforms would be very useful. If it's possible to look into this, that would be great!
     
  7. lasercannon

    lasercannon

    Joined:
    Nov 29, 2012
    Posts:
    80
    @[RV]CWolf @UPMediaLab @runevision
    If anyone is still wondering about this, I found that the "Reference Resolution" component (which goes on the root canvas object) works for me, and does the same thing that UIRoot did in NGUI. I looked over this somehow when reading the docs!