Author Topic: better method to hide UIPanel.  (Read 13658 times)

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
better method to hide UIPanel.
« on: May 01, 2012, 08:49:38 AM »
There are 3 methods to hide UIPanel, each of them is not a perfect solution.

1. NGUITools.SetActive
- if UIPanel show up again, some gameobject will become active that you don't want.

2. disable UIPanel Component
- Collider is not disabled.

3. Move UIPanel out of the UICamera
- UIPanel LateUpdate still being called that will hit performance.

loopyllama

  • Guest
Re: better method to hide UIPanel.
« Reply #1 on: May 01, 2012, 01:32:56 PM »
I have been finding the parent camera and doing a .setActiveRecursively (false) to hide the panel and (true) to unhide it. You won't been doing any unnecessary processing when it is off because you are deactivating the camera and every node below it, but you will have to have a camera per panel you want to independently hide/unhide.

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: better method to hide UIPanel.
« Reply #2 on: May 01, 2012, 08:57:32 PM »
I think having a camera per panel would be workaround solution but it would be hard to setup if there is many panels.
« Last Edit: May 02, 2012, 12:29:10 AM by yuewah »

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: better method to hide UIPanel.
« Reply #3 on: May 02, 2012, 09:33:35 AM »
@ArenMook, any better solution ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: better method to hide UIPanel.
« Reply #4 on: May 02, 2012, 09:38:22 AM »
Going #1 has been my choice so far. I structure my UI in such a way that this isn't a problem. In Windward I have a tutorial window that has several elements on top of each other that should only show up one at a time. When the window gets enabled, by default it enables all of them, but I have a script that listens for OnEnable and disables the objects I don't want to be visible.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: better method to hide UIPanel.
« Reply #5 on: May 02, 2012, 05:49:51 PM »
4th option, attach your own script that handles it.

We have used a script called UIScreen, which has a virtual method called "Show()", which handles everything that needs to be activated/deactivated when it needs to.

Then you just call myScreen.Show() and it will activate itself and so on. This does mean that it will have to have references to everything that it needs to activate of course, but if you structure it nicely, you can have things that always are on in a certain parent and dynamic things somewhere else, so you can use the NGUITools.SetActive on static things ( or "always on" things).

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: better method to hide UIPanel.
« Reply #6 on: May 02, 2012, 10:59:54 PM »
how about having a generic script that attached to the gameobject that is always On or Off while it will not affected by NGUITool.SetActive

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: better method to hide UIPanel.
« Reply #7 on: May 03, 2012, 02:17:46 AM »
Well, to make a gameobject permanently on/off, you have to either not use the recursive SetActives or use OnDisable/OnEnable to switch them back on or off.

Disabling a game object just means that it doesn't receive the general calls to Update, LateUpdate etc. You can still call methods directly in your class, like a Setup method, eventhough the gameObject is active = false.

yuewah

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 180
    • View Profile
Re: better method to hide UIPanel.
« Reply #8 on: May 03, 2012, 12:16:47 PM »
If UIWidget has a property , says isAlwaysActive = false, then NGUITools.SetActive( UIPanelA ) will ignore this and recursively set others child to be inactive.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: better method to hide UIPanel.
« Reply #9 on: May 03, 2012, 12:19:07 PM »
NGUI doesn't hide its source code specifically so you can make any modifications you wish. NGUITools.SetActive works with everything -- not just widgets -- and adding a GetComponent<UIWidget> to it to check 'isAlwaysActive' flag is going to slow it down. Why don't you just create your own simple script... call it "DontHideMe", that has absolutely nothing inside... attach this script to an object you don't want hidden, then create your own SetActive function that will check to see if this script exists, and if it does -- don't disable the object.