Development Diary #12: Quality settings…

Every button has its own FSM to handle input, deal with on/over/selected states and to store pertinent, pre-set values. Settings are changed by replacing the current values stored on Settings IO with these pre-sets before triggering Save New Settings to update the actual playerSettings file.

Fullscreen_FSM_Main

This is the FSM on the Fullscreen button, it stores a boolean and acts as a toggle. The highlighted Self variable is a Unity Object of type UnityEngine.TextMesh, when using Get Component on a GameObject, Unity will take the first one it finds of the set type, so it’s a good idea to set that here.

Fullscreen_FSM_Annotated

Wait for IO Idle is empty and waits for an IO Idle event from Settings Menu Update, note that in addition to the START event the first state can be entered via the global event IO Busy. Initialize finds objects and components and store them as local variables.

Get Current Fullscreen gets the Fullscreen boolean value from the Settings Menu Update FSM storing it locally as Current Fullscreen, this allows us to compare the two and automatically select or deselect the button to begin with, without requiring a click.

(At this point, a lot depends on how you’re handling input, I have a slightly odd cursor set up, in order to tell when the player is hovering over a button with a mouse I compare the Owner to a globally determined Hovered_Object. You could alternatively use an OnMouse event or another equivalent.)

When a button is first selected, the local Fullscreen boolean is set to true and the font style is changed to bold. Idle Selected checks every frame for a mouse over, when it detects one it triggers the Over event and switches to Over Selected which checks every frame for a click event as well. Selected Cursor Over state is the equivalent for non mouse input and is entered and exited via the global events Cursor Over and Cursor Off, sent from elsewhere. Both Over states also scale the parent button up slightly, Idle Selected scales it back.

Upon detecting a Click event, Update Changes Selected first sends an event to the Apply Settings button to indicate that a change has taken place before swapping over to Deselect, all the states here work identically to their selected counterparts except the text style is set to regular and the Fullscreen boolean is set to false.

No values are actually sent to Settings IO FSM until Update Settings receives the Update Settings IO global event from the Apply Settings button.

Button_FSM_Main

The FSM templates used on most of the other buttons are extremely similar to the one for Fullscreen, the Unselected states all work exactly as before. For resolution, AA-Level and V-sync, however, there always has to be a value selected, what’s more it can’t be deselected without simultaneously choosing a new one, they behave more like standard radio buttons.

Button_FSM_Annotated

The differences can be seen in the Select state which broadcasts a deselect event to all the other FSMs on buttons of the same type, this makes sure only one is selected at a time. (Make sure you check the Exclude Self box in the Send Event action or the button will trigger its own Deselect event!) The Update Settings IO state has been moved so as to be available only while the button is selected, and the scaling has been removed from both Selected Over and Selected Cursor Over states. These states no longer check for click events either.

The templates for resolution, AA and V-sync are identical except they check for and set their relevant variables instead of width/height and the Deselect event is named differently. The Aspect ratio buttons do a slightly different job and have a few extra elements…

 

Nick

3D-artist and fledgling Unity Dev. Currently working on a wordless point-and-click adventure game...

3 comments on “Development Diary #12: Quality settings…”

Leave a Reply to Nick Preston Cancel reply

Your email address will not be published.