Author Topic: TweenAlpha for all content in Sprite  (Read 11490 times)

Romano

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
TweenAlpha for all content in Sprite
« on: November 26, 2013, 07:56:57 AM »
Hello
1) How to apply the alpha to all children of the object using TweenAlpha?
2) How to work with tweenAlpha.onFinished?
3) How to get  target from onFinished method?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #1 on: November 26, 2013, 08:31:57 AM »
1. TweenAlpha works on a single component, so if you need it to work on multiple, you need multiple tweens. Either that or derive from UITweener to implement your own custom tween component.

2. Use EventDelegate.Add(tween.onFinished, YourCallback);

3. UITweener.current. With NGUI event delegate, it's always <className>.current.

Romano

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #2 on: November 27, 2013, 12:42:08 AM »
I'm doing this

  1. void ShowPanel()
  2.         {
  3.                 print ("ShowPanel");
  4.                 gameObject.SetActive(true);
  5.  
  6.                 foreach(var widget in gameObject.GetComponentsInChildren<UIWidget>())
  7.                 {
  8.                         tweenAlpha = TweenAlpha.Begin(widget.gameObject, duration, 1);
  9.                 }
  10.         }
  11.  
  12.         void HidePanel()
  13.         {
  14.                 print ("HidePanel");
  15.                 foreach(var widget in gameObject.GetComponentsInChildren<UIWidget>())
  16.                 {
  17.                         tweenAlpha  = TweenAlpha.Begin(widget.gameObject, duration, 0);
  18.                         EventDelegate.Add(tweenAlpha.onFinished, ChangeVisible);
  19.                 }
  20.         }
  21.  
  22.         public void ChangeVisible()
  23.         {
  24.                 print ("ChangeVisible");
  25.                 print("UITweener.current: " + UITweener.current);
  26.  
  27.                 EventDelegate.Remove(UITweener.current.GetComponent<TweenAlpha>().onFinished, ChangeVisible);
  28.                 gameObject.SetActive(false);
  29.         }

When calling ShowPanel again. After the ShowPanel is called ChangeVisible. Why?! I remove listener on onFinished.
What am I doing wrong?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #3 on: November 27, 2013, 12:45:56 AM »
If you want it to be removed after getting called, pass 'false' for the last parameter, like so:
  1. EventDelegate.Add(tweenAlpha.onFinished, ChangeVisible, false);
Then you don't need the Remove() call.

Romano

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #4 on: November 27, 2013, 12:59:51 AM »
it's don't working (

Romano

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #5 on: November 27, 2013, 01:43:30 AM »
It removes only one listener. Why?!

Romano

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #6 on: November 27, 2013, 01:51:16 AM »
it's working!

  1. void ShowPanel()
  2.         {
  3.                 print ("ShowPanel");
  4.                 countAlpha = 0;
  5.                 gameObject.SetActive(true);
  6.  
  7.                 foreach(var widget in gameObject.GetComponentsInChildren<UIWidget>())
  8.                 {
  9.                         tweenAlpha = TweenAlpha.Begin(widget.gameObject, duration, 1);
  10.                 }
  11.         }
  12.  
  13.         void HidePanel()
  14.         {
  15.                 print ("HidePanel");
  16.                 foreach(var widget in gameObject.GetComponentsInChildren<UIWidget>())
  17.                 {
  18.                         tweenAlpha  = TweenAlpha.Begin(widget.gameObject, duration, 0);
  19.                         EventDelegate.Add(tweenAlpha.onFinished, ChangeVisible, true);
  20.                 }
  21.         }
  22.  
  23.         public void ChangeVisible()
  24.         {
  25.                 print ("ChangeVisible");
  26.                 countAlpha++;
  27.                 if (countAlpha >= gameObject.GetComponentsInChildren<UIWidget>().Length) {
  28.                         gameObject.SetActive(false);
  29.                 }
  30.         }

Romano

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #7 on: November 27, 2013, 01:52:32 AM »
When to ameObject.SetActive(false), then onFinished other objects does not working

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #8 on: November 27, 2013, 03:48:30 AM »
Why are you tweening out so many widgets anyway? Why not just TweenAlpha the panel that the widgets use? This way you only need one tween.

Romano

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #9 on: November 27, 2013, 04:13:00 AM »
Clipping does not work when the panel inside the panel

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #10 on: November 27, 2013, 05:27:05 AM »
That's right, that limitation is mentioned on the doc page for UIPanel: http://www.tasharen.com/forum/index.php?topic=6705.0 -- but we're talking about tweening alpha here, not clipping -- and alpha is nested.

Romano

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #11 on: November 27, 2013, 05:30:42 AM »
I understand. How to fix that situation?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #12 on: November 27, 2013, 10:11:02 AM »
You can't have multiple clip rects affect widgets. Only one panel can clip widgets within. There is currently no way to get it to work otherwise with NGUI.

Romano

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 32
    • View Profile
Re: TweenAlpha for all content in Sprite
« Reply #13 on: November 28, 2013, 04:23:25 AM »
How to fix that situation WITH ANIMATION?