Author Topic: Feature requests: more options for UIPlay Tween and Tween Rotation  (Read 4322 times)

rilez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
first post here, and it's for help/feature requests!   ;)

use case: i'm more of a designer than programmer, but not much of either. i've chosen to use NGUI to animate our menus. the main reason for doing this, as opposed to using unity's animator, is because we want the menu to animate while the game is paused (timescale = 0, easiest way). there's no convenient way of doing this using the animator. i struggled for a couple of days to try and hack together some scripts people had made to get around this issue, but i'm not much of a programmer, and couldn't get them to work. we're using NGUI for some other things, and so i've decided to rebuild the animations using tweens, and take advantage of NGUI's ignore timescale option.

1) as a designer, with some programming ability, i'd like to be able to call specific tweens and tween groups from code, so that i can take advantage of the animation curve, but also the flexibility of calling events from scripts. (how do i call Tween ScaleA on gameobject1 using this trigger/that trigger/on finished, and not Tween ScaleB on gameobject1?)

you are super helpful on the forums (probably more so than you need to be), and i realize this isn't a place to "teach people to code," but one of the things i really like about unity's documentation is the examples that they provide. i was able to figure out how create all of our animations, create parameters and a simple state machine, and call everything from code based on the game's current state and user's input. your documentation is superb, but for someone who's not great at programming, more often than not, i'm left with a feeling of "ok, great... now how do i use this?"

2) as a designer who can't figure out how to call specific tweens from code, i'd like all of the trigger conditions, with every possible permutation, available in the UIPlay Tween script.

since i can't figure out how to do this in code, and you're not here to teach us how to code, i come to you on hands and knees to beg for a more robust/user friendly interaction script options in the inspector. this is one point that is driving me absolutely-computer-smashing-insane nuts.

some of my objects have a half dozen Tween Scale components attached, for each state/animation. i've assigned each of these to groups, which i'm equating to states (keeping track of this is enough to drive one mad). i have very specific animations that play when i onpress (true? down?) on a button, ondrag off of it, onpress (up? false?), etc. OnPress plays the animation automatically in reverse when i press off/drag off, which i don't want it to do. OnPress true plays it only when i press down (hooray!), but then OnPress false doesn't seem to want to trigger... anything... and there is no OnDrag off, and... i could get this to work in code using NGUI's events, and unity's animator, easily. i've battled with NGUI for a couple of days here, and am left wanting nothing more than to rage and smash my computer to bits.

3) please, for the love of god, how do i get something to rotate?

one of the animations i've created is very similar to one found in Path's app; press a button and everything comes flying/spinning into place. i tried the spin script recommended in another thread, but it doesn't work with timescale = 0 (rahhh!). one would think Tween Rotation would work, but i cannot cannot CANNOT figure out what arguments to put into from/to, or finagle the animation curve/duration, in order to get something to spin quickly a half dozen times, for about a second, and then stop.

thanks dude! you're really helpful here on the forums, and have built something truly awesome! i feel like a dickhead coming with complaints and requests, but if you want feedback/rage inducing use cases, here ya' go  ;D

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Feature requests: more options for UIPlay Tween and Tween Rotation
« Reply #1 on: February 25, 2014, 12:59:53 PM »
You can use the animator just fine with timescale 0.

Just attach ActiveAnimation script to play the animation instead of relying on Unity to do it. ActiveAnimation is able to play it while the game is paused. This is also what NGUI does to play animations when you activate something via UIPlayAnimation.

You can trigger the animation via code by using ActiveAnimation.Play as well.

Re: TweenRotation. In short, it's not meant to spin things. Just adjust the rotation. So if you try to tween from 0 to 360, it wont move because it's the same rotation angle (0 degrees). You can use this modified Spin class to achieve what you need:
  1. using UnityEngine;
  2.  
  3. /// <summary>
  4. /// Want something to spin? Attach this script to it. Works equally well with rigidbodies as without.
  5. /// </summary>
  6.  
  7. [AddComponentMenu("NGUI/Examples/Spin")]
  8. public class Spin : MonoBehaviour
  9. {
  10.         public Vector3 rotationsPerSecond = new Vector3(0f, 0.1f, 0f);
  11.         public bool ignoreTimeScale = false;
  12.  
  13.         Rigidbody mRb;
  14.         Transform mTrans;
  15.  
  16.         void Start ()
  17.         {
  18.                 mTrans = transform;
  19.                 mRb = rigidbody;
  20.         }
  21.  
  22.         void Update ()
  23.         {
  24.                 if (mRb == null)
  25.                 {
  26.                         ApplyDelta(ignoreTimeScale ? RealTime.deltaTime : Time.deltaTime);
  27.                 }
  28.         }
  29.  
  30.         void FixedUpdate ()
  31.         {
  32.                 if (mRb != null)
  33.                 {
  34.                         ApplyDelta(Time.deltaTime);
  35.                 }
  36.         }
  37.  
  38.         public void ApplyDelta (float delta)
  39.         {
  40.                 delta *= Mathf.Rad2Deg * Mathf.PI * 2f;
  41.                 Quaternion offset = Quaternion.Euler(rotationsPerSecond * delta);
  42.  
  43.                 if (mRb == null)
  44.                 {
  45.                         mTrans.rotation = mTrans.rotation * offset;
  46.                 }
  47.                 else
  48.                 {
  49.                         mRb.MoveRotation(mRb.rotation * offset);
  50.                 }
  51.         }
  52. }

rilez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Feature requests: more options for UIPlay Tween and Tween Rotation
« Reply #2 on: February 26, 2014, 05:20:57 AM »
thanks for the help XD prior to deciding to rebuild my animations using tweens, i was able to play them with UIPlayAnimation, but only by using trigger conditions via the inspector, and only once- no looping, annnd only by setting them to legacy (otherwise i get the common "Default clip could not be found" error). i can't get them to loop/continue to play as they were while paused, even with wrap mode set to loop (i'm guessing this is wrong, anyway). i'll keep fiddling around with it.

just attaching ActiveAnimation to a gameobject doesn't seem to have any effect when timescale = 0. i've tried it with both the animator and animation components, without any luck. is it that simple, or am i doing something wrong? i guess i really just wish unity had a better, baked in way to selectively pause gameobjects ("don't pause my physics!"/"don't pause my animations!"). for a couple relatively green devs, figuring out how to stop the game has really... stopped the game.

re: rotation, that's kinda what i gathered from the forum. i guess i had reached a frustration point yesterday, and wanted to smash something when the "rotation" script wouldn't bend to my will. i can figure out how to enable/disable the component to get it to work how i want. if this is what people are meant to use to reallyyy rotate things however, it would be nice to have duration, group, and an animation curve added in a future update.

cheers!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Feature requests: more options for UIPlay Tween and Tween Rotation
« Reply #3 on: February 26, 2014, 03:39:28 PM »
No, simply attaching ActiveAnimation won't do anything. You need to actually trigger it from somewhere using ActiveAnimation.Play.