Author Topic: [SOLVED] uGUI Image's "Preverse Aspect" Equivalent In NGUI  (Read 4013 times)

yasirkula

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
[SOLVED] uGUI Image's "Preverse Aspect" Equivalent In NGUI
« on: July 23, 2015, 08:19:56 AM »
Hi there,

Due to awful draw call optimization of uGUI, we are replacing the whole system with NGUI. So far, everything works well. But I am simply having one major issue with UI Sprite component.

In uGUI Image component, there is an option called "Preserve Aspect". It simply keeps the aspect ratio of the image without changing its RectTransform. In other words, "Preserve Aspect" does not affect the size or anchors of the component. In NGUI, however, if I select "Based on Width" or "Based on Height", the size of the widget no longer stays the same. I don't want the size to change but the image to fit inside that specific rectangle.

Is it possible to reproduce the "Preserve Aspect" in NGUI?

Many thanks =)
« Last Edit: July 27, 2015, 10:57:27 AM by yasirkula »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: uGUI Image's "Preverse Aspect" Equivalent In NGUI
« Reply #1 on: July 24, 2015, 10:42:41 AM »
There is such a setting on the UIRoot, but not on widgets. Assuming you want to preserve the original region for clicking purposes and such, I recommend using a two widget approach:

UIWidget (invisible widget, ALT+SHIFT+W -- put your collider on it to make it clickable)
- UITexture (anchor it as you need with the aspect ratio you want)

Alternatively you can achieve what you want by writing a script that gives your UITexture some padding to make it the aspect ratio you want.

yasirkula

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: uGUI Image's "Preverse Aspect" Equivalent In NGUI
« Reply #2 on: July 27, 2015, 10:56:35 AM »
Hello again,

I have followed your instructions and it worked perfectly (though I used UI2D Sprite instead of UITexture).

Thank you for the quick response :D