Author Topic: Tween position animation on panel  (Read 5077 times)

Kafar

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 27
    • View Profile
Tween position animation on panel
« on: August 27, 2015, 02:58:05 PM »
Hi,

I want make a sliding panel with buttons anchored on top-left of the screen.
I created the anchor game object and inside a panel with two buttons.
If I add tween animation position on the buttons these move when I click on it, but if I add tween animation on the panel this not move.
Why? Isn't possible to add tween animation on a panel with buttons inside it and move the panel?

Thanks

-Kafar

Holy Manfred

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 8
  • Posts: 71
    • View Profile
Re: Tween position animation on panel
« Reply #1 on: August 27, 2015, 06:50:48 PM »
Tweening anchored objects doesn't work so well. The anchors are keeping them in place and tweens won't work. You can however tween any children of your anchored objects. So I think you could have a widget for your button anchored at the correct palce and then add the button as a child and tween it this way.

Kafar

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: Tween position animation on panel
« Reply #2 on: August 28, 2015, 12:56:11 AM »
Thanks for reply.

Yes but in this mode I have a button animation for each button.
I need to touch the screen and all sliding buttons show, then I think need to use a tween animation on a ngui game object who contains all buttons. But which and how?

-Kafar

Holy Manfred

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 8
  • Posts: 71
    • View Profile
Re: Tween position animation on panel
« Reply #3 on: August 28, 2015, 05:01:27 PM »
I might misunderstand what you are trying to achieve, but as long as you anchor everything correctly and don't tween anchored widgets it should work.
And if you want to animate multiple buttons with one tween you have something like this:
+UIRoot
++UIWidget (anchored anywhere)
+++UIWidget (this has the tween)
++++UIButton
++++UIButton
++++UIButton
++++...


Kafar

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: Tween position animation on panel
« Reply #4 on: August 29, 2015, 04:12:09 AM »
YES!

It's exactly what I done, and it run perfectly.

Now I trying to rotate the UIroot in according with the device orientation, but with poor result.
Do you have any suggest about this?

Thanks!

Holy Manfred

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 8
  • Posts: 71
    • View Profile
Re: Tween position animation on panel
« Reply #5 on: August 29, 2015, 11:50:19 AM »
I have never tried to rotate the UIRoot and I don't think you really need to anyway and the anchors should take care of things.
Then again, I don't know what you are trying to achieve exactly. It depends a lot on the settings in your UIRoot, the aspect ratios and what you want your screen to do when the device is rotated, etc.

Kafar

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: Tween position animation on panel
« Reply #6 on: August 30, 2015, 09:57:31 AM »
That I need is to rotate each GUI buttons on his axis when the device orientation change.

I found two threads on web about this argument but using these the GUI button rotate but not stop when the device is oriented (Eg; Device oriented in Landscape, the button rotate on his axis continuosly, if the device change orientation in Portrait the button continue to rotate in the previous rotation and not stop.)

So, can how modify this code to change the rotation and stop when the orientation is reached?

Thanks, below the code.

void OnGUI() {
 if (Input.deviceOrientation == DeviceOrientation.LandscapeLeft) {
    rotAngle += 45; }
 if (Input.deviceOrientation == DeviceOrientation.LandscapeRight) {
 rotAngle -= 45; }

 //rotAngle++;
         Rect guiRect = new Rect(Screen.width / 2.0f, Screen.height / 2.0f, 128.0f, 128.0f);
         float xValue = ((guiRect.x + guiRect.width / 2.0f));
         float yValue = ((guiRect.y + guiRect.height / 2.0f));
         Vector2 Pivot = new Vector2(xValue, yValue);
         GUIUtility.RotateAroundPivot(rotAngle, Pivot);
         GUI.Button(guiRect, "Test button");
         GUI.matrix = Matrix4x4.identity;
     }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tween position animation on panel
« Reply #7 on: August 30, 2015, 03:34:58 PM »
There is absolutely no need to rotate the GUI. Ever. When the device's orientation changes, all that happens on Unity's side is the width and height get flipped. So if it was 1920x1080 before, it becomes 1080x1920 after. Anchored objects automatically adjust to this change.

Kafar

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 27
    • View Profile
Re: Tween position animation on panel
« Reply #8 on: August 30, 2015, 04:30:19 PM »
Ok, but in my case I work with vuforia and I can't  set the auto rotation in unity to avoid issues with the AR camera, then I can't rotate the cam but I must rotate the ngui buttons when the device physically change orientation.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tween position animation on panel
« Reply #9 on: September 06, 2015, 04:45:49 PM »
NGUI is designed to work with Unity, not Vuforia, so I can't suggest much. Anchoring won't work if you rotate it 90 degrees.