Mechropolis: Main Menu

This week the major artifact I worked on was the main menu and options system. To give a more quality feel I believe that you must have a proper options menu by which you can tailor performance options after your system. Many indie games provides basic functionality such as window resolution and quality presets but I wanted to take that a step further and provide most customizable properties available. I’d rather give the player the option than not to.

The strength of the NGUI plugin really showed here. NGUI was surprisingly easy to use, feature-rich and relatively bug-free. I had the basic layout and design ready in after just a few hours of reading through documentation and trying different settings. NGUI provides standard UI-elements such as buttons, labels ,dropdown menus, checkboxes and sliders. This saved me many hours of work and headaches trying to implement myself.

The results are the images above. The layout is highly provisional and may change. I also need to oversee the fonts as zero (0) looks like eight (8) using the current font. There are also some options missing (such as keybindings) which will be included in a later release. As you can see I allow the user to change FoV (both camera and hands), AA and texture/shadow quality in addition to the more standard resolution/vsync/fullscreen options. I’m planning to use a similar menu for the in-game options and the functionality is already prepared for realtime changes. Changing any of the options (except for resolution and fullscreen) is applied instantly and the idea is that you can quickly see what options you want without having to wait for a screen refresh (as with a resolution change).

Applying changes

Actually changing these options is surprisingly straight-forward. Everything except for shadow options and resolution is available through the

class QualitySettings

 static variables. I opted for a specific anti-aliasing component as hardware anti-aliasing is not available with deferred rendering. Changing any of these options is applied instantly. The following options are the ones I use internally.

QualitySettings static variables

Unity Quality Settings
QualitySetting variable Mechropolis option Used Values Description
QualitySettings.anisotropicFiltering
Texture Filtering
AnisotropicFiltering.ForceEnable

,

AnisotropicFiltering.Disable
ForceEnable = On, Disable = Off. Filtering level set per texture.
QualitySettings.masterTextureLimit
Texture Quality 0, 1, 2 0 = Low, 1 = Medium, 2 = High. Denotes the maximum mipmap level, where 0 = full resolution, 1 = half etc.
QualitySettings.vSyncCount
VSync 1, 0 1 = On (VSync every VBlank), 2 = Off.

Anti-aliasing

For anti-aliasing I’m using the Anti-Aliasing plugin/component available from the Image Effects package included with Unity Pro. changing is done simply by changing the

AntialiasingAsPostEffect.mode

 component variable. I tested the quality options available and decided that there should be three levels of anti-aliasing; disabled (off), DLAA, and FXAAPresetB (best).

Shadow settings

Shadow settings exists in QualitySettings as well, but it is missing the most crucial of the options; shadow resolution. Settings such as cascades and distance is still available through scripting but in order to change the overall shadow resolution a trick has to be used. The editable quality presets (in the Editor, Edit -> Project Settings -> Quality) can be switched in runtime with 

QualitySettings.SetQualityLevel(int preset)

 and the idea is that you set up quality level according to your desired shadow presets. In theory I could use this in conjunction with the QualitySettings variables, but given our timeframe and project scale I decided to settle for just being able to select shadow presets (disabled, low, medium, and high quality shadows). Here are the shadow presets as I have set them up:

All Rendering and Other settings are ignored as they are applied by QualitySettings variables after I apply the shadow preset (overriding existing settings). As these presets are applied with an index value it is also important that the order is the same as the main menu management code believes, so that the correct value in the dropdown box corresponds to the correct preset value.

Resolution

Changing resolution is easy; just call

Screen.SetResolution(int Width, int Height, bool Fullscreen

 with the corresponding values. Obtaining a list of valid resolutions is done with the

Screen.resolutions

 list.

A side-note though: I wanted to display the current resolution as the pre-selected value in the dropdown box. This is done with

Screen.width

 and

Screen.height

 which returns the current window (or screen if fullscreen) dimensions, but when changing with 

Screen.SetResolution(int Width, int Height, bool Fullscreen)

 note that the actual process of changing resolution occurs in a separate thread, and the values for

Screen.width

 and

Screen.height

  is not updated until this finishes. In order to compensate for this I run everything in a coroutine that waits for 1.5 seconds before populating the dropdown values, which should be sufficient.

About Kenth Ljung

2012 Programming