Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started by: catacomber on July 29, 2012, 09:57:35 PM
-
I know the UIRoot and its children are all part of a game object (or at least I think so : ) ) but I'm not sure how to show/hide my NGUI game object.
Is there anything special I have to do? For example, if I wanted to show a Quest Log if you click a book icon in your HUD and then hide it by hitting the nice Close button in the example.
I'm trying to read through all the posts in the NGUI thread at the Unity forum and here so i don't ask questions already answered but have only gotten up to 13th page of the Unity forum posts and have 100 to go because I'm also following the videos and working with the examples and sleeping sometimes. : ) Thought it might be better just to ask. I did find something about--
SetActiveRecursively
but not sure how to use it. I know I have to do something that handles all the children of the UIRoot--or at least i think so. : )
Reading in the Unity Script Reference this "Sets the active state of this and all the game objects children to state."
Javascript is gameObject.SetActiveRecursively(true);
Is that also C# script? : )
Would it be like this?
using UnityEngine;
using System.Collections;
public class ShowIt : MonoBehaviour {
// On Mouse down function not looking to see what it is right now but want to show the NGUI : )
{
UIRoot root = GetComponent<UIroot>();
root.SetActiveRecursively(true);
}
}
What if I have more than one UIRoot in a game level?
-
NGUITools.SetActive(yourWindowGameObject, true/false)
-
"yourWindowGameObject"
Would that be a tag that I'd give the UIRoot--if I have more than one? Or do I have to assign them each a variable?
Is there a place here I can read more about NGUITools?
-
No, it would literally be your window's game object. Generally the UI is organized into windows -- which is just a game object under which you place your widgets. For example, for a main menu you'd create a game object called "Main Menu", and put everything related to the main menu -- labels, sprites, etc -- as children of this game object. So in order to show or hide this window you'd use NGUITools.SetActive.
There is no need to have more than one UIRoot in your scene.
-
I think I see. Thank you. Can I read more about NGUITools here? Thank you for your responsiveness. I know it's late. : )
That helps me with showing my Main Menu even though I hadn't even gotten to that question yet. : )
-
Here you go: http://tasharen.com/ngui/docs/class_n_g_u_i_tools.html
-
Well I guess I won't be sleeping for a few weeks. : ) Thanks very much!!! :D
-
So, for example, I'd have a UIRoot---
and it would have windows--
one for my Main Menu popping up
one for my Health Bars always being onscreen
one for my Quest Log popping up
one for my Inventory popping up
and one for Dialogues popping up
etcetera, etcetera?
And each window's visibility would be controllable via script . . . . .that references that window . . . and I would feed what appears in those via script or using the NGUI interface and colliders on in game objects--for example, signs. . .
-
Yeah. It's also a good idea to put a UIPanel on each of your windows. This way each window is a separate, independent draw call and won't affect others when it's moved / hidden / shown.
-
:-* Thanks. : )