When your GUI is gluey, what to do-ey?

Hello

I’ve made a GUI scrip to display a variety of information in the game on the HUD, I have added some buttons that lead to some menus. The menus are going to be arranged in a grid with an image/texture button representing a game object that is purchasable in game. This will be my shop design.

I am going to generate the item buttons at run time depending on how many items are available in the shop. The problem I’m having is coming up with a way I can store the references to these items.

I was looking into creating an item class that has all the basic properties, then I could just create a new instance with the name,cost,texture and the game object itself for each item. Then I was thinking I could loop through each item and display it as a button which when clicked would instantiate the game object.

Is it possible to break up parts of the GUI into smaller scripts and then call them all in one scrip that displays everything? or Would this be best to do in one script and keep everything together? My GUI scrip is getting a bit long and messy.

How would I go about creating the base class for the item or is there a better workaround ?

Thanks

Personally I put “WindowDisplay()” methods in the classes that they most relate to and then use a single OnGUI() in a camera mounted script to call those that are active at that time.

On larger projects I have such “gui element classes” register themselves with the gui-controlling script at startup (or when they are generated) and build a table of enabled/disabled values the OnGUI can scan through.