Author Topic: Animating UISprite Dimensions in 3.0.x?  (Read 17358 times)

SwabbyNat

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Animating UISprite Dimensions in 3.0.x?
« on: October 03, 2013, 01:46:11 PM »
I'm animating some UI elements in 3.0.1 and i cant for the life of me find out how to animate the dimensions in the UISprite??

Scale i can animate, but the effect is completely different (using a sliced sprite).

Is this possible, if yes, how? If not, when?

Nathaniel Hunter
SuperTales Inc.

Mitch

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #1 on: October 03, 2013, 04:59:34 PM »
I'm animating some UI elements in 3.0.1 and i cant for the life of me find out how to animate the dimensions in the UISprite??

Scale i can animate, but the effect is completely different (using a sliced sprite).

Is this possible, if yes, how? If not, when?

Nathaniel Hunter
SuperTales Inc.

Came here to talk / complain about this as I look into updating to NGUI 3.0.x

My current UI makes extensive use of unity Animation to control the scale of sliced sprites.  This is hard pill to swallow as the only real answer I see at the moment is to use a similar solution to the Animated Alpha script in which I don't get a preview while animating - this was pretty crippling but not unworkable... however not being able to see the SCALE of the thing I'm animating until I run the app... man... This is a big deal breaker for me.   Please advise.

SwabbyNat

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #2 on: October 03, 2013, 05:06:11 PM »
This is also of great concern to my team, as we're on the verge of upgrading to 3.0 to be compliant, but currently the inability to animate dimensions to get the effects we were getting with 2.7 scales is a show stopper (we're doing lots of motion graphics based HUD elements that utilize a TON of hand animated motions).

Reluctantly i'll have to go back to the older version unless Aren or someone else can come to the rescue with a fix/solution.

:-(

Nathaniel Hunter
SuperTales Inc.

Mitch

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #3 on: October 03, 2013, 07:02:45 PM »
I've created a AnimatedDimensions behaviour and a helper editorwindow to convert and preview (while in AnimationMode) AnimationClip assets from m_localScale to AnimatedDimensions width and height properties.

Ugh.

Anyway...  I'm ok for now... but if I ever have to port any of my old more complicated UI's this is going to need a lot of love.

SwabbyNat:  PM me some contact info for Skype or some such if you would; I'd love to talk to you about your requirements to see if I my scripts will help you as well.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #4 on: October 04, 2013, 02:14:24 AM »
TweenWidth, TweenHeight?

Occam's razor, no?

SwabbyNat

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #5 on: October 04, 2013, 09:13:15 AM »
I could tween them, but i'm doing some pretty detailed animation curves and nested stuff (think the interfaces you see in Iron Man's helmet), so tweens would be a nightmare to time/offset/etc. In one animation i have no less than 40-50 keys across 11 objects.

Mitch and I PM'ed and he had a control script that allows for animating the variables, so that works for now as a temp fix.

It would be great to add it to the list of must haves for an upcoming release of 3.0 though so its supported behavior in the core product.

Thanks!

Nathaniel Hunter
SuperTales Inc.

Darkmax

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 93
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #6 on: October 04, 2013, 10:44:17 AM »
I was just wondering this problem, because I have a project on ngui  2.7 where I scale the sprite using an animation file of unity and attach an animation component of unity to play the animation file.

This file was scaling the transform scale that on ngui 2.7 was used to scale the sprite, but on ngui 3.0 this was moved to width and height, and that is good for other things I understand, but not for this case.

I know that I can make this possible this effect with Tween Width and Tween Height, but I was animating other things to like alpha, position and rotation on the animation file and just write one line of code to play this animation, but with ngui 3 i need to add like 4 tweens scripts to the sprite and play all tweens at the same time, and thats ok, but why not have the alternative option of using also animation files of unity?

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #7 on: October 04, 2013, 01:30:01 PM »
The width and height on each widget is exposed, can't you route the animation values into that?

Mitch

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #8 on: October 04, 2013, 03:27:17 PM »
The width and height on each widget is exposed, can't you route the animation values into that?

This is effectively what I did, mirroring the AnimatedAlpha behaviour with AnimatedDimensions.

The properties for widget Width and Height are exposed as Get/Set properties which means they can't be seen by the unity animation editor (also they're Int32).

