I need some advice on using panel prefabs in NGUI. I have recently went through and updated all the panels and widgets in my game to the latest NGUI and am thinking that since I have a lot of panels and that they don't always need to be on the screen or even loaded for that matter it might be a good idea to make them into prefabs that can be loaded as needed using the NGUITools.AddChild . What I'm not sure about is how to properly destroy them.
Here is my example.
Lets say I have a looting panel. When something happens in the game like player clicking on a chest or dead creature the looting panel is added to the root using the AddChild. The panel contains its script which can do all the necessary functions but the panel has a close button on it for when your done looting. What is the proper way to close this. Should the destroy function be in the script that is attached to the prefab panel or should it be elsewhere. Ill try to represent things here
UIRoot
- MainGUI Controller script attached to UIroot. Call this Script A for example purposes
- LootPrefab Panel
- Loot panel script attached to panel. Call this Script B for example purposes.
Should the Loot panel script (script B) call the destroy on itself? if not what is the best way to handle this?
Also a second question. When using the add child it looks like you could use a resources.load.. is there any reason you would need to do this if the prefab is in your project? Perhaps thats more of a unity question??
Thanks in advance. BTW this might be a good example to do some where to show people how to properly add and delete objects using the NGUITools.functions