Hi Everyone,
I have been drawing up a prototype menu system for a sports management game that’s been flying about in design recently. Being a management game, it has an extensive menu system.
I started coding the menu with confidence, here’s a snippet of how I’m currently doing it:
//Menu Layer Vars
var mainmenu : boolean = true;
var teammanage : boolean;
var noticeboard : boolean;
var teamaffairs : boolean;
var playmanagement : boolean;
var market : boolean;
var options : boolean;
function OnGUI()
{
GUILayout.BeginArea(Rect(Screen.Width/2 -buttonWidth/2,Screen.Height/2 - buttonHeight/2, buttonWidth, buttonHeight)"Scrott-Balls"); // make all the menus centered.
if(mainmenu) // main menu stuff goes here
{
if(GUILayout.Button("Team Management", GUILayout.Height(buttonHeight)))
{
teammanage = true;
}
if(GUILayout.Button("Options"),GUILayout.Height(buttonHeight)))
{
options = true;
teammanage = false;
}
}
if(teammanage) // begin team management menu
{
if(GUILayout.Button("Notiss Boord", GUILayout.Height(buttonHeight)))
{
noticeboard = true;
teammanage = false;
So as you can see, when a buttons pressed i just turn one variable off and another on.
This has worked in the past for me, but on smaller menus. I would guesstimate at around 100+ elements to this menu system (that includes back buttons and “are you sure’s”.
Now obviously with the way I’m doing it this file is gonna be HUGE and navigating / debugging the code is going to be an absolute nightmare!
I’ve considered giving each sub-menu its own code file and enabling / disabling them… but that could turn out just as messy in the end, and i don’t want to waste more time finding out the hard way.
Has anyone got any advice or ideas on the best way to (tidily) make such a hugeumungus menu?
Thanks for reading :).
thanks a lot for your answer :). 1: We have done this, have you seen freemind? great program for prototyping menus early on. 2: I understand what you mean, we are going for a slightly different approach tho. 3: Switch case structures definitely look like a way forward, will have to look into these as i have never come across them before. 4: Are you saying that instead of putting the functionality for the buttons inside the OnGUI, you suggest calling another function from OnGUI? So OnGUI simply draws the GUI and calls the functions, the rest is done inside the said functions?
– timsk4: YUP! Look for n-tier development patterns/architecture
– BerggreenDKawesome, will crack on with this then. Thanks a lot for your help Berggreen.
– timskJust want to make sure im going about this the right way (and help anyone who stumbles on this question). Im declaring my switch statement in function OnGUI like this: switch(menulayer) { case "mainmenu" //draw GUI function and button code, button code changes the case and calls functions from buttonfunctionsclass. break; } im defining the GUI drawing in a helper function and all the actual functionality in a seperate class. Edit: Cant find a way to format code in comments.
– timsk@timsk <.pre> <pre> CODE </pre> <./pre> //without dots
– DavidDebnar