But the real issue comes from that I can't *preview* my animation while I'm animating it... I have to animate blind then see if it works later.  If I animate exposed public variables directly, they don't receive updates from the animation because they don't force an update in NGUI.  I had written a AnimationUtility.IsAnimationMode() editor script that did the preview, but the Unity ANimation editor generates keyframes when it updates the exposed properties of the Widget...which causes garbage curves to be created.  Its just an ugly process.

What I'll probably do is create a similar helper script htat just draws a rectangle onto the scene view so at least I can see the bounds of what I'm animating or something.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #9 on: October 04, 2013, 08:48:44 PM »
The way animation window works in Unity is an ugly process. I'm tempted to just write a proper animation tool.

Mitch

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #10 on: October 05, 2013, 07:24:59 PM »
The way animation window works in Unity is an ugly process. I'm tempted to just write a proper animation tool.

That's your prerogative.  I hope I'm able to animate UI elements using an animation tool using uGUI.

Thanks for your response.

N.W.S

  • Guest
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #11 on: October 30, 2013, 10:00:08 AM »
Hey Guys.

I'm the same boat as you guys, I am artist making the GUI all pretty and responsive and then sending that onto the programmer who controls the flow and more advanced backend stuff, thus all advanced feedback and in/out sequences are made by me using the animation tool of Unity.

I've been having the same problem, suddenly not being able to animate the dimensions of my sliced sprites. While I don't understand why it should not be animatable, I have found a no-code workaround.

1. Make my sliced sprite.
2. Make a ScaleHack gameobject with an empty widget component with the widget dimensions of 1x1.
3. Attack a stretch component to my sliced sprite, pointing the container to the ScaleHack, setting the scale mode to whatever suits my need, "both" if you want full control.
4. Animate the transform of the ScaleHack which is then translated into dimensions on the sliced sprite by the stretch component.
5. Profit

I haven't played with it but, if you slap and anchor onto the sliced sprite pointing that to the ScaleHack as well I guess you could do all your moving and scaling animations like in ye olden days simply using the ScaleHacks transforms.

(FakeEdit: You can do the anchor thing but its pretty jittery.)

-NWS

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #12 on: October 30, 2013, 11:36:46 AM »
An easier method is to animate the following script's values instead:

  1. using UnityEngine;
  2.  
  3. public class AnimatedWidget : MonoBehaviour
  4. {
  5.     public UIWidget widget;
  6.  
  7.     [SerializeField] int width = 100;
  8.     [SerializeField] int height = 100;
  9.  
  10.     void Start()
  11.     {
  12.         if (widget != null)
  13.         {
  14.             width = widget.width;
  15.             height = widget.height;
  16.         }
  17.     }
  18.  
  19.     void Update()
  20.     {
  21.          if (widget != null)
  22.          {
  23.               widget.width = width;
  24.               widget.height = height;
  25.          }
  26.     }
  27. }

Nerosam

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #13 on: December 23, 2013, 09:22:06 PM »
An easier method is to animate the following script's values instead:

  1. using UnityEngine;
  2.  
  3. public class AnimatedWidget : MonoBehaviour
  4. {
  5.     public UIWidget widget;
  6.  
  7.     [SerializeField] int width = 100;
  8.     [SerializeField] int height = 100;
  9.  
  10.     void Start()
  11.     {
  12.         if (widget != null)
  13.         {
  14.             width = widget.width;
  15.             height = widget.height;
  16.         }
  17.     }
  18.  
  19.     void Update()
  20.     {
  21.          if (widget != null)
  22.          {
  23.               widget.width = width;
  24.               widget.height = height;
  25.          }
  26.     }
  27. }

This may be more of a unity question but i'm attempting to use this code to animate sliced sprite widgets in unity 4.3.2 but I am not getting the option to animate the width and height values. I've tried getting rid of the SerializeField tags and adding the public keyword infront of the variables but they are still undetected within the animation window. However when I add a random float variable to the script (and mark as public), this shows up within the animation window right way.

Any ideas as to why I'm having this awekward issue?

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Animating UISprite Dimensions in 3.0.x?
« Reply #14 on: December 24, 2013, 12:49:17 PM »
The animation system changed recently within Unity, so it's entirely possible that this doesn't work with 'int' types. Change them to float then, and Mathf.RoundToInt the value before assigning widget's width and height.