Author Topic: Best way to fade in/out a UIPanel and all its children?  (Read 10255 times)

legend411

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Best way to fade in/out a UIPanel and all its children?
« on: May 08, 2012, 07:45:23 AM »
I tried using a tween color component on the parent UIPanel and activating it with a UIButtonTween in another panel, but I get really odd results.

Also, is NGUITools.SetActive() in the latest version of the free package? I've been trying to do it by hand as an alternative, looping through all the GetComponentsInChildren.<UIWidget>() of the panel and lerping their color.a, but I'm getting weird results with SetActiveRecursively(), and its telling me NUGITools.SetActive() doesn't exist. I just downloaded the package over the weekend?

matix

  • Guest
Re: Best way to fade in/out a UIPanel and all its children?
« Reply #1 on: May 08, 2012, 07:56:11 AM »
  1. private static void SetNguiVisible(GameObject gameObject, bool visible)
  2.         {
  3.                 foreach(var widget in gameObject.GetComponents<UIWidget>())
  4.                 {
  5.                         widget.enabled = visible;
  6.                 }
  7.         }

legend411

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Best way to fade in/out a UIPanel and all its children?
« Reply #2 on: May 08, 2012, 08:09:37 AM »
I don't just want to set it invisible, I want to fade the alpha from 255-0 over time, then disable it entirely so it can't be interacted with.

matix

  • Guest
Re: Best way to fade in/out a UIPanel and all its children?
« Reply #3 on: May 08, 2012, 08:40:19 AM »
do u tryed?
  1. widget.alpha = Mathf.Lerp(0,255,Time.deltaTime);
  2. widget.color = new Color(0,0,0,  Mathf.Lerp(0,255,Time.deltaTime));

cayou

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 3
  • Posts: 90
    • View Profile
Re: Best way to fade in/out a UIPanel and all its children?
« Reply #4 on: May 08, 2012, 09:46:21 AM »
You can also use iTween or HOTween to perform this in one line.

legend411

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 9
    • View Profile
Re: Best way to fade in/out a UIPanel and all its children?
« Reply #5 on: May 08, 2012, 10:14:44 AM »
As I mentioned in the OP, it works fine when I do it manually... but I need to disable/enable the panel and all its children whenever it fades out/in, and SetActiveRecursively() is giving me weird issues or not working at all, and apparently NGUITools.SetActive() doesn't exist in the free version, unless I'm missing something.

Either way, if doing it by hand works, it'd be nice if you could make the TweenColor work, too (on the panel and all child widgets); not sure why it doesn't. I really like how intuitive using the built-in tweens is.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Best way to fade in/out a UIPanel and all its children?
« Reply #6 on: May 08, 2012, 11:42:34 AM »
TweenColor works on individual components -- a single widget, light, or renderer. A panel has many widgets, and as such -- many colors. Keep in mind the free version of NGUI comes as-is, it's not supported due to it being so far behind the current version.