Author Topic: TweenPosition and Anchors  (Read 3179 times)

halsafar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
TweenPosition and Anchors
« on: May 08, 2014, 07:41:49 PM »
I googled around and read the forums, from what I gather this is both possible and impossible.  I think older versions of NGUI anchors + tween was impossible, newer versions it appears possible.

So I have a setup like this, basically a big container for buttons.

UIRoot
-Camera
--Panel
---ContainerMain
----ContainerButton
-----Texture

ContainerMain is anchored to Panel.
ContainerButton in anchored to container main.

I have two TweenPositions set on ContainerMain, one to slide it in and one to slide it out.  I fire the tween in script.

This is where it breaks down.  This breaks resolution independence.  The anchor does its job but the tween seems to work in absolute numbers.
« Last Edit: May 08, 2014, 08:00:00 PM by halsafar »

halsafar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: TweenPosition and Anchors
« Reply #1 on: May 08, 2014, 08:05:26 PM »
Well apparently turning on ScalingStyle: FixedSizedOnMobile on UIRoot fixed most of my problems.

I still notice on Android the tweening breaks the UI but by far less now.  The offsets still are wrong, if I disable tweening then it anchors correctly.

Update:
- okay well with FixedSizeOnMobile enabled NGUI draws a bit offscreen on PC/GameView and draws to far inscreen on mobile.  With FixedSizeOnMobile disabled NGUI is perfect on PC/GameView but fails on all mobile devices (IOS and Android).
« Last Edit: May 08, 2014, 08:30:49 PM by halsafar »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenPosition and Anchors
« Reply #2 on: May 09, 2014, 05:40:59 AM »
Tweens always adjust absolute values. Assuming you anchored to the side you want (for example top-left), then it all should work as you'd expect regardless of whether you have it set to fixed size or not. Just be aware that you shouldn't use "FixedSizeOnMobile" with tweens on anchored objects because it will have a Pixel Perfect look on PC, and Fixed Size while on mobiles. This means different virtual pixel sizes, so there will be a discrepancy in your tweens. Choose either Fixed Size or Pixel Perfect and stick to it, and you won't have issues.

halsafar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: TweenPosition and Anchors
« Reply #3 on: May 11, 2014, 06:53:55 PM »
I still have an issue with this.

So UIRoot is set to FixedSize.

Everything looks beautiful and resizes nicely when I change the game view resolution.  Everything looks great in the unity player.

If I build a PC build, the tweens carry the UIWidgets offscreen to far.

If I build an Android build the tweens carry the UIWidgets inscreen to far.

When the game view is in "Free Aspect" I get the same issue as Android, to far inscreen.

What option might I have checked or really what can I do to resolve this?  This is primarily a mobile app so I not concerned about PC builds but I cannot get it to look good in either.

I think the problem is that whenever Game View resolution updates, sure everything anchors nicely but the tweens fail to update their positions so when the tween plays everything goes to the wrong spot.

« Last Edit: May 11, 2014, 07:04:26 PM by halsafar »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenPosition and Anchors
« Reply #4 on: May 12, 2014, 02:23:49 PM »
UIRoot set to fixed size means the height of the screen is fixed, but the width won't be as that's determined by the aspect ratio. Easiest thing to do is to move your objects farther off-screen so that they would be hidden on all aspect ratios (assuming you are trying to move centered objects off-screen).

halsafar

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: TweenPosition and Anchors
« Reply #5 on: May 13, 2014, 12:06:14 PM »
My goal is to tween a widget which is anchored to the top left of a UIPanel off screen and then back on screen.  So it slides away and slides back when needed. 

There is another widget anchored top right, same deal though.

The tweens just don't seem to work with anchors.  The anchor works regardless of resolution/aspect ratio.  The tween is absolute numbers so as soon as resolution changes the numbers are way off.   I see no apparent solution except to not Tween.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenPosition and Anchors
« Reply #6 on: May 14, 2014, 05:34:03 AM »
Structure your hierarchy like this:

UIWidget (anchored to top right)
- UISprite (or whatever widget you want visible)

Place your tween on the UISprite. This way it will always move by the same local value, and will remain anchored because of the UIWidget above it.