61
NGUI 3 Support / Possible Bug In NGUITools.SetActiveChildren (2.6.3)
« on: June 27, 2013, 01:34:53 PM »
In certain circumstances NGUITools.SetActiveChildren will recursively enable objects in Unity 4.0+.
NGUITools.SetActiveChildren(gameObject, true) will call NGUITools.Activate() which contains the following:
Notice that if !UNITY_3_5 and all children of the transform are activeSelf == false, the final for loop is executed. For example, in the following hierarchy:
If NGUITools.SetActiveChildren(Parent, true) is called, both Child and Subchild will be enabled. Obviously, this can occur recursively to any depth.
NGUITools.SetActiveChildren(gameObject, true) will call NGUITools.Activate() which contains the following:
- static void Activate (Transform t)
- {
- SetActiveSelf(t.gameObject, true);
- // Prior to Unity 4, active state was not nested. It was possible to have an enabled child of a disabled object.
- // Unity 4 onwards made it so that the state is nested, and a disabled parent results in a disabled child.
- #if UNITY_3_5
- for (int i = 0, imax = t.GetChildCount(); i < imax; ++i)
- {
- Transform child = t.GetChild(i);
- Activate(child);
- }
- #else
- // If there is even a single enabled child, then we're using a Unity 4.0-based nested active state scheme.
- for (int i = 0, imax = t.childCount; i < imax; ++i)
- {
- Transform child = t.GetChild(i);
- if (child.gameObject.activeSelf) return;
- }
- // If this point is reached, then all the children are disabled, so we must be using a Unity 3.5-based active state scheme.
- for (int i = 0, imax = t.childCount; i < imax; ++i)
- {
- Transform child = t.GetChild(i);
- Activate(child);
- }
- #endif
- }
Notice that if !UNITY_3_5 and all children of the transform are activeSelf == false, the final for loop is executed. For example, in the following hierarchy:
- Parent (active)
- Child (inactive)
- Subchild (inactive)
If NGUITools.SetActiveChildren(Parent, true) is called, both Child and Subchild will be enabled. Obviously, this can occur recursively to any depth.