Author Topic: Help with coding structure  (Read 1697 times)

Pip Robbins

  • Guest
Help with coding structure
« on: September 05, 2012, 05:32:28 AM »
Firstly I would like to say big thanks, as NGUI is a fantastic addition to unity, also I apologise in advance as this question is rather open ended and properly very difficult answer.

I am currently in the process of trying to set up a reusable and flexible gui with NGUI for a range of games in the line of dragonvale, tiny village, paradise island etc

These two videos provides some examples of what I mean
http://www.youtube.com/watch?v=YICNvhCbUos
http://www.youtube.com/watch?v=-FNEZRPcJsw

What is the most professional way do this?

I am thinking of setting up generic GUI elements / panels, such as building panels, information panels, progress bars etc then saving them as prefabs.

Then depending on what building / button is clicked on it will fill out the building panel with the list of buildings or information based on that building.

How would you go about setting this up coding wise, create a handler for each generic panel?

Any advice would be greatly welcome!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Help with coding structure
« Reply #1 on: September 05, 2012, 03:26:43 PM »
Pretty much as you think -- you create prefabs for each UI screen that you need, and change the contents of that screen dynamically. For example if you need to show the building's name, you'd modify the "BuildingName" label's text value. In Windward I generally have a "row" script for each table entry -- for example, NewsTable script is attached to the same game object as UITable, and it references a prefab I created earlier with a NewsRow script on it. NewsRow references various components underneath it via public variables -- title, date, and content, for example. Then when NewsTable creates a new NewsRow prefab instance, it GetComponent<NewsRow>, and populates the values.