I have this game menu which is made up of gui elements such as button, selection grid, toggles etc. This is all great.
I have a global variable representing pause, lets call it gamePaused, which everything can check up against to see if the game is paused and decide what to do.
The problem is that i would like to do a form of popup exit menu that become visible on ESC, pauses the game and only lets the user interact with components in the esc menu and not any other GUI components, but those should still be rendered.
I initially thought i could just check on all action states such as buttons if the game was paused and not do anything.
if( GUI.Button(..., "myStyle") )
{
if(!gamePaused) OnClick();
}
This work to make the gui passive in that it wont activate anything. BUT its not passive enough all the hover effects and such are still fully functional.
I then though i could just render a passive control using Box and still have the menu look like it should.
if(gamePaused)
{
if( GUI.Button(..., "myStyle") )
{
OnClick();
}
}
else
{
GUI.Box(..., "myStyle");
}
This works for some components, but not for toggles. Here i will have to detect the state of the toggle and extract the correct style image to use.
if(gamePaused)
{
GUIStyle toggle = GUI.skin.GetStyle("toggle");
GUI.Box(new GUIContent(toggle.onNormal.background), ..., toggle);
}
else
{
GUIStyle toggle = GUI.skin.GetStyle("toggle");
GUI.Box(new GUIContent(toggle.normal.background), ..., toggle);
}
This can get even more complicated, but thats not the point the point is it clutters the code up with a lot of extracting the right data based on state.
It would be really nice and simplify things to just be able to write something like
GUI.PassiveToggle(...);
So basically to create the effect i want i could write:
void OnGUI()
{
GUI.skin = mySkin;
... some shared code for both paused an non paused
if(!gamePaused)
{
value = GUILayout.Toggle(value, ...);
}
else
{
GUILayout.PassiveToggle(value, ...);
}
}
So a passive version of a gui component use the same information as the active ones, just that passive ones are only renders of the components state without the interactivity.
Is there any way to do this simple or do i have to wrap all components? Is it even a good idea, maybe im doing things wrong?
Comments are welcome.
Regards,
Marc