Author Topic: UITweener feature requests  (Read 7151 times)

step

  • Guest
UITweener feature requests
« on: July 13, 2012, 10:41:23 PM »
Hi,
It would be really useful for me to have tweens that does not have the From field, and use the current (position, color, alpha, etc) of the widget instead. Alternatively, i could write my own tweeners which do that if UITweener class had virtual OnStart method.

Also, would be nice to have Bounce tween method available.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITweener feature requests
« Reply #1 on: July 13, 2012, 11:07:51 PM »
You're looking for UITweener.Begin series of functions. For example:
  1. TweenPosition.Begin(targetGameObject, duration, targetPosition);
As you may notice they don't have a "from" field, meaning they'll use the current position/color/whatever you're tweening as the starting point.

Bounce tween is already implemented. Make sure you've got the latest version.

  1. TweenPosition.Begin(targetGameObject, duration, targetPosition).method = UITweener.Method.BounceOut;

step

  • Guest
Re: UITweener feature requests
« Reply #2 on: July 16, 2012, 05:48:16 PM »
Got the latest version, bounce works, thanks.

I'd like to have all my tweens to have the same parent class and interface. That way i can query them by using GetComponentsInChildren<UITween> and start the needed tween group (like in UIButtonTween). I'd hate to build a new tree of tweener scripts with a different base class and make a second call to GetComponentsInChildren to use TweenPosition.Begin.
So actually the only thing needed for me to be able to write my own tweens derived from UITween is the virtual OnPlay() method that gets called from UITweener.Play function. Is there any chance this might be added to official NGUI release?

Attached are modified UITweener script and the example of "To" tween.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITweener feature requests
« Reply #3 on: July 16, 2012, 06:36:37 PM »
The obvious question is -- why?

Tweens start playing as soon as the script is enabled, and Play function is used to switch the direction (or to start playing if it's disabled, for that matter).

Why would you need it to be virtual?

step

  • Guest
Re: UITweener feature requests
« Reply #4 on: July 16, 2012, 07:26:18 PM »
So i can override it and have my own code executed in my tweens (in case of "tween to" it's setting "from" variable to the current value). I could use the OnEnable method for that, but it's not very reliable.

As i told, i'd like to have all the tweens to have the same parent class and the same way to start - whether it's standard "From-To" tweens or "To" tween. I'm trying to avoid having to call "Play" for standard tweens and TweenWhatever.Begin for others.

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UITweener feature requests
« Reply #5 on: July 16, 2012, 07:34:28 PM »
Begin() will work fine for everything. It returns an instance of the tweener that you can then modify, setting the "from" if you like.

step

  • Guest
Re: UITweener feature requests
« Reply #6 on: July 16, 2012, 08:09:41 PM »
I use the following code to start all the tweens (belonging to a given tween group) of an object:
  1. tweens = GetComponentsInChildren<UITweener>();
  2. foreach (UITweener tween in tweens)
  3. {
  4.         if (tween.tweenGroup == group)
  5.         {
  6.                 tween.Play(true);
  7.                 tween.Reset();
  8.         }
  9. }
  10.  

Simple and elegant. If i have to use Begin method, i'll need to handle all the possible tween types separately, which is not that elegant. With the enhancement i'm proposing, there will be no need in that. Of course, there's one more function call in Play method, but i think it won't do much bad. And it will be useful for tweener to know the fact it has begun anyway.