Tab Switch Controller
A Tab Switch Controller is for navigating Tabs.
The easiest way to implement tabs is a combination of Better Toggles with an Object Activeness Transition (see here), but this controller is flexible enough that you can define whatever Selectables you want as tabs.
Inspector Properties
Tabs
The Selectable Collection that holds the Selectables which represent the tabs.
Focus Mode
Defines how the tab should behave when it becomes the current tab:
- Nothing
Nothing happens. Probably, this option does not make sense in any configuration. - Trigger
If the tab is a Toggle or Better Toggle, its "isOn" state will be set to true.
If it is a (Better) Button, the "onClick()" event is invoked.
If it is another kind of Selectable, a warning is logged to the console (only Toggles and Buttons are supported as tabs for Focus Mode "Trigger"). - Select
The Selectable will become the currently active Selectable. - Transition To Selected State
The Selectable will appear to become selected but it will not be the current selection for navigation.
Note that you can select multiple of these options. This probably only makes sense in a single scenario: If your tab is a Button that shall trigger, you want to set it to "Trigger | Transition To Selected State", so that it looks like it is the currently active tab but the user can navigate elsewhere (likely in the content page of that tab).
Current Tab Changed (SelectableChangedArgs)
This event is invoked when the current tab was changed (if changed from your code, it only triggers if the "triggerEvent" parameter is true). It is not invoked when the initial tab is selected.
Custom methods can be registered here. They may or may not have a "SelectableChangedArgs" as parameter, which contains the current and the previous tab.
Is Controlling Navigation Groups
If this is checked, the input for switching tabs is evaluated only if one of the Controlled Navigation Groups is currently focused.
Also, the indented parameters below are only relevant if this is checked.
They are basically behave the same as in Navigation Group Switch Controller:
- enabled / gameObject.activeInHierarchy
- Controlled Navigation Groups ("Navigation Groups" in Navigation Group Switch Controller)
- Switch Group By Moving
- Smart Select for Move out of group
- Smart Select for switch by Button
- Unfocus Navigation Group On Disable
- Disable When No Managed Group Active
- Enable When Managed Group Active
Smart Select works a bit differently here:
If you go to the right most element inside a tab contents page and navigate to the right, the next tab is selected (for horizontal navigation) and the left-most element at about the same vertical position is selected. It works this way for all directions.
Controlled Navigation Groups Parent
If the "Controlled Navigation Group" is not a "Fixed Set", you should assign a game object here that has all managed Navigation Groups as children or sub-children (any sub-level in the hierarchy).
If this field is left empty, it is assumed that the game object with the Tab Switch Controller is the parent.
Settings
There are Input Action Bindings for:
- Navigate Up
- Navigate Down
- Navigate Left
- Navigate Right
If the corresponding input action is detected and the Tab Switch Controller is active (and one of its groups is focused if "Is Controlling Navigation Groups" is true), it switches to a tab at the corresponding direction.
For every of those bindings an Input Action Visualization can be defined.
These Settings are Size Config Collections (as the tabs might be horizontal in portrait mode and vertical in landscape mode).
Code Access
Static
Same as in Navigation Group Switch Controller:
- ActiveControllers
- AllControllers
- ActiveHandlers
- TryFocusAnotherGroup()
Non-Static
The following properties are the same as in Navigation Group Switch Controller:
- IsInitialized
- ControlledNavigationGroups
- SwitchGroupByMoving
- UnfocusNavigationOnDisable.
- NavigateLeftInput / NavigateRightInput / NavigateUpInput / NavigateDownInput
- NavigateLeftVisualization / NavigateRightVisualization / NavigateUpVisualization / NavigateDownVisualization
IsControllingNavigationGroups
Gets the value. See Inspector Properties
Tabs
Gets the Selectable Collection that holds the Selectables which represent the tabs.
CurrentTab
Gets the currently active tab (can be null in case of a faulty state / non-initialized state).
CurrentTabChanged
The Unity Event for when a Tab changes. See Inspector Properties
ControlledNavigationGroupParent
See Inspector Properties.
SetCurrentTab()
Sets the current tab to the provided selectable.
If "executeFocusLogic" is true, that tab will be focused (See Inspector Properties: Focus Mode).
If "triggerEvent" is true, the "Current Tab Changed" event will be triggered (if the passed selectable was not already the current tab).
If "shouldSmartMove" is true, the Smart Select feature will be used to determine the selected element of the new tabs content page (see highlighted section in Inspector Properties)