unity3D ngui 插件 关于隐藏和显示游戏对象的问题
发布网友
发布时间:2022-05-16 07:52
我来回答
共2个回答
热心网友
时间:2023-10-15 20:34
我看了下NGUI关于 NGUITools.SetActive(gameobject,state)这个方法的定义,是这样定义的
static public void SetActive (GameObject go, bool state)
{
if (state)
{
Activate(go.transform);
}
else
{
Deactivate(go.transform);
}
}
然后Activae(Transform t)是这样定义的:
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
}
SetActiveSelf(t.gameObject, true);方法是这样定义的:
static public void SetActiveSelf(GameObject go, bool state)
{
#if UNITY_3_5
go.active = state;
#else
go.SetActive(state);
#endif
}
结论就是他的这个NGUITools.SetActive(gameObject, false);方法归根结底还是用的gameObject.setActivate(bool state)方法,所以你还是直接用gameObject.setActivate(bool state)方法就可以了
热心网友
时间:2023-10-15 20:34
额 你说的隐藏其实就是将它摧毁了 你都摧毁了 怎么还能调用它呢?想调用就还要重新载入。
给你个提示吧 如果隐藏的话就赋予它一个空值 显示的时候再赋予图片的精灵 这样是最简单的方法。