Hello, I’m using NGUI. In my UI, I have buttons, windows, title bars, etc. Clicking a button might do something to the window its in. For example a ‘X’ (close) button will close the window its in.
Here’s what I have:
(The 2nd bar above the file manager’s address bar shouldn’t be there)
As you can probably tell, there’s a lot of things going on. For example:
- If you click on ITEMS you will see
the items view, click on FILES to see
the file manager. Now, this involved
hiding/showing the parent object
holding the items/file manager. - Clicking on the close button, will
deactivate the inventory’s panel. - Clicking on the little tetris icon,
will sort the items. - Clicking on the green down arrow,
will discard all items.
In the last two examples, the buttons had to communicate with the items’ bag, and call the necessary methods. For that, I create a script called button_Sort and button_Discard, have a public serialized Bag variable, and assign it in the inspector before I play.
If not in the inspector, assuming the button is a child somewhere under the bag, the bag accesses the button’s button_Sort script and assign itself to the Bag variable inside there.
This sounds tedious, is there a better way than this?
And in general, what’s the best way to handle this type of communication between such components? I’ve recently learned about the Mediator pattern, I’m thinking how I could use it here. How about SendMessage? - If you do suggest it, I’d appreciate a brief explanation about how it works, how it sends the message, etc because I haven’t used it before.
Thanks for you ideas and suggestions in advance.