Author Topic: Show hide my NGUI  (Read 15051 times)

catacomber

  • Guest
Show hide my NGUI
« 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? 
« Last Edit: July 29, 2012, 10:19:49 PM by catacomber »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Show hide my NGUI
« Reply #1 on: July 29, 2012, 10:23:20 PM »
NGUITools.SetActive(yourWindowGameObject, true/false)

catacomber

  • Guest
Re: Show hide my NGUI
« Reply #2 on: July 29, 2012, 10:29:07 PM »
"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?   
« Last Edit: July 29, 2012, 10:46:22 PM by catacomber »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Show hide my NGUI
« Reply #3 on: July 29, 2012, 10:46:33 PM »
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.

catacomber

  • Guest
Re: Show hide my NGUI
« Reply #4 on: July 29, 2012, 10:51:10 PM »
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.  :  )
« Last Edit: July 29, 2012, 10:53:10 PM by catacomber »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Show hide my NGUI
« Reply #5 on: July 29, 2012, 10:52:27 PM »

catacomber

  • Guest
Re: Show hide my NGUI
« Reply #6 on: July 29, 2012, 10:54:37 PM »
Well I guess I won't be sleeping for a few weeks.  :  )  Thanks very much!!!   :D

catacomber

  • Guest
Re: Show hide my NGUI
« Reply #7 on: July 29, 2012, 11:13:40 PM »
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. . .
« Last Edit: July 29, 2012, 11:16:17 PM by catacomber »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Show hide my NGUI
« Reply #8 on: July 29, 2012, 11:19:10 PM »
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.

catacomber

  • Guest
Re: Show hide my NGUI
« Reply #9 on: July 29, 2012, 11:22:33 PM »
 :-* Thanks.  :  )