Author Topic: UI2DSprite  (Read 48197 times)

Benzino07

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 24
    • View Profile
Re: UI2DSprite
« Reply #30 on: February 18, 2015, 04:39:16 AM »
I understand that, however UI2DSprite has a handy checkbox in the inspector called Fixed Aspect Ratio, which seems to maintain the aspect ratio of the sprite after you adjust the size of it. Unless I'm missing something, there doesn't seem to be any easy way to maintain the aspect ratio of a sprite that is not anchored in code (well mFixedAspect does it, but it's hidden by default).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UI2DSprite
« Reply #31 on: February 18, 2015, 05:49:05 PM »
If doing it via code, and setting the width, knowing the desired aspect ratio, calculating height is trivial.

fenixn0909

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1
    • View Profile
Re: UI2DSprite
« Reply #32 on: April 05, 2015, 07:38:51 PM »
Hi,

I'm new for Unity & NGUI, a fast question: how can I change Unity 2D Sprite at runtime?


Thanks,

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UI2DSprite
« Reply #33 on: April 06, 2015, 08:15:53 AM »
UI2DSprite.sprite2D = somethingElse;

enhilljr

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UI2DSprite
« Reply #34 on: September 17, 2015, 06:52:39 PM »
Hello!

We're experiencing a clipping problem with UI2DSprite.

We have a file list viewer created with NGUI that uses a UIPanel/UIScrollView to which we add our own "FileIconTemplate" prefabs (1 per file) at runtime.  Each "FileIconTemplate" contains a couple of UISprite elements to create a nice background, a UILabel that contains the filename text, and a UI2DSprite that contains a graphic thumbnail of the contents of the file.  All of the previously mentioned elements are children of a UISprite with a UIDragScrollView.cs attached to it that serves as the root of the prefab.

When we put enough of our FileIconTemplate items in the ScrollView and scroll up and down (Movement=Vertical), all of the sub-elements of the template get clipped properly except the UI2DSprite elements.  The UI2DSprite elements appear in front of the surrounding UI components (outside the ScrollView) until they are moved completely outside the ScrollView volume and are culled.

Is there some sort of setting, switch or depth value that we might not be setting properly or is boundry clipping not possible with UI2DSprite elements?

We're using Unity 5.1.0f3 and NGUI 3.7.7

Any insight would be greatly appreciated!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UI2DSprite
« Reply #35 on: September 20, 2015, 03:47:02 AM »
Check what material/shader is used by your UI2DSprites. You should be using the Unlit/Transparent Colored shader.

Bradamante3D

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 79
    • View Profile
Re: UI2DSprite
« Reply #36 on: October 22, 2015, 03:09:03 PM »
Is there any benefit of using UI2DSprite over the standard NGUI sprite component? Better performance? Less draw calls? Automated atlas management?

How does using UI2DSprite everywhere work with a dynamic Unity font? I wouldn't require any NGUI atlas at all in this case, right?
#301224014, #301432336, #302399130

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UI2DSprite
« Reply #37 on: October 24, 2015, 04:56:33 AM »
Automatic atlas creation is the only benefit.

Dynamic fonts create a separate set of draw calls, often more than one unless your widget depth is set just-right.

You will get better performance and fewer draw calls by using bitmap fonts and NGUI sprites.

skatola

  • Newbie
  • *
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 31
    • View Profile
Re: UI2DSprite
« Reply #38 on: April 30, 2016, 12:44:58 PM »
Hi!
i found the "fixed aspect" function in the ispector very useful for displaying images, just one question:
There's a way to recalculate the "fixed aspect" after the screen orientation is changed?
Cause fixed aspect work like a charm when i open the image, but if rotate my device obviously is not updated, thank you!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UI2DSprite
« Reply #39 on: May 03, 2016, 01:49:56 PM »
Fixed aspect? You can make the aspect ratio be based on width or height -- is this what you mean? This ratio is based on the sprite and has nothing to do with screen size. If you want it to be based on screen size, you will have to write some code to do that.