Author Topic: Unity 3.5 -> Unity 4 NGUITools.SetActive still doesn't work right...  (Read 5923 times)

terence

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
I noticed this:
http://www.tasharen.com/forum/index.php?topic=2283.msg11378#msg11378

and also notes in the build about fixes, but it still doesn't work right for me because when I call NGUITools.SetActive, many of my widgets child objects (i.e. labels, sprites etc) don't get activated. I just update to 2.3.6 and the problem is still there.

If it matter any, the panel starts out disabled (i.e. all elements disabled).

terence

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Unity 3.5 -> Unity 4 NGUITools.SetActive still doesn't work right...
« Reply #1 on: March 10, 2013, 11:22:30 PM »
This is how i 'fixed' it...in NGUITools..
  1.         static void Activate (Transform t)
  2.         {
  3.                 SetActiveSelf(t.gameObject, true);
  4.  
  5.                 // Prior to Unity 4, active state was not nested. It was possible to have an enabled child of a disabled object.
  6.                 // Unity 4 onwards made it so that the state is nested, and a disabled parent results in a disabled child.
  7. #if UNITY_3_5
  8.                 for (int i = 0, imax = t.GetChildCount(); i < imax; ++i)
  9.                 {
  10.                         Transform child = t.GetChild(i);
  11.                         Activate(child);
  12.                 }
  13. #else
  14.                 // If there is even a single enabled child, then we're using a Unity 4.0-based nested active state scheme.
  15.                 /*for (int i = 0, imax = t.GetChildCount(); i < imax; ++i)
  16.                 {
  17.                         Transform child = t.GetChild(i);
  18.                         if (child.gameObject.activeSelf) return;
  19.                 }*/
  20.  
  21.                 // If this point is reached, then all the children are disabled, so we must be using a Unity 3.5-based active state scheme.
  22.                 for (int i = 0, imax = t.GetChildCount(); i < imax; ++i)
  23.                 {
  24.                         Transform child = t.GetChild(i);
  25.                         Activate(child);
  26.                 }
  27. #endif
  28.         }
  29.  
  30.  

Pretty much commented out the check which pops out of the method if it finds any 'active' children. The only thing that comes to mind is that some how an active child was found when there shouldn't be..

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Unity 3.5 -> Unity 4 NGUITools.SetActive still doesn't work right...
« Reply #2 on: March 11, 2013, 08:20:26 AM »
SetActive only sets the current gameObject as active (via activeSelf).

This is a different behavior than the old SetActiveRecursively.

If you need to set it active recursively do something like this

  1.  
  2. void Activate(Transform t)
  3. {
  4.   SetActive(t.gameObject);
  5.  for (int i = 0; i<t.childCount;i++)
  6. {
  7.   Activate(t[i]);
  8. }
  9.  
  10. }
  11.  
  12.  

terence

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 14
    • View Profile
Re: Unity 3.5 -> Unity 4 NGUITools.SetActive still doesn't work right...
« Reply #3 on: March 11, 2013, 10:29:25 PM »
Yes. I know that, but I am just pointing out that the NGUITools.SetActive should still work consistently across Unity3.5 and Unity 4..

I should either be included as a fix for the current build or improved upon so it does work consistently.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Unity 3.5 -> Unity 4 NGUITools.SetActive still doesn't work right...
« Reply #4 on: March 12, 2013, 12:56:42 AM »
The way it works is quite correct. The goal of it is to disable a game object and all of its children. In Unity 3.5 this means disabling the game object and all the children individually. In 4.0 it means disabling only the topmost object.