Author Topic: [Solved] Recommendation on how set up my NGUI Root  (Read 315 times)

yo_milo

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 2
  • Posts: 36
    • View Profile
[Solved] Recommendation on how set up my NGUI Root
« on: October 02, 2017, 07:04:16 PM »
Greetings.
I have been struggling on a good way to set up my NGUI Roots.
 I used to have an NGUIRoot prefab, but when it comes to the moment of adding other components, things get "shaky".

Additionally, lately I have found some elements I need to reuse in my main menu and in my levels, which cause this huge struggle because the "Levels" UI is a prefab, and if I nest other prefabs, then I will break the link to the original one.

This is not like a "This is the right answer" kind of question, I was wondering... What would you suggest, fellow devs?

These are the solutions I believe they could work:
> Adding all the needed UI in every place in One centralized prefab, set up any other needed stuff with code as needed. The root would not destroy on load.
> Saving all the elements in Panel prefabs and spawning them as needed on demand, Root could be a another prefab, spawned as needed.

Any suggestions?
« Last Edit: October 06, 2017, 10:49:13 AM by yo_milo »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,137
  • Toronto, Canada
    • View Profile
Re: [Solved] Recommendation on how set up my NGUI Root
« Reply #1 on: October 07, 2017, 06:25:42 AM »
Always have only one UIRoot per scene. Each window underneath it should have its own panel, and should be saved as a prefab. Inventory, character screen, player list, world map, etc -- some examples of such windows. This way when you set up a new scene, you can drag in only the prefabs you need for it.

I also generally start most of those panels in a disabled state, and have a "window manager" script attached to the root with references to those game objects. When I want to enable a window, I tell the window manager to do it. For example, "window manager, show me the inventory window". It then enables the correct game object and shows it.

yo_milo

  • Newbie
  • *
  • Thank You
  • -Given: 10
  • -Receive: 2
  • Posts: 36
    • View Profile
Re: [Solved] Recommendation on how set up my NGUI Root
« Reply #2 on: October 12, 2017, 01:59:14 PM »
Thank you Aren, that is what I did, kind of.

I added all the needed UI under my Root, which has don't destroy on load (And it is actually like a lazy gameobject, which instantiates itself when called), and I just call each window when needed, and even created some modal screens using your eventDelegate methods.


I had a problem when loading async another scene because the loading has it's own UIRoot, but I fixed it by changing one line of code and everything runs smooth as butter. I thought having a lot of UI disabled would be a lot of overhead, but it is negligible